001: package org.manentia.kasai;
002:
003: import java.io.IOException;
004: import java.io.Serializable;
005: import java.sql.ResultSet;
006: import java.sql.SQLException;
007: import java.util.HashMap;
008: import java.util.Map;
009:
010: import javax.xml.parsers.FactoryConfigurationError;
011: import javax.xml.parsers.ParserConfigurationException;
012:
013: import org.apache.commons.lang.StringUtils;
014: import org.manentia.kasai.exceptions.InvalidAttributesException;
015: import org.manentia.kasai.util.MiscUtils;
016: import org.xml.sax.SAXException;
017:
018: import com.manentia.commons.log.Log;
019:
020: /**
021: *
022: * @author fpena
023: *
024: */
025:
026: public class Group implements Serializable {
027: /**
028: *
029: */
030: private static final long serialVersionUID = -7524294522631191294L;
031:
032: private String id;
033:
034: private boolean blocked;
035:
036: private String description;
037:
038: private boolean system;
039:
040: private Map attributes;
041:
042: private String[] members;
043:
044: public Group() {
045: attributes = new HashMap();
046: }
047:
048: public Group(ResultSet rs) throws SQLException, SAXException,
049: IOException, ParserConfigurationException,
050: FactoryConfigurationError {
051: id = rs.getString("id");
052: blocked = (rs.getInt("blocked") != 0);
053: description = rs.getString("description");
054: system = (rs.getInt("system") != 0);
055: attributes = MiscUtils.parseXMLMap(rs.getString("data"));
056: }
057:
058: public void setAttribute(String key, String value) {
059: this .attributes.put(key, value);
060: }
061:
062: public String getAttribute(String key)
063: throws com.manentia.commons.xml.XMLException {
064: return (String) this .attributes.get(key);
065: }
066:
067: public String getAttributesXML()
068: throws ParserConfigurationException,
069: FactoryConfigurationError {
070: return MiscUtils.serializeMapToXML(attributes);
071: }
072:
073: public boolean getBlocked() {
074: return this .blocked;
075: }
076:
077: public void setBlocked(boolean blocked) {
078: this .blocked = blocked;
079: }
080:
081: public String getDescription() {
082: return this .description;
083: }
084:
085: public void setDescription(String description) {
086: this .description = description;
087: }
088:
089: public String getId() {
090: return this .id;
091: }
092:
093: public void setId(String id) {
094: this .id = id;
095: }
096:
097: public void validate() throws InvalidAttributesException {
098: Log.write("Enter", Log.INFO, "validate", Group.class);
099:
100: if ((this .getId() == null) || (this .getId().length() == 0)) {
101: Log.write("Id was not specified", Log.WARN, "validate",
102: Group.class);
103:
104: throw new InvalidAttributesException(Group.class.getName()
105: + ".emptyId");
106: }
107:
108: Log.write("Exit", Log.INFO, "validate", Group.class);
109: }
110:
111: public boolean equals(java.lang.Object obj) {
112: boolean result = false;
113:
114: try {
115: if (obj instanceof Group) {
116: if (((Group) obj).getId().equals(this .id)) {
117: result = true;
118: }
119: }
120: } catch (Exception e) {
121: result = false;
122: }
123: return result;
124: }
125:
126: public boolean getSystem() {
127: return this .system;
128: }
129:
130: public void setSystem(boolean system) {
131: this .system = system;
132: }
133:
134: public String getDescriptionPrefix() {
135: String result = StringUtils.defaultString(description);
136:
137: if (result.length() > 60) {
138: result = result.substring(0, 57) + "...";
139: }
140:
141: return result;
142: }
143:
144: public String getObjectId() {
145: return "/kasai/group/" + this .getId();
146: }
147:
148: public String[] getMembers() {
149: return members;
150: }
151:
152: public void setMembers(String[] members) {
153: this.members = members;
154: }
155:
156: }
|