?? genericvalueobject.java
字號:
package com.set.appframe.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.set.utils.DateTimeUtils;
import com.set.utils.StringUtils;
/**
* GenericValueObject represents a generic value object returned from the EIS
* layer. It provides a light-weight object to store large number of values
* returned from EIS layer, which can be rendered and displayed in the Web/
* client layer easily.
* <p>
* The GenericValueObject can also be used as a general placeholder for
* name-value pairs in other situations.
*
* @author Oliver Yip
* @author tommy
* @since 1.0
*/
public class GenericValueObject implements Serializable {
private Map htValues = null;
/**
* constructs a <code>GenericValueObject</code> object.
*
*/
public GenericValueObject() {
htValues = new HashMap();
}
/**
* constructs a <code>GenericValueObject</code> object.
*
* @param ht
* Hashtable object which represents a collection of name-value
* pairs for the construction of the GenericValueObject.
*
*/
public GenericValueObject(Map ht) {
if (ht == null)
htValues = new HashMap();
else
htValues = ht;
}
/**
* returns the hashtable key-value pairs for the GenericValueObject
*
* @return the hashtable key-value pairs for the GenericValueObject
*
*/
public Map getHashtable() {
return htValues;
}
/**
* adds a name-value pair to the GenericValueObject
*
* @param keyStr
* the key for the name-value pair
* @param val
* the value object for the name-value pair
*
*/
public void add(String keyStr, Object val) {
if (keyStr != null && null != val)
htValues.put(keyStr, val);
}
/**
* returns all the keys of the GenericValueObject
*
* @return all the keys for the name-value pairs
*
*/
public Set getKeys() {
return htValues.keySet();
}
/**
* accesses a name-value pair from the GenericValueObject
*
* @param keyStr
* the key for the name-value pair to access
* @return the value object for the name-value pair to access
*
*/
public Object getItem(String keyStr) {
if (keyStr != null)
return htValues.get(keyStr);
else
return null;
}
/**
* get date string
*
* @param keyStr
* @return
* @author zzf
*/
public String getItemDateString(String keyStr) {
String result = "";
Object v = getItem(keyStr);
if (null != v) {
if (v instanceof Date) {
result = DateTimeUtils.dateToShortString((Date) v);
} else {
result = String.valueOf(v);
}
}
return result;
}
/**
* the this vo doesn't contain the key,then return ""
*
* @param keyStr
* String
* @return String
* @author zhifeng
*/
public String getItemString(String keyStr) {
return StringUtils.dealNull(getItem(keyStr));
}
public String getItemListString(String keyStr, String delima) {
Object obj = getItem(keyStr);
StringBuffer buffer = new StringBuffer();
if (null != obj) {
// buffer = new StringBuffer();
if (obj instanceof ArrayList) {
ArrayList list = (ArrayList) getItem(keyStr);
Iterator it = list.iterator();
while (it.hasNext()) {
buffer.append(it.next()).append(delima);
}
}
}
return buffer.toString();
}
/**
* removes a name-value pair from the GenericValueObject
*
* @param keyStr
* the key for the name-value pair to remove
* @return a boolean indicating whether the name-value pair can be removed
*
*/
public boolean removeItem(String keyStr) {
Object o = htValues.remove(keyStr);
return (o != null);
}
/**
* converts a Collection object from DBAccess component to a List of
* GenericValueObject objects
*
* @param Collection
* Collection object returned from the DBAccess component
* @return List of GenericValueObject objects transformed from the DBAccess
* Collection
*
*/
public static List convertDBAccessCollection(Collection c) {
List vReturn = new ArrayList();
if (c != null) {
Iterator it = c.iterator();
Map htRow;
while (it.hasNext()) {
htRow = (Map) it.next();
GenericValueObject gvo = new GenericValueObject(htRow);
vReturn.add(gvo);
}
}
return vReturn;
}
/**
* set the created by value for this object
*
* @param o
* the created by value for this object
*
*/
public void setCreateBy(Object o) {
add("CREATEDBY", o);
}
public void setCreateByName(Object o) {
add("CREATEDBYNAME", o);
}
/**
* return the created by value for this object
*
* @return the created by value for this object
*
*/
public Object getCreateBy() {
return getItem("CREATEDBY");
}
public Object getCreateByName() {
return getItem("CREATEDBYNAME");
}
/**
* set the creation date value for this object
*
* @param o
* the creation date value for this object
*
*/
public void setCreateDate(Object o) {
add("CREATEDDATE", o);
}
/**
* return the creation date value for this object
*
* @return the creation date value for this object
*
*/
public Object getCreateDate() {
return getItem("CREATEDDATE");
}
/**
* set the last updated by value for this object
*
* @param o
* the last updated by value for this object
*
*/
public void setLastUpdateBy(Object o) {
add("MODIFIEDBY", o);
}
/**
* return the last updated by value for this object
*
* @return the last updated by value for this object
*
*/
public Object getLastUpdateBy() {
return getItem("MODIFIEDBY");
}
/**
* set the last updated date value for this object
*
* @param o
* the last updated date value for this object
*
*/
public void setLastUpdateDate(Object o) {
add("MODIFIEDDATE", o);
}
/**
* return the last updated date value for this object
*
* @return the last updated date value for this object
*
*/
public Object getLastUpdateDate() {
return getItem("MODIFIEDDATE");
}
public GenericValueObject encodeHTMLTags(String[] fields,
boolean isExcludesive) {
Set eKeys = getKeys();
Iterator it = eKeys.iterator();
while (it.hasNext()) {
String key = (String) it.next();
boolean contains = StringUtils.checkContain(fields, key);
if ((contains && !isExcludesive) || (!contains && isExcludesive)) {
String newValue = StringUtils.escapeHTMLTags(getItem(key)
.toString());
htValues.put(key, newValue);
}
}
return this;
}
public GenericValueObject encodeHTMLTags(String[] excludeFields) {
return encodeHTMLTags(excludeFields, true);
}
private Iterator splitString(String s, String delim) {
List vTokens = new ArrayList();
int currpos = 0;
int delimpos = s.indexOf(delim, currpos);
while (delimpos != -1) {
String ss = s.substring(currpos, delimpos);
vTokens.add(ss);
currpos = delimpos + delim.length();
delimpos = s.indexOf(delim, currpos);
}
vTokens.add(s.substring(currpos));
return vTokens.iterator();
}
public void addVO(GenericValueObject gvo) {
// TODO 自動生成方法存根
Map map = gvo.getHashtable();
Set keyset = map.keySet();
Iterator it = keyset.iterator();
while (it.hasNext()) {
String key = (String) it.next();
this.htValues.put(key, map.get(key));
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -