1 23 24 package com.sun.enterprise.deployment; 25 26 import java.util.*; 27 import java.lang.reflect.*; 28 import java.util.logging.*; 29 import com.sun.logging.*; 30 31 import com.sun.enterprise.util.LocalStringManagerImpl; 32 import com.sun.enterprise.util.TypeUtil; 33 34 import com.sun.enterprise.deployment.util.EjbVisitor; 35 import com.sun.enterprise.deployment.util.LogDomains; 36 import com.sun.enterprise.util.BeanMethodCalculator; 37 38 42 43 public class EjbCMPEntityDescriptor extends EjbEntityDescriptor { 44 45 private static final String FIELD_ACCESS_METHOD_PREFIX = "get"; 47 public static final int UNDEFINED = -1; 49 public static final int CMP_1_1 = 1; 50 public static final int CMP_2_x = 2; 51 52 private int cmpVersion = UNDEFINED; 53 private PersistenceDescriptor pers; 54 private String abstractSchemaName=null; 55 private FieldDescriptor primaryKeyFieldDesc; 56 private String stateImplClassName=null; 57 private String ejbImplementationImplClassName=null; 58 59 private static LocalStringManagerImpl localStrings = 60 new LocalStringManagerImpl(EjbCMPEntityDescriptor.class); 61 62 static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 63 64 65 public EjbCMPEntityDescriptor() { 66 this.setPersistenceType(CONTAINER_PERSISTENCE); 67 } 68 69 72 public EjbCMPEntityDescriptor(EjbDescriptor other) { 73 super(other); 74 75 this.setPersistenceType(CONTAINER_PERSISTENCE); 76 77 if ( other instanceof EjbCMPEntityDescriptor ) { 78 EjbCMPEntityDescriptor entity = (EjbCMPEntityDescriptor)other; 79 this.pers = entity.pers; 80 this.cmpVersion = entity.cmpVersion; 81 this.abstractSchemaName = entity.abstractSchemaName; 82 } 83 } 84 85 88 public void setStateImplClassName(String name) { 89 this.stateImplClassName = name; 90 } 91 92 95 public String getStateImplClassName() { 96 return this.stateImplClassName; 97 } 98 99 public Vector getFields() { 100 Vector fields = new Vector(); 101 if( isEJB20() ) { 102 } else { 106 fields = super.getFields(); 107 } 108 return fields; 109 } 110 111 public Vector getFieldDescriptors() { 112 Vector fieldDescriptors = new Vector(); 113 if( isEJB20() ) { 114 try { 115 ClassLoader cl = getEjbBundleDescriptor().getClassLoader(); 116 fieldDescriptors = BeanMethodCalculator.getPossibleCmpCmrFields 117 (cl, this.getEjbClassName()); 118 } catch(Throwable t) { 119 String errorMsg = localStrings.getLocalString 120 ("enterprise.deployment.errorloadingejbclass", 121 "error loading the ejb class {0} in getFields" + 122 " on EjbDescriptor\n {1}", 123 new Object [] {this.getEjbClassName(), t.toString() }); 124 _logger.log(Level.FINE,errorMsg); 125 } 126 } else { 127 fieldDescriptors = super.getFieldDescriptors(); 128 } 129 return fieldDescriptors; 130 } 131 132 135 public int getCMPVersion() { 136 if (cmpVersion == UNDEFINED) { 137 if (getEjbBundleDescriptor()!=null) { 138 String bundleVersion = getEjbBundleDescriptor().getSpecVersion(); 139 if (bundleVersion.startsWith("1.")) { 140 cmpVersion = CMP_1_1; 141 } else { 142 cmpVersion = CMP_2_x; 143 } 144 } else { 145 cmpVersion = CMP_2_x; 147 } 148 } 149 return cmpVersion; 150 } 151 152 155 public void setCMPVersion(int version) { 156 if (version==CMP_1_1 || version == CMP_2_x) { 157 cmpVersion = version; 158 } else { 159 throw new IllegalArgumentException (localStrings.getLocalString( 160 "enterprise.deployment.invalidcmpversion", "Invalid CMP version: {0}.", new Object [] {new Integer (version)})); } 163 } 164 165 169 public boolean isEJB20() { 170 return getCMPVersion()==CMP_2_x; 171 } 172 173 public void setEjbBundleDescriptor(EjbBundleDescriptor bundleDescriptor) { 174 super.setEjbBundleDescriptor(bundleDescriptor); 175 } 176 177 public Vector getPossibleTransactionAttributes() { 178 Vector txAttributes = null; 179 if( isEJB20() ) { 180 txAttributes = new Vector(); 181 txAttributes.add(new ContainerTransaction 182 (ContainerTransaction.REQUIRED, "")); 183 txAttributes.add(new ContainerTransaction 184 (ContainerTransaction.REQUIRES_NEW, "")); 185 txAttributes.add(new ContainerTransaction 186 (ContainerTransaction.MANDATORY, "")); 187 if( isTimedObject() ) { 188 txAttributes.add(new ContainerTransaction 189 (ContainerTransaction.NOT_SUPPORTED, "")); 190 } 191 } else { 192 txAttributes = super.getPossibleTransactionAttributes(); 193 } 194 return txAttributes; 195 } 196 197 public void setPersistenceDescriptor(PersistenceDescriptor pd) 198 { 199 this.pers = pd; 200 pd.setParentDescriptor(this); 201 } 202 203 public PersistenceDescriptor getPersistenceDescriptor() 204 { 205 if (pers==null) { 206 pers = new PersistenceDescriptor(); 207 this.setPersistenceDescriptor(pers); 208 } 209 return pers; 210 } 211 212 private void invalidatePersistenceInfo() { 213 if( pers != null ) { 214 pers.invalidate(); 215 } 216 } 217 218 public void setPrimaryKeyFieldDesc(FieldDescriptor pkf) 219 { 220 this.primaryKeyFieldDesc = pkf; 221 invalidatePersistenceInfo(); 222 } 223 224 public FieldDescriptor getPrimaryKeyFieldDesc() 225 { 226 return primaryKeyFieldDesc; 227 } 228 229 230 231 232 public void setAbstractSchemaName(String abstractSchemaName) 233 { 234 this.abstractSchemaName = abstractSchemaName; 235 } 236 237 public String getAbstractSchemaName() 238 { 239 return abstractSchemaName; 240 } 241 242 246 public void setEjbImplementationImplClassName(String className) { 247 ejbImplementationImplClassName = className; 248 } 249 250 253 public String getEjbImplementationImplClassName() { 254 return ejbImplementationImplClassName; 255 } 256 257 public static Vector getPossibleCmpCmrFields(ClassLoader cl, 258 String className) 259 throws Exception { 260 261 Vector fieldDescriptors = new Vector(); 262 Class theClass = cl.loadClass(className); 263 264 Method[] methods = theClass.getMethods(); 266 267 for(int mIndex = 0; mIndex < methods.length; mIndex++) { 272 Method next = methods[mIndex]; 273 String nextName = next.getName(); 274 int nextModifiers = next.getModifiers(); 275 if( Modifier.isAbstract(nextModifiers) ) { 276 if( nextName.startsWith(FIELD_ACCESS_METHOD_PREFIX) && 277 nextName.length() > 3 ) { 278 String field = 279 nextName.substring(3,4).toLowerCase() + 280 nextName.substring(4); 281 fieldDescriptors.add(new FieldDescriptor(field)); 282 } 283 } 284 } 285 return fieldDescriptors; 286 } 287 288 291 public void print(StringBuffer toStringBuffer) { 292 super.print(toStringBuffer); 293 toStringBuffer.append("\n cmpVersion ").append(cmpVersion). 294 append("\n primKeyField "); 295 296 if(getPrimaryKeyFieldDesc() != null) 297 ((Descriptor)getPrimaryKeyFieldDesc()).print(toStringBuffer); 298 299 if(pers != null) 300 ((Descriptor)pers).print(toStringBuffer); 301 } 302 303 308 public void visit(EjbVisitor aVisitor) { 309 super.visit(aVisitor); 310 PersistenceDescriptor persistenceDesc = getPersistenceDescriptor(); 311 for (Iterator e=persistenceDesc.getCMPFields().iterator();e.hasNext();) { 312 FieldDescriptor fd = (FieldDescriptor) e.next(); 313 aVisitor.accept(fd); 314 } 315 for (Iterator e=persistenceDesc.getQueriedMethods().iterator();e.hasNext();) { 316 Object method = e.next(); 317 if (method instanceof MethodDescriptor) { 318 QueryDescriptor qd = persistenceDesc.getQueryFor((MethodDescriptor) method); 319 aVisitor.accept((MethodDescriptor) method, qd); 320 } 321 } 322 } 323 324 } 325 | Popular Tags |