1 23 24 package com.sun.enterprise.resource; 25 26 import java.util.Iterator ; 27 import java.util.Properties ; 28 import javax.management.AttributeList ; 29 import javax.management.Attribute ; 30 31 import com.sun.enterprise.config.serverbeans.ServerTags; 32 33 import static com.sun.enterprise.resource.ResourceConstants.*; 34 35 38 public class Resource 39 { 40 protected static final String CUSTOM_RESOURCE = ServerTags.CUSTOM_RESOURCE; 41 protected static final String JDBC_CONNECTION_POOL = ServerTags.JDBC_CONNECTION_POOL; 42 protected static final String CONNECTOR_RESOURCE = ServerTags.CONNECTOR_RESOURCE; 43 protected static final String ADMIN_OBJECT_RESOURCE = ServerTags.ADMIN_OBJECT_RESOURCE; 44 protected static final String JDBC_RESOURCE = ServerTags.JDBC_RESOURCE; 45 protected static final String RESOURCE_ADAPTER_CONFIG = ServerTags.RESOURCE_ADAPTER_CONFIG; 46 protected static final String MAIL_RESOURCE = ServerTags.MAIL_RESOURCE; 47 protected static final String EXTERNAL_JNDI_RESOURCE = ServerTags.EXTERNAL_JNDI_RESOURCE; 48 protected static final String CONNECTOR_CONNECTION_POOL = ServerTags.CONNECTOR_CONNECTION_POOL; 49 protected static final String PERSISTENCE_MANAGER_FACTORY_RESOURCE = ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE; 50 protected static final String CONNECTOR_SECURITY_MAP = ServerTags.SECURITY_MAP; 51 52 private String resType; 53 private AttributeList attrList = new AttributeList (); 54 private Properties props = new Properties (); 55 private String sDescription = null; 56 57 public Resource() 58 { 59 } 60 61 public Resource(String type) 62 { 63 resType = type; 64 } 65 66 public String getType() 67 { 68 return resType; 69 } 70 71 public void setType(String type) 72 { 73 resType = type; 74 } 75 76 public AttributeList getAttributes() 77 { 78 return attrList; 79 } 80 81 public void setAttribute(String name, String value) 82 { 83 attrList.add(new Attribute (name, value)); 84 } 85 86 public void setAttribute(String name, String [] value) 87 { 88 attrList.add(new Attribute (name, value)); 89 } 90 91 public void setDescription(String sDescription) 92 { 93 this.sDescription = sDescription; 94 } 95 96 public String getDescription() 97 { 98 return sDescription; 99 } 100 101 public void setProperty(String name, String value) 102 { 103 props.setProperty(name, value); 104 } 105 106 public void setProperty(String name, String value, String desc) 107 { 108 } 110 111 public Properties getProperties() 112 { 113 return props; 114 } 115 116 @Override 118 public boolean equals(Object obj) { 119 if (this == obj) return true; 120 if ( !(obj instanceof Resource) ) return false; 121 122 Resource r = (Resource)obj; 123 return r.getType().equals(this.getType()) && 124 r.getDescription().equals(this.getDescription()) && 125 r.getProperties().equals(this.getProperties()) && 126 r.getAttributes().equals(this.getAttributes()); 127 } 128 129 @Override 131 public int hashCode() { 132 return this.getAttributes().hashCode() + 133 this.getProperties().hashCode() + 134 this.getType().hashCode() + 135 this.getDescription().hashCode(); 136 } 137 138 public boolean isAConflict(Resource r) { 143 if (r.equals(this)) return true; 146 147 if (hasSameIdentity(r)) { 149 boolean propsNotEqual = (!(this.getProperties().equals( 152 r.getProperties()))); 153 boolean attrsNotEqual = (!(this.getAttributes().equals( 154 r.getAttributes()))); 155 if (propsNotEqual || attrsNotEqual) return true; 156 } 157 158 return false; 159 } 160 161 165 private boolean hasSameIdentity(Resource r) { 166 if (r.getType() != this.getType()) { 168 return false; 169 } 170 String rType = r.getType(); 171 172 if (rType.equals(CUSTOM_RESOURCE)|| rType.equals(EXTERNAL_JNDI_RESOURCE) 174 || rType.equals(JDBC_RESOURCE)|| rType.equals(PERSISTENCE_MANAGER_FACTORY_RESOURCE) 175 || rType.equals(CONNECTOR_RESOURCE)|| rType.equals(ADMIN_OBJECT_RESOURCE)) { 176 return r.getAttributes().equals(this.getAttributes()); 177 } 178 179 if (rType.equals(JDBC_CONNECTION_POOL)) { 182 return isEqualAttribute(r, CONNECTION_POOL_NAME) && 183 isEqualAttribute(r, DATASOURCE_CLASS) 184 && isEqualAttribute(r, RES_TYPE); 185 } 186 187 if (rType.equals(CONNECTOR_CONNECTION_POOL)) { 188 return isEqualAttribute(r, CONNECTION_POOL_NAME) && 189 isEqualAttribute(r, RESOURCE_ADAPTER_CONFIG_NAME) 190 && isEqualAttribute(r, CONN_DEF_NAME); 191 } 192 193 if (rType.equals(MAIL_RESOURCE)) { 194 return isEqualAttribute(r, JNDI_NAME); 195 } 196 197 if (rType.equals(RESOURCE_ADAPTER_CONFIG)) { 198 return isEqualAttribute(r, RES_ADAPTER_NAME) && 199 isEqualAttribute(r, RES_ADAPTER_CONFIG); 200 } 201 202 return false; 203 } 204 205 210 private boolean isEqualAttribute(Resource r, String name) { 211 return (getAttribute(r, name).equals(getAttribute(this, name))); 212 } 213 214 218 private Attribute getAttribute(Resource r, String name) { 219 for (Iterator <Attribute > iter = r.getAttributes().iterator(); iter.hasNext();) { 220 Attribute elt = (Attribute ) iter.next(); 221 if (elt.getName().equals(name)) return elt; 222 } 223 return null; 224 } 225 226 } 227 | Popular Tags |