001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.model;
019:
020: import org.columba.core.xml.XmlElement;
021:
022: /**
023: * @author fdietz
024: *
025: */
026: public class GroupModel implements IGroupModel {
027:
028: private XmlElement root;
029: private String folderUid;
030:
031: public GroupModel(XmlElement group, String folderUid) {
032: this .root = group;
033: this .folderUid = folderUid;
034:
035: }
036:
037: public GroupModel() {
038:
039: root = new XmlElement("group");
040:
041: XmlElement members = root.getElement("members");
042: if (members == null) {
043: members = new XmlElement("members");
044: root.addElement(members);
045: }
046: }
047:
048: public XmlElement getRootElement() {
049: return root;
050: }
051:
052: public void setName(String name) {
053: root.addAttribute("name", name);
054:
055: }
056:
057: public String getName() {
058: return root.getAttribute("name");
059: }
060:
061: public void setDescription(String description) {
062: root.addAttribute("description", description);
063: }
064:
065: public String getDescription() {
066: return root.getAttribute("description");
067: }
068:
069: public void addMember(Object uid) {
070:
071: XmlElement members = root.getElement("members");
072:
073: XmlElement m = new XmlElement("member");
074: m.addAttribute("uid", uid.toString());
075:
076: members.addElement(m);
077: }
078:
079: public int count() {
080: XmlElement members = root.getElement("members");
081:
082: return members.count();
083: }
084:
085: public boolean exists(Object uid) {
086: if (getMember(uid) != null)
087: return true;
088:
089: return false;
090: }
091:
092: protected XmlElement getMember(Object uid) {
093: XmlElement members = root.getElement("members");
094:
095: for (int i = 0; i < members.count(); i++) {
096: XmlElement m = members.getElement(i);
097: Integer str = new Integer(m.getAttribute("uid"));
098: if (str.equals(uid))
099: return m;
100: }
101:
102: return null;
103: }
104:
105: public String[] getMembers() {
106: XmlElement members = root.getElement("members");
107:
108: String[] result = new String[members.count()];
109: for (int i = 0; i < members.count(); i++) {
110: XmlElement m = members.getElement(i);
111: String uid = m.getAttribute("uid");
112: result[i] = uid;
113: }
114:
115: return result;
116: }
117:
118: public void remove(Object uid) {
119: XmlElement m = getMember(uid);
120:
121: m.removeFromParent();
122: }
123:
124: public void removeAllMembers() {
125: XmlElement members = root.getElement("members");
126: members.removeAllElements();
127: }
128:
129: /**
130: * @return Returns the folderUid.
131: */
132: public String getFolderUid() {
133: return folderUid;
134: }
135:
136: /**
137: * @param folderUid The folderUid to set.
138: */
139: public void setFolderUid(String folderUid) {
140: this.folderUid = folderUid;
141: }
142: }
|