1 26 27 package org.objectweb.jonas.security.realm.principals; 28 29 import java.io.Serializable ; 30 import java.util.Enumeration ; 31 import java.util.StringTokenizer ; 32 import java.util.Vector ; 33 34 import org.objectweb.jonas.security.realm.lib.XML; 35 36 41 42 public class Group implements Serializable , GroupMBean { 43 44 47 protected static final String SEPARATOR = ","; 48 49 52 private String name = null; 53 54 57 private Vector roles = new Vector (); 58 59 62 private String description = null; 63 64 67 public Group() { 68 69 } 70 71 75 public Group(String name) { 76 setName(name); 77 } 78 79 83 public void setName(String name) { 84 this.name = name; 85 } 86 87 91 public String getName() { 92 return name; 93 } 94 95 99 public void setDescription(String description) { 100 this.description = description; 101 } 102 103 107 public String getDescription() { 108 return description; 109 } 110 111 115 public void setRoles(String roles) { 116 StringTokenizer st = new StringTokenizer (roles, SEPARATOR); 117 String role = null; 118 while (st.hasMoreTokens()) { 119 role = st.nextToken().trim(); 120 addRole(role); 121 } 122 } 123 124 128 public void addRole(String role) { 129 if (!roles.contains(role)) { 130 this.roles.addElement(role); 131 } 132 } 133 134 138 public void removeRole(String role) { 139 if (roles.contains(role)) { 140 this.roles.removeElement(role); 141 } 142 } 143 144 148 public String getRoles() { 149 String rolesList = ""; 150 Enumeration r = roles.elements(); 151 int nb = 0; 152 String role = null; 153 154 while (r.hasMoreElements()) { 155 if (nb > 0) { 156 rolesList += ", "; 157 } 158 role = (String ) r.nextElement(); 159 rolesList += role; 160 } 161 return rolesList; 162 } 163 164 168 public String [] getArrayRoles() { 169 return ((String []) roles.toArray(new String [roles.size()])); 170 } 171 172 176 public String toXML() { 177 StringBuffer xml = new StringBuffer ("<group name=\""); 178 xml.append(name); 179 xml.append("\" description=\""); 180 if (description != null) { 181 xml.append(description); 182 } 183 xml.append("\""); 184 XML.appendVectorToBuffer("roles=", xml, roles); 185 xml.append(" />"); 186 return xml.toString(); 187 } 188 189 193 public String toString() { 194 return this.toXML(); 195 } 196 197 } | Popular Tags |