1 19 20 package com.sslexplorer.policyframework; 21 22 import java.io.Serializable ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import com.sslexplorer.security.SessionInfo; 29 30 37 public class DefaultResourceType implements ResourceType, Serializable { 38 39 41 private int id; 42 private String bundle; 43 private List <Permission> permissions; 44 private String permissionClass; 45 private boolean policyRequired; 46 47 57 public DefaultResourceType(int id, String bundle, String permissionClass) { 58 this(id, bundle, permissionClass, PolicyConstants.DELEGATION_CLASS.equals(permissionClass)); 59 } 60 61 70 public DefaultResourceType(int id, String bundle, String permissionClass, boolean policyRequired) { 71 this.id = id; 72 this.bundle = bundle; 73 this.permissionClass = permissionClass; 74 permissions = new ArrayList <Permission>(); 75 this.policyRequired = policyRequired; 76 77 } 78 79 84 public String getPermissionClass() { 85 return permissionClass; 86 } 87 88 93 public void setPermissionClass(String permissionClass) { 94 this.permissionClass = permissionClass; 95 } 96 97 102 public int getResourceTypeId() { 103 return id; 104 } 105 106 111 public String getBundle() { 112 return bundle; 113 } 114 115 120 public Collection <Permission> getPermissions() { 121 return permissions; 122 } 123 124 129 public void addPermission(Permission permission) { 130 permissions.add(permission); 131 } 132 133 138 public Permission getPermission(int id) { 139 Permission p = null; 140 for (Iterator i = permissions.iterator(); i.hasNext();) { 141 p = (Permission) i.next(); 142 if (p.getId() == id) { 143 return p; 144 } 145 } 146 return null; 147 } 148 149 154 public boolean equals(Object o) { 155 return o instanceof ResourceType && getResourceTypeId() == ((ResourceType) o).getResourceTypeId(); 156 } 157 158 164 public int compareTo(ResourceType o) { 165 int i = getPermissionClass().compareTo(o.getPermissionClass()); 166 return i == 0 ? new Integer (getResourceTypeId()).compareTo(new Integer (o.getResourceTypeId())) : i; 167 } 168 169 176 public String toString() { 177 StringBuffer buf = new StringBuffer ("ResourceType '"); 178 buf.append(getResourceTypeId()); 179 buf.append("' [permissionClass="); 180 buf.append(getPermissionClass()); 181 buf.append(",bundle="); 182 buf.append(getBundle()); 183 buf.append("]"); 184 return buf.toString(); 185 } 186 187 192 public Resource getResourceById(int resourceId) throws Exception { 193 throw new UnsupportedOperationException ("Not supported."); 194 } 195 196 202 public Resource getResourceByName(String resourceName, SessionInfo session) throws Exception { 203 throw new UnsupportedOperationException ("Not supported."); 204 } 205 206 212 public Resource removeResource(int resourceId, SessionInfo session) throws Exception { 213 throw new UnsupportedOperationException ("Not supported."); 214 } 215 216 222 public void updateResource(Resource resource, SessionInfo session) throws Exception { 223 throw new UnsupportedOperationException ("Not supported."); 224 } 225 226 231 public boolean isPolicyRequired() { 232 return policyRequired; 233 } 234 235 240 public Resource cloneResource(Resource sourceResource, SessionInfo session) throws CloneNotSupportedException { 241 244 try { 245 Resource r = getResourceById(sourceResource.getResourceId()); 246 int idx = 1; 247 while (true) { 248 r.setResourceName((idx == 1 ? "Copy of " : ("Copy (" + idx + ") ")) + sourceResource.getResourceName()); 249 if (sourceResource.getResourceType().getResourceByName(r.getResourceName(), session) == null) { 250 break; 251 } 252 idx++; 253 } 254 return r; 255 } catch (Exception e) { 256 e.printStackTrace(); 257 throw new CloneNotSupportedException (); 258 } 259 } 260 } 261 | Popular Tags |