FileDocCategorySizeDatePackage
IASEjbCMPEntityDescriptor.javaAPI DocGlassfish v2 API26789Fri May 04 22:31:22 BST 2007com.sun.enterprise.deployment

IASEjbCMPEntityDescriptor

public class IASEjbCMPEntityDescriptor extends EjbCMPEntityDescriptor
This class contains information about EJB1.1 and EJB2.0 CMP EntityBeans.

Fields Summary
private transient Class
ejbClass
private String
pcImplClassName
private String
concreteImplClassName
private String
ejbImplClassName
private String
mappingProperties
private transient ClassLoader
jcl
private String
uniqueName
private String
moduleDir
private static LocalStringManagerImpl
localStrings
private static final Logger
_logger
private static final char
DOT
private static final char
LIST_START
private static final char
LIST_END
private static final char
LIST_SEPARATOR
private static final char
NAME_PART_SEPARATOR
private static final char
NAME_CONCATENATOR
private static final String
FIND
private static final String
EJB_SELECT
private static final String
JDOSTATE
private static final String
CONCRETE_IMPL
private static final String
MAPPINGEXT
private transient Collection
finders
private transient Collection
selectors
private com.sun.enterprise.deployment.interfaces.QueryParser
queryParser
private PrefetchDisabledDescriptor
prefetchDisabledDescriptor
private static final Map
conversionTable
private Map
oneOneFinders
private List
arrOneOneFinders
Constructors Summary
public IASEjbCMPEntityDescriptor()

    
public IASEjbCMPEntityDescriptor(EjbDescriptor other)
The copy constructor.Hopefully we wont need it;)

           super(other);

           setPersistenceType(CONTAINER_PERSISTENCE);

           if ( other instanceof EjbCMPEntityDescriptor ) {
             EjbCMPEntityDescriptor entity = (EjbCMPEntityDescriptor)other;
           }
    
Methods Summary
private voidaddAllInterfaceMethodsIn(java.util.Collection methodDescriptors, java.lang.Class c)

    
          
        Method[] methods = c.getMethods();
        for (int i=0; i<methods.length; i++) {
            methodDescriptors.add(methods[i]);
        }
    
private voidaddAllUniqueInterfaceMethodsIn(java.util.Collection methodDescriptors, java.lang.Class c)

        Method[] methods = c.getMethods();
        for (int i=0; i<methods.length; i++) {
        if(findEquivalentMethod(methodDescriptors, methods[i]) == null)
            methodDescriptors.add(methods[i]);
        }
    
public voidaddOneOneFinder(IASEjbCMPFinder finder)

        arrOneOneFinders.add(finder);
    
public booleanclassesChanged()
Called from EjbBundleDescriptor/EjbBundleArchivist when some classes in this bean are updated.


        /**        No Implementation Yet
        boolean superChanged = super.classesChanged();

        boolean persChanged = pers.classesChanged();

        // Send changed event only if parent didn't already do it.
        if( !superChanged && persChanged ) {
            changed();
        }

        return (superChanged || persChanged);
        */
        
        return false;
    
private static java.util.MapcreateConversionTable()
This method returns the conversion table which maps the unqualified name (e.g., String) of the java.lang classes to their fully qualified name (e.g., java.lang.String)


        HashMap conversionTable = new HashMap();
        conversionTable.put("Boolean", "java.lang.Boolean"); //NOI18N
        conversionTable.put("Byte", "java.lang.Byte"); //NOI18N
        conversionTable.put("Character", "java.lang.Character"); //NOI18N
        conversionTable.put("Double", "java.lang.Double"); //NOI18N
        conversionTable.put("Float", "java.lang.Float"); //NOI18N
        conversionTable.put("Integer", "java.lang.Integer"); //NOI18N
        conversionTable.put("Long", "java.lang.Long"); //NOI18N
        conversionTable.put("Number", "java.lang.Number"); //NOI18N
        conversionTable.put("Short", "java.lang.Short"); //NOI18N
        conversionTable.put("String", "java.lang.String"); //NOI18N
        conversionTable.put("Object", "java.lang.Object"); //NOI18N
        return conversionTable;
    
private java.lang.reflect.MethodfindEquivalentMethod(java.util.Collection methods, java.lang.reflect.Method methodToMatch)

        if(methods == null)
            return null;

        Method matchedMethod = null;
        for(Iterator iter = methods.iterator(); iter.hasNext();) {
            Method next = (Method) iter.next();
            // Compare methods, ignoring declaring class.
            if( methodsEqual(next, methodToMatch, false) ) {
                matchedMethod = next;
                break;
            }
        }
        return matchedMethod;
    
private java.lang.StringgenerateKey(IASEjbCMPFinder finder, com.sun.enterprise.deployment.interfaces.QueryParser parser)

        
        StringBuffer key = new StringBuffer();
        key.append(finder.getMethodName()).append(LIST_START);

        String queryParams = finder.getQueryParameterDeclaration();
        Iterator iter = parser.parameterTypeIterator(queryParams);
        while ( iter.hasNext() )  {
            String type = ( String ) iter.next() ;
            key.append(getFullyQualifiedType(type)) ;
            if( iter.hasNext() ) {
                key.append(LIST_SEPARATOR); 
            }
        }
        key.append(LIST_END);

        return key.toString().intern();
    
public java.util.CollectiongetAllMethods()


        HashSet methods = new HashSet();

        try {
            if (isRemoteInterfacesSupported()) {
                addAllInterfaceMethodsIn(methods, jcl.loadClass(getHomeClassName()));
                addAllInterfaceMethodsIn(methods, jcl.loadClass(getRemoteClassName()));
            }

            if (isLocalInterfacesSupported()) {
                addAllInterfaceMethodsIn(methods, jcl.loadClass(getLocalHomeClassName()));
                addAllInterfaceMethodsIn(methods, jcl.loadClass(getLocalClassName()));
            }
        } catch (Throwable t) {
            _logger.log( Level.WARNING,
                    "enterprise.deployment_error_loading_class_excp", t ); // NOI18N
            throw new RuntimeException(t.getMessage());
        }
        return methods;
    
public java.util.CollectiongetAllPersistentFields()

        PersistenceDescriptor pers = getPersistenceDescriptor();
        PersistentFieldInfo[] persFields = pers.getPersistentFieldInfo();
        PersistentFieldInfo[] pkeyFields = pers.getPkeyFieldInfo();
        HashMap fields = new HashMap();

        for(int i=0; i<persFields.length; i++) {
            fields.put(persFields[i].name, persFields[i]);
        }
        
        for(int i=0; i<pkeyFields.length; i++) {
            fields.put(pkeyFields[i].name, pkeyFields[i]);
        }
        
        return fields.values();        
    
public java.util.CollectiongetAllUniqueMethods()

        HashSet methods = new HashSet();

        try {
            if (isRemoteInterfacesSupported()) {
                addAllUniqueInterfaceMethodsIn(methods, jcl.loadClass(getHomeClassName()));
                addAllUniqueInterfaceMethodsIn(methods, jcl.loadClass(getRemoteClassName()));
            }
            if (isLocalInterfacesSupported()) {
                addAllUniqueInterfaceMethodsIn(methods, jcl.loadClass(getLocalHomeClassName()));
                addAllUniqueInterfaceMethodsIn(methods, jcl.loadClass(getLocalClassName()));
            }
        } catch (Throwable t) {
            _logger.log( Level.WARNING,
                "enterprise.deployment_error_loading_class_excp", t ); // NOI18N
            throw new RuntimeException(t.getMessage());
        }
        return methods;

    
public java.lang.StringgetBaseName(java.lang.String className)

        if (className == null)
            return null;

        int dot = className.lastIndexOf(DOT);
        if (dot == -1)
            return className;
        return className.substring(dot+1);
    
public java.lang.ClassLoadergetClassLoader()

        return jcl;
    
public java.lang.StringgetConcreteImplClassName()
Returns the classname of the State class impl.

        if (concreteImplClassName == null) {
        /**    The Ear may contain two jar files with beans with same ejb names
        */
             concreteImplClassName = getUniqueName() + CONCRETE_IMPL;
        }

        return concreteImplClassName;
    
private java.lang.ClassgetEjbClass()
The method returns the class instance for the ejb class.

return
ejb class

        if (ejbClass == null) {
            String ejbClassName = getEjbClassName();
            if(_logger.isLoggable(Level.FINE)) 
                _logger.fine("@@@@@@ Ejb name is  "+ ejbClassName); //NOI18N
            if (jcl == null) {
                String msg = localStrings.getLocalString(
                    "enterprise.deployment.error_missing_classloader", //NOI18N
                    "IASEjbCMPEntityDescriptor.getEjbClass"); //NOI18N
                _logger.log(Level.WARNING, msg);
                throw new RuntimeException(msg);
            }

            try {
                ejbClass=Class.forName(ejbClassName, true, jcl);

            } catch(ClassNotFoundException e) {
                String msg = localStrings.getLocalString(
                    "enterprise.deployment.error_cannot_find_ejbclass", //NOI18N
                        ejbClassName);
                _logger.log(Level.WARNING, msg);
                throw new RuntimeException(msg);
            }
        }
        return ejbClass;
    
public java.lang.StringgetEjbImplClassName()
IASRI 4725194 Returns the Execution class, which is sam as the user-specified class in case of Message, Session and Bean Managed Persistence Entity Beans but is different for Container Mananged Persistence Entity Bean Therefore, the implementation in the base class is to return getEjbClassName() and the method is redefined in IASEjbCMPDescriptor.

        if (ejbImplClassName == null) {
            String packageName = getPackageName(getEjbClassName());
            ejbImplClassName = getConcreteImplClassName();
            if(packageName != null)
                ejbImplClassName = packageName + DOT + ejbImplClassName;
        }
        return ejbImplClassName;
    
public java.util.CollectiongetFinders()
Returns a collection of finder method instances.

        if (finders == null) {
            String ejbClassName = getEjbClassName();
            Class ejbClass = getEjbClass();
                
            if ( super.isRemoteInterfacesSupported() ) {
                Class remoteHomeIntf = null;
                if(_logger.isLoggable(Level.FINE)) 
                    _logger.fine("@@@@@@ " + ejbClassName + //NOI18N 
                         " : Remote Interface is supported "); //NOI18N 

                try {
                    remoteHomeIntf = ejbClass.getClassLoader().loadClass(
                        super.getHomeClassName());
                } catch (ClassNotFoundException ex) {
                    _logger.log( Level.WARNING,
                         "enterprise.deployment_class_not_found", ex ); //NOI18N

                    return null;
                }

                finders = getFinders(remoteHomeIntf);
                if(_logger.isLoggable(Level.FINE)) {
                    for(Iterator iter = finders.iterator(); iter.hasNext();) {
                        Method remoteHomeMethod=(Method)iter.next();
                        _logger.fine("@@@@ adding Remote interface method " + //NOI18N
                                     remoteHomeMethod.getName() );
                    }
                }
            } //end of isRemoteInterfaceSupported

            if ( super.isLocalInterfacesSupported() ) {
                Class localHomeIntf = null;

                if(_logger.isLoggable(Level.FINE)) 
                    _logger.fine("@@@@@@ " + ejbClassName + ":  Local Interface is supported "); //NOI18N

                try {
                    localHomeIntf = ejbClass.getClassLoader().loadClass(
                        super.getLocalHomeClassName());
                } catch (ClassNotFoundException ex) {
                    _logger.log( Level.WARNING,
                         "enterprise.deployment_class_not_found", ex ); //NOI18N
                    return null;
                }
        
                Collection localFinders = getFinders(localHomeIntf);
                if(finders == null) {
                    // if there were no finders specified in the remote
                    // home, the local finders are the finders  
                    finders = localFinders;

                } else if(localFinders != null) {
                    // Remove the Common Elements from the collections
                    // and keep only unique methods
                    if(_logger.isLoggable(Level.FINE)) 
                        _logger.fine("@@@@@@ Trying to remove the Common Elements from HashSet....... "); //NOI18N

                    for(Iterator iter = localFinders.iterator(); iter.hasNext();) {
                        Method localHomeMethod=(Method)iter.next();
                        if(findEquivalentMethod(finders, localHomeMethod) == null) {
                            if(_logger.isLoggable(Level.FINE)) 
                                _logger.fine("@@@@ adding local interface method " + //NOI18N
                                     localHomeMethod.getName() ); 

                            finders.add(localHomeMethod);
                        }
                    }
                }
            } //end of isLocalInterfaceSupported

            if (finders == null)
                // still not initialized => empty set
                finders = new HashSet();
        }

        return finders;
    
public java.util.CollectiongetFinders(java.lang.Class homeIntf)
Returns a collection of finder methods declared by the home interface given by a class object.

        Method[] methods = homeIntf.getMethods();
        Collection finders = new HashSet();
        for(int i=0; i<methods.length; i++) {
           if(methods[i].getName().startsWith(FIND)) {
               finders.add(methods[i]);
           }
        }
        
        return finders;
    
private java.lang.StringgetFullyQualifiedType(java.lang.String type)

        String knownType=(String)conversionTable.get(type);
        return knownType == null ? type : knownType;
    
public IASEjbCMPFindergetIASEjbCMPFinder(java.lang.reflect.Method method)

        //Checks if the given method is present in the interfaces.
        if(findEquivalentMethod(getFinders(), method) == null ) {
            return null;
        }
        String methodName = method.getName();
        
        //key is of the form methodName(param0, param1, ....)
        StringBuffer key = new StringBuffer();
        key.append(methodName);
        key.append(LIST_START);
        Class paramList[] = method.getParameterTypes();
        for (int index = 0 ; index < paramList.length ; index++ ) {
            if(index>0) {
                key.append(LIST_SEPARATOR);
            }
            key.append(paramList[index].getName());
        }
        key.append(LIST_END);
        return (IASEjbCMPFinder)getOneOneFinders().get(key.toString());
    
public java.lang.StringgetMappingProperties()
Returns the classname of the State class impl.

         return mappingProperties;
    
public java.lang.StringgetModuleDir()
Returns the Module root of this module.

        //FIXME:this needs to be changed when the API is available.
        if(moduleDir != null)
            return moduleDir;
        else
            return null;
    
public java.util.MapgetOneOneFinders()
Returns a Map which maps between a method signature and the corresponding IASEjbCMPFinder instance. The key is the method signature as a string and consists of methodName(type1, type2.....).

        // update the oneOneFinders map if there are any entries pending in
        // the array arrOneOneFinders.
        if (!arrOneOneFinders.isEmpty()) {
            if (queryParser == null) {
                String msg = localStrings.getLocalString(
                    "enterprise.deployment.error_missing_queryparser", //NOI18N
                    "IASEjbCMPEntityDescriptor.getOneOneFinders"); //NOI18N
                _logger.log(Level.WARNING, msg);
                throw new RuntimeException(msg);
            }
            
            //parse the query declaration parameter and store the query object
            for ( Iterator i = arrOneOneFinders.iterator(); i.hasNext(); ) {
                IASEjbCMPFinder finder = ( IASEjbCMPFinder )i.next();
                String key = generateKey(finder, queryParser);
                oneOneFinders.put(key, finder);
            }
            arrOneOneFinders.clear();
        }
        return oneOneFinders;
    
public java.lang.StringgetPackageName(java.lang.String className)

        int dot = className.lastIndexOf(DOT);
        if (dot == -1)
            return null;
        return className.substring(0, dot);
     
public java.lang.StringgetPcImplClassName()

       if (pcImplClassName == null) { 
           // Check for Null added 
           pcImplClassName = getUniqueName() + JDOSTATE;
           String packageName = getPackageName(getEjbClassName());
           if(packageName != null)
               pcImplClassName = packageName + DOT + pcImplClassName;

            if(_logger.isLoggable(Level.FINE)) 
                _logger.fine("##### PCImplClass Name is " + pcImplClassName); // NOI18N
        }
        return pcImplClassName;
    
public java.util.CollectiongetPersistentFields()

        
        PersistenceDescriptor pers = getPersistenceDescriptor();
        PersistentFieldInfo[] persFields = pers.getPersistentFieldInfo();
        
        HashMap fields = new HashMap();

        for(int i=0; i<persFields.length; i++) {
            fields.put(persFields[i].name, persFields[i]);
        }
        
        return fields.values();        
    
public PrefetchDisabledDescriptorgetPrefetchDisabledDescriptor()
Getter for prefetch-disabled

return
Value of prefetchDisabledDescriptor

        return prefetchDisabledDescriptor;
    
public java.util.CollectiongetPrimaryKeyFields()

        
        PersistenceDescriptor pers = getPersistenceDescriptor();
        PersistentFieldInfo[] pkeyFields = pers.getPkeyFieldInfo();
        
        HashMap pkey = new HashMap();
        for(int i=0; i<pkeyFields.length; i++) {
            pkey.put(pkeyFields[i].name, pkeyFields[i]);
        }
        
        return pkey.values();        
        
    
public com.sun.enterprise.deployment.interfaces.QueryParsergetQueryParser()
Returns the query parser object

        return queryParser;
    
public java.util.CollectiongetSelectors()
Returns a collection of selector methods.

        if (selectors == null) {
            selectors = new HashSet();
            Class ejbClass = getEjbClass();
            Method[] methods = ejbClass.getMethods();
            for(int i=0; i<methods.length; i++) {
                if(methods[i].getName().startsWith(EJB_SELECT)) { //NOI18N
                    selectors.add(methods[i]);
                }
            }
        }
        
        return selectors;
    
public java.lang.StringgetUniqueName()

        if(uniqueName == null) {
            BundleDescriptor bundle = getEjbBundleDescriptor();
            Application application = bundle.getApplication();

            // Add ejb name and application name.
            StringBuffer rc = new StringBuffer().
                    append(getName()).
                    append(NAME_CONCATENATOR).
                    append(application.getRegistrationName());

            // If it's not just a module, add a module name.
            if (!application.isVirtual()) {
                rc.append(NAME_CONCATENATOR).
                   append(bundle.getModuleDescriptor().getArchiveUri());
            }

            uniqueName = getBaseName(getEjbClassName()) 
                    + getUniqueNumber(rc.toString());
        }

        return uniqueName;
    
public java.lang.StringgetUniqueNumber(java.lang.String num)

        //Modified to decrease the possibility of collision
        String newNum= "" + num.hashCode(); // NOI18N
        newNum = newNum.replace('-", NAME_PART_SEPARATOR); // NOI18N
        return newNum;
     
private booleanmethodsEqual(java.lang.reflect.Method m1, java.lang.reflect.Method m2, boolean compareDeclaringClass)
Checks whether two methods that might have been loaded by different class loaders are equal.

param
compareDeclaringClass if true, declaring class will be considered as part of equality test.

        boolean equal = false;

        do {
            String m1Name = m1.getName();
            String m2Name = m2.getName();

            if( !m1Name.equals(m2Name) ) { break; }
        
            String m1DeclaringClass = m1.getDeclaringClass().getName();
            String m2DeclaringClass = m2.getDeclaringClass().getName();

            if( compareDeclaringClass ) {
                if( !m1DeclaringClass.equals(m2DeclaringClass) ) { break; }
            }

            Class[] m1ParamTypes = m1.getParameterTypes();
            Class[] m2ParamTypes = m2.getParameterTypes();

            if( m1ParamTypes.length != m2ParamTypes.length ) { break; }

            equal = true;
            for(int pIndex = 0; pIndex < m1ParamTypes.length; pIndex++) {
                String m1ParamClass = m1ParamTypes[pIndex].getName();
                String m2ParamClass = m2ParamTypes[pIndex].getName();
                if( !m1ParamClass.equals(m2ParamClass) ) {
                    equal = false;
                    break;
                }
            }

        } while(false);

        return equal;
    
public voidsetClassLoader(java.lang.ClassLoader jcl)

        this.jcl = jcl;
    
public voidsetConcreteImplClassName(java.lang.String name)
Sets the State class implementation classname.

         concreteImplClassName = name;
    
public voidsetMappingProperties(java.lang.String mappingProperties)

         this.mappingProperties = mappingProperties;
    
public voidsetModuleDir(java.lang.String moduleRootDir)

        moduleDir = moduleRootDir;
    
public voidsetPcImplClassName(java.lang.String name)
Sets the State class implementation classname.

         pcImplClassName = name;
    
public voidsetPrefetchDisabledDescriptor(PrefetchDisabledDescriptor prefetchDisabledDescriptor)
Setter for prefetch-disabled

param
prefetchDisabledDescriptor New value of prefetchDisabledDescriptor.

        this.prefetchDisabledDescriptor = prefetchDisabledDescriptor;
    
public voidsetQueryParser(com.sun.enterprise.deployment.interfaces.QueryParser inParser)
This method sets the parser which would be used to parse the query parameter declaration given in sun-ejb-jar.xml. This method is called from JDOCodenerator class 's generate() method.

        queryParser = inParser;