1 16 package org.apache.cocoon.portal.pluto.om.common; 17 18 import java.util.HashSet ; 19 import java.util.Iterator ; 20 21 import org.apache.pluto.om.common.SecurityRole; 22 import org.apache.pluto.om.common.SecurityRoleSet; 23 import org.apache.pluto.util.StringUtils; 24 25 32 public class SecurityRoleSetImpl extends HashSet implements SecurityRoleSet, java.io.Serializable { 33 34 35 37 public static class Unmodifiable 38 extends UnmodifiableSet 39 implements SecurityRoleSet { 40 41 public Unmodifiable(SecurityRoleSet c) { 42 super(c); 43 } 44 45 public SecurityRole get(String roleName) { 46 return ((SecurityRoleSet)c).get(roleName); 47 } 48 49 } 50 51 public SecurityRoleSetImpl() { 52 } 54 55 57 public SecurityRole get(String roleName) { 58 Iterator iterator = this.iterator(); 59 while (iterator.hasNext()) { 60 SecurityRole securityRole = (SecurityRole)iterator.next(); 61 if (securityRole.getRoleName().equals(roleName)) { 62 return securityRole; 63 } 64 } 65 return null; 66 } 67 68 70 public SecurityRole add(SecurityRole securityRole) { 71 SecurityRoleImpl newSecurityRole = new SecurityRoleImpl(); 72 newSecurityRole.setRoleName(securityRole.getRoleName()); 73 newSecurityRole.setDescription(securityRole.getDescription()); 74 75 super.add(newSecurityRole); 76 77 return newSecurityRole; 78 } 79 80 public SecurityRole add(String roleName, String description) { 81 SecurityRoleImpl securityRole = new SecurityRoleImpl(); 82 securityRole.setRoleName(roleName); 83 securityRole.setDescription(description); 84 85 super.add(securityRole); 86 87 return securityRole; 88 } 89 90 public void remove(SecurityRole securityRole) { 91 super.remove(securityRole); 92 } 93 94 public SecurityRole remove(String roleName) { 95 Iterator iterator = this.iterator(); 96 while (iterator.hasNext()) { 97 SecurityRole securityRole = (SecurityRole)iterator.next(); 98 if (securityRole.getRoleName().equals(roleName)) { 99 super.remove(securityRole); 100 return securityRole; 101 } 102 } 103 return null; 104 } 105 106 public String toString() { 107 return toString(0); 108 } 109 110 public String toString(int indent) { 111 StringBuffer buffer = new StringBuffer (50); 112 StringUtils.newLine(buffer,indent); 113 buffer.append(getClass().toString()); 114 buffer.append(": "); 115 Iterator iterator = this.iterator(); 116 while (iterator.hasNext()) { 117 buffer.append(((SecurityRoleImpl)iterator.next()).toString(indent+2)); 118 } 119 return buffer.toString(); 120 } 121 122 } 123 | Popular Tags |