FileDocCategorySizeDatePackage
EjbCMPEntityDescriptor.javaAPI DocGlassfish v2 API11596Fri May 04 22:31:20 BST 2007com.sun.enterprise.deployment

EjbCMPEntityDescriptor

public class EjbCMPEntityDescriptor extends EjbEntityDescriptor
This class contains information about EJB1.1 and EJB2.0 CMP EntityBeans.
author
Sanjeev Krishnan

Fields Summary
private static final String
FIELD_ACCESS_METHOD_PREFIX
public static final int
UNDEFINED
public static final int
CMP_1_1
public static final int
CMP_2_x
private int
cmpVersion
private PersistenceDescriptor
pers
private String
abstractSchemaName
private FieldDescriptor
primaryKeyFieldDesc
private String
stateImplClassName
private String
ejbImplementationImplClassName
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
static Logger
_logger
Constructors Summary
public EjbCMPEntityDescriptor()

        
    
      
	this.setPersistenceType(CONTAINER_PERSISTENCE);
    
public EjbCMPEntityDescriptor(EjbDescriptor other)
The copy constructor.

	super(other);

	this.setPersistenceType(CONTAINER_PERSISTENCE);

	if ( other instanceof EjbCMPEntityDescriptor ) {
	    EjbCMPEntityDescriptor entity = (EjbCMPEntityDescriptor)other;
	    this.pers = entity.pers;
	    this.cmpVersion = entity.cmpVersion;
	    this.abstractSchemaName = entity.abstractSchemaName;
	}
    
Methods Summary
public java.lang.StringgetAbstractSchemaName()

	return abstractSchemaName;
    
public intgetCMPVersion()
Returns CMP version as an enum type.

        if (cmpVersion == UNDEFINED) {
            if (getEjbBundleDescriptor()!=null) {
                String bundleVersion = getEjbBundleDescriptor().getSpecVersion();
                if (bundleVersion.startsWith("1.")) {
                    cmpVersion = CMP_1_1;
                } else {
                    cmpVersion = CMP_2_x;
                }
            } else {
                // we cannot get the version from the bundle, set it to default...
                cmpVersion = CMP_2_x;
            }
        }
        return cmpVersion;
    
public java.lang.StringgetEjbImplementationImplClassName()

return
the generated implementation class

        return ejbImplementationImplClassName;
    
public java.util.VectorgetFieldDescriptors()

        Vector fieldDescriptors = new Vector();
        if( isEJB20() ) {
            try {
                ClassLoader cl = getEjbBundleDescriptor().getClassLoader();
                fieldDescriptors = BeanMethodCalculator.getPossibleCmpCmrFields
                    (cl, this.getEjbClassName());
            } catch(Throwable t) {
                String errorMsg = localStrings.getLocalString
                    ("enterprise.deployment.errorloadingejbclass",
                     "error loading the ejb class {0} in getFields" +
                     " on EjbDescriptor\n {1}",
                     new Object[] {this.getEjbClassName(), t.toString() });
                _logger.log(Level.FINE,errorMsg);
           }
        } else {
            fieldDescriptors = super.getFieldDescriptors();
        }
        return fieldDescriptors;
    
public java.util.VectorgetFields()

        Vector fields = new Vector();
        if( isEJB20() ) {
            // All cmp "fields" are abstract, so we can't construct
            // java.lang.reflect.Field elements from them.  Use
            // getFieldDescriptors() instead.
        } else {
            fields = super.getFields();
        } 
        return fields;
    
public PersistenceDescriptorgetPersistenceDescriptor()

	if (pers==null) {
	    pers = new PersistenceDescriptor();
	    this.setPersistenceDescriptor(pers);
        }
	return pers;
    
public static java.util.VectorgetPossibleCmpCmrFields(java.lang.ClassLoader cl, java.lang.String className)


        Vector fieldDescriptors = new Vector();
        Class theClass = cl.loadClass(className);

        // Start with all *public* methods
        Method[] methods = theClass.getMethods();

        // Find all accessors that could be cmp fields. This list 
        // will contain all cmr field accessors as well, since there
        // is no good way to distinguish between the two purely based
        // on method signature.
        for(int mIndex = 0; mIndex < methods.length; mIndex++) {
            Method next = methods[mIndex];
            String nextName = next.getName();
            int nextModifiers = next.getModifiers();
            if( Modifier.isAbstract(nextModifiers) ) {
                if( nextName.startsWith(FIELD_ACCESS_METHOD_PREFIX) &&
                    nextName.length() > 3 ) {
                    String field = 
                        nextName.substring(3,4).toLowerCase() + 
                        nextName.substring(4);
                    fieldDescriptors.add(new FieldDescriptor(field));
                }
            }
        }
        return fieldDescriptors;
    
public java.util.VectorgetPossibleTransactionAttributes()

        Vector txAttributes = null;
        if( isEJB20() ) {
            txAttributes = new Vector();
            txAttributes.add(new ContainerTransaction
                (ContainerTransaction.REQUIRED, ""));
            txAttributes.add(new ContainerTransaction
                (ContainerTransaction.REQUIRES_NEW, ""));
            txAttributes.add(new ContainerTransaction
                (ContainerTransaction.MANDATORY, ""));
            if( isTimedObject() ) {
                txAttributes.add(new ContainerTransaction
                    (ContainerTransaction.NOT_SUPPORTED, ""));
            }
        } else {
            txAttributes = super.getPossibleTransactionAttributes();
        }
        return txAttributes;
    
public FieldDescriptorgetPrimaryKeyFieldDesc()

	return primaryKeyFieldDesc;
    
public java.lang.StringgetStateImplClassName()
Returns the classname of the State class impl.

	return this.stateImplClassName;
    
private voidinvalidatePersistenceInfo()

        if( pers != null ) {
            pers.invalidate();
        }
    
public booleanisEJB20()
return true if this is an EJB2.0 CMP Entitybean DEPRECATED

	return getCMPVersion()==CMP_2_x;
    
public voidprint(java.lang.StringBuffer toStringBuffer)
Return my formatted string representation.

	super.print(toStringBuffer);
	toStringBuffer.append("\n cmpVersion ").append(cmpVersion).
            append("\n primKeyField ");

        if(getPrimaryKeyFieldDesc() != null)
            ((Descriptor)getPrimaryKeyFieldDesc()).print(toStringBuffer); 

        if(pers != null)
            ((Descriptor)pers).print(toStringBuffer);   
    
public voidsetAbstractSchemaName(java.lang.String abstractSchemaName)

	this.abstractSchemaName = abstractSchemaName;
    
public voidsetCMPVersion(int version)
Set the CMP version

	if (version==CMP_1_1 || version == CMP_2_x) {
            cmpVersion = version;
        } else {
	    throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.invalidcmpversion",
                                         "Invalid CMP version: {0}.",
                                         new Object[]{Integer.valueOf(version)})); // NOI18N
        }
    
public voidsetEjbBundleDescriptor(EjbBundleDescriptor bundleDescriptor)

        super.setEjbBundleDescriptor(bundleDescriptor);
    
public voidsetEjbImplementationImplClassName(java.lang.String className)
set the generated implementation class for a CMP 2.0 Ejb object

param
className the generated implementation

        ejbImplementationImplClassName = className;
    
public voidsetPersistenceDescriptor(PersistenceDescriptor pd)

	this.pers = pd;
	pd.setParentDescriptor(this);
    
public voidsetPrimaryKeyFieldDesc(FieldDescriptor pkf)

	this.primaryKeyFieldDesc = pkf;
        invalidatePersistenceInfo();
    
public voidsetStateImplClassName(java.lang.String name)
Sets the State class implementation classname.

	this.stateImplClassName = name;
    
public voidvisit(com.sun.enterprise.deployment.util.EjbVisitor aVisitor)
visit the descriptor and all sub descriptors with a DOL visitor implementation

param
a visitor to traverse the descriptors

        super.visit(aVisitor);     
        PersistenceDescriptor persistenceDesc = getPersistenceDescriptor();
        for (Iterator e=persistenceDesc.getCMPFields().iterator();e.hasNext();) {
            FieldDescriptor fd = (FieldDescriptor) e.next();
            aVisitor.accept(fd);
        }
        for (Iterator e=persistenceDesc.getQueriedMethods().iterator();e.hasNext();) {
            Object method = e.next();
            if (method instanceof MethodDescriptor) {
                QueryDescriptor qd = persistenceDesc.getQueryFor((MethodDescriptor) method);
                aVisitor.accept((MethodDescriptor) method, qd);
            }
        }