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

EjbBundleDescriptor

public class EjbBundleDescriptor extends BundleDescriptor
I represent all the configurable deployment information contained in an EJB JAR.
author
Danny Coward

Fields Summary
public static final String
SPEC_VERSION
private long
uniqueId
private Set
ejbs
private Set
relationships
private String
relationshipsDescription
private String
ejbClientJarUri
private Vector
configured_pms
private com.sun.enterprise.deployment.runtime.PersistenceManagerInUse
pm_inuse
private ResourceReferenceDescriptor
cmpResourceReference
private Set
applicationExceptions
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
static Logger
_logger
private List
roleMaps
private Map
interceptors
private LinkedList
interceptorBindings
Constructors Summary
public EjbBundleDescriptor()
Constructs an ejb bundle descriptor with no ejbs.


                 
      
    
Methods Summary
public voidaddApplicationException(EjbApplicationExceptionInfo appExc)

        applicationExceptions.add(appExc);
    
public voidaddEjb(EjbDescriptor ejbDescriptor)
Add an ejb to me.

	ejbDescriptor.setEjbBundleDescriptor(this);
	this.getEjbs().add(ejbDescriptor);
	super.changed();
    
public voidaddEjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor ejbBundleDescriptor)

	super.addBundleDescriptor(ejbBundleDescriptor);

	// mdf - #4400074 ejb added to existing ejb-jar in wizard has wrong bundle
	//this.getEjbs().addAll(ejbBundleDescriptor.getEjbs());
        for (Iterator ejbs = ejbBundleDescriptor.getEjbs().iterator(); ejbs.hasNext();) {
            EjbDescriptor ejbDescriptor = (EjbDescriptor)ejbs.next();
	    ejbDescriptor.setEjbBundleDescriptor(this);
	    this.getEjbs().add(ejbDescriptor);
	}

	// WebServices
	WebServicesDescriptor thisWebServices = this.getWebServices();
	WebServicesDescriptor otherWebServices = ejbBundleDescriptor.getWebServices();
	for (Iterator i = otherWebServices.getWebServices().iterator(); i.hasNext();) {
	    WebService ws = (WebService)i.next();
	    thisWebServices.addWebService(new WebService(ws));
	}

	this.changed();
    
public voidaddInterceptor(EjbInterceptor interceptor)

        EjbInterceptor ic =
            getInterceptorByClassName(interceptor.getInterceptorClassName());
        if (ic == null) {
            interceptor.setEjbBundleDescriptor(this);
            interceptors.put(interceptor.getInterceptorClassName(), interceptor);
        }                 
    
public voidaddPersistenceManager(com.sun.enterprise.deployment.runtime.IASPersistenceManagerDescriptor pmDesc)

        if (configured_pms==null) {
            configured_pms=new Vector();
        }
        configured_pms.add(pmDesc);
        if (_logger.isLoggable(Level.FINE))
            _logger.fine("***IASEjbBundleDescriptor"
               + ".addPersistenceManager done -#- ");
    
public voidaddRelationship(RelationshipDescriptor relDesc)
Add a RelationshipDescriptor which describes a CMR field between a bean/DO/entityRef in this ejb-jar.

        relationships.add(relDesc);
        super.changed();
    
public voidaddSecurityRoleMapping(com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping roleMapping)

        roleMaps.add(roleMapping);
    
public voidappendInterceptorBinding(InterceptorBindingDescriptor binding)

        interceptorBindings.addLast(binding);
    
public booleanareResourceReferencesValid()
Checks whether the role references my ejbs have reference roles that I have.

	// run through each of the ejb's role references, checking that the roles exist in this bundle
	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
	    for (Iterator roleRefs = ejbDescriptor.getRoleReferences().iterator(); roleRefs.hasNext();) {
		RoleReference roleReference = (RoleReference) roleRefs.next();
		Role referredRole = roleReference.getRole();
		if (!referredRole.getName().equals("") 
		    && !super.getRoles().contains(referredRole) ) {
			
		    _logger.log(Level.FINE,localStrings.getLocalString(
			   "enterprise.deployment.badrolereference",
			   "Warning: Bad role reference to {0}", new Object[] {referredRole}));
		    _logger.log(Level.FINE,"Roles:  "+ this.getRoles());
		    return false;
		}
	    }
	}
	return true;
    
public booleancontainsCMPEntity()

return
true if this bundle descriptor contains at least one CMP EntityBean

        
        Set ejbs = getEjbs();
        if (ejbs==null)
            return false;
        for (Iterator ejbsItr = ejbs.iterator();ejbsItr.hasNext();) {
            if (ejbsItr.next() instanceof EjbCMPEntityDescriptor) {
                return true;
            }
        }
        return false;
    
private voiddoMethodDescriptorConversions()

 	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
 	    EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
 	    ejbDescriptor.doMethodDescriptorConversions();
 	}
    
public java.util.CollectionfindReferencedPUs()
{@inheritDoc}

        Collection<PersistenceUnitDescriptor> pus =
                new HashSet<PersistenceUnitDescriptor>();
        for (EjbDescriptor ejb :
                (Collection<EjbDescriptor>)getEjbs()) {
            pus.addAll(findReferencedPUsViaPURefs(ejb));
            pus.addAll(findReferencedPUsViaPCRefs(ejb));
        }
        return pus;
    
public java.util.SetgetApplicationExceptions()

        return new HashSet<EjbApplicationExceptionInfo>(applicationExceptions);
    
public ResourceReferenceDescriptorgetCMPResourceReference()
Return the Resource I use for CMP.

	return this.cmpResourceReference;
    
public java.lang.StringgetDefaultSpecVersion()

return
the default version of the deployment descriptor loaded by this descriptor

        return EjbBundleNode.SPEC_VERSION;
    
public DescriptorgetDescriptorByName(java.lang.String name)

        
        try {
            return getEjbByName(name);
        } catch(IllegalArgumentException iae) {
            // Bundle doesn't contain ejb with the given name.
            return null;
        }
    
public EjbDescriptor[]getEjbByClassName(java.lang.String className)
Returns all ejb descriptors that has a give Class name. It returns an empty array if no ejb is found.

        ArrayList<EjbDescriptor> ejbList = new ArrayList<EjbDescriptor>();
	for (Object ejb : this.getEjbs()) {
            if (ejb instanceof EjbDescriptor) {
                EjbDescriptor ejbDesc = (EjbDescriptor)ejb;
                if (className.equals(ejbDesc.getEjbClassName())) {
                    ejbList.add(ejbDesc);
                }
            }
	}
        return ejbList.toArray(new EjbDescriptor[ejbList.size()]);
    
public EjbDescriptorgetEjbByName(java.lang.String name)
Returns an ejb descriptor that I have by the same name, otherwise throws an IllegalArgumentException

        return getEjbByName(name, false);
    
public EjbDescriptorgetEjbByName(java.lang.String name, boolean isCreateDummy)
Returns an ejb descriptor that I have by the same name. Create a DummyEjbDescriptor if requested, otherwise throws an IllegalArgumentException

	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    Descriptor next = (Descriptor) itr.next();
	    if (next.getName().equals(name)) {
		return (EjbDescriptor) next;
	    }
	}

        if (!isCreateDummy) {   
            throw new IllegalArgumentException(localStrings.getLocalString(
                "enterprise.deployment.exceptionbeanbundle",
                "Referencing error: this bundle has no bean of name: {0}",
                new Object[] {name}));
        }

        // there could be cases where the annotation defines the ejb component
        // and the ejb-jar.xml just uses it 
        // we have to create a dummy version of the ejb descriptor in this 
        // case as we process xml before annotations.
        _logger.log(Level.FINE, "enterprise.deployment_dummy_ejb_descriptor",
                        new Object[] {name});
        DummyEjbDescriptor dummyEjbDesc = new DummyEjbDescriptor();
        dummyEjbDesc.setName(name);
        addEjb(dummyEjbDesc);
        return dummyEjbDesc;
    
public EjbDescriptor[]getEjbBySEIName(java.lang.String className)
Returns all ejb descriptors that has a given Class name as the web service endpoint interface. It returns an empty array if no ejb is found.

        ArrayList<EjbDescriptor> ejbList = new ArrayList<EjbDescriptor>();
	for (Object ejb : this.getEjbs()) {
            if (ejb instanceof EjbDescriptor) {
                EjbDescriptor ejbDesc = (EjbDescriptor)ejb;
                if (className.equals(ejbDesc.getWebServiceEndpointInterfaceName())) {
                    ejbList.add(ejbDesc);
                }
            }
	}
        return ejbList.toArray(new EjbDescriptor[ejbList.size()]);
    
public java.lang.StringgetEjbClientJarUri()
Return the emptry String or the entry name of the ejb client JAR in my archive if I have one.

	if (this.ejbClientJarUri == null) {
	    this.ejbClientJarUri = "";
	}
	return this.ejbClientJarUri;
    
public java.util.SetgetEjbs()
Return the Set of ejb descriptors that I have.

	return this.ejbs;
    
public static intgetIdFromEjbId(long ejbId)

	long id = ejbId >> 32;	
	return (int)id;
    
public java.util.ListgetInterceptorBindings()

        return new LinkedList<InterceptorBindingDescriptor>
            (interceptorBindings);
    
public EjbInterceptorgetInterceptorByClassName(java.lang.String className)


        return interceptors.get(className);

    
public java.util.SetgetInterceptors()


        return new HashSet<EjbInterceptor>(interceptors.values());

    
public javax.enterprise.deploy.shared.ModuleTypegetModuleType()

return
the module type for this bundle descriptor

        return ModuleType.EJB;
    
public java.lang.StringgetName()
Returns my name.

	if ("".equals(super.getName())) {
	    super.setName("Ejb1");
	}
	return super.getName();
    
public java.util.CollectiongetNamedDescriptors()
Return the set of NamedDescriptors that I have.

	Collection namedDescriptors = new Vector();
	for (Iterator ejbs = this.getEjbs().iterator(); ejbs.hasNext();) {
	    EjbDescriptor ejbDescriptor = (EjbDescriptor) ejbs.next();
	    namedDescriptors.add(ejbDescriptor);
	    namedDescriptors.addAll(super.getNamedDescriptorsFrom(ejbDescriptor));
	}
	return namedDescriptors;
    
public java.util.VectorgetNamedReferencePairs()
Return all the named descriptors I have together with the descriptor that references each one in a Vector of NameReferencePairs.

	Vector pairs = new Vector();
	for (Iterator ejbs = this.getEjbs().iterator(); ejbs.hasNext();) {
	    EjbDescriptor ejbDescriptor = (EjbDescriptor) ejbs.next();
	    pairs.add(NamedReferencePair.createEjbPair(ejbDescriptor, 
                                                       ejbDescriptor));
	    pairs.addAll(super.getNamedReferencePairsFrom(ejbDescriptor));
	}
	return pairs;
    
public com.sun.enterprise.deployment.runtime.PersistenceManagerInUsegetPersistenceManagerInUse()

        return pm_inuse;
    
public java.util.VectorgetPersistenceManagers()

        if (_logger.isLoggable(Level.FINE))
	    _logger.fine("***IASEjbBundleDescriptor.getPersistenceManagers done -#- ");
	return configured_pms;
    
public com.sun.enterprise.deployment.runtime.IASPersistenceManagerDescriptorgetPreferredPersistenceManager()

        boolean debug = _logger.isLoggable(Level.FINE);

        if (configured_pms == null || configured_pms.size() == 0) {
            // return the default persistence manager descriptor
            return null;
        }

        String pminuse_id 	= pm_inuse.get_pm_identifier().trim();
        String pminuse_ver  = pm_inuse.get_pm_version().trim();
        if (debug) {
             _logger.fine("IASPersistenceManagerDescriptor.getPreferred - inid*" + 
                pminuse_id.trim() + "*"); 
             _logger.fine("IASPersistenceManagerDescriptor.getPreferred - inver*" + 
                pminuse_ver.trim() + "*"); 
        }

        int size = configured_pms.size();
        for(int i = 0; i < size; i++) {
            IASPersistenceManagerDescriptor pmdesc=(IASPersistenceManagerDescriptor)configured_pms.elementAt(i);
	    String pmdesc_id 	= pmdesc.getPersistenceManagerIdentifier();
	    String pmdesc_ver 	= pmdesc.getPersistenceManagerVersion();

            if (debug) {
	        _logger.fine("IASPersistenceManagerDescriptor.getPreferred - pmid*" + 
                    pmdesc_id.trim() + "*"); 
	        _logger.fine("IASPersistenceManagerDescriptor.getPreferred - pmver*" + 
                    pmdesc_ver.trim() + "*"); 
            }


            if( ((pmdesc_id.trim()).equals(pminuse_id)) && 
                ((pmdesc_ver.trim()).equals(pminuse_ver)) ) {

                if (debug)
		    _logger.fine("***IASEjbBundleDescriptor.getPreferredPersistenceManager done -#- ");

                return (IASPersistenceManagerDescriptor)pmdesc;
	    }
	}
	throw new IllegalArgumentException(localStrings.getLocalString(
	   "enterprise.deployment.nomatchingpminusefound",
	   "No PersistenceManager found that matches specified PersistenceManager in use."));
    
public java.util.SetgetRelationships()
Get all relationships in this ejb-jar.

return
a Set of RelationshipDescriptors.

        return relationships;
    
public java.lang.StringgetRelationshipsDescription()
EJB2.0: get description for element.

	if ( relationshipsDescription == null )
	    relationshipsDescription = "";
	return relationshipsDescription;
    
public java.util.SetgetResourceReferenceDescriptors()
Return the set of references to resources that I have.

	Set resourceReferences = new HashSet();
	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
	    resourceReferences.addAll(ejbDescriptor.getResourceReferenceDescriptors());
	}
	return resourceReferences;
    
public java.util.ListgetSecurityRoleMappings()

        return roleMaps;
    
public java.util.SetgetServiceReferenceDescriptors()

return
a set of service-ref from this bundle or null if none

        Set serviceRefs = new OrderedSet();
        for(Iterator ejbs = getEjbs().iterator();ejbs.hasNext();) {
            EjbDescriptor next = (EjbDescriptor) ejbs.next();
            serviceRefs.addAll(next.getServiceReferenceDescriptors());
        }
        return serviceRefs;        
    
public longgetUniqueId()
Returns the unique id used in a stand alone ejb module. For application, this will return zero.

return
the unique if used in stand alone ejb module

        return uniqueId;
    
public booleanhasAssemblyInformation()
Return true if I have roles, permissioned roles or container transactions.

	return (!this.getRoles().isEmpty())
		|| this.hasPermissionedRoles()
		    || this.hasContainerTransactions();
    
    
public booleanhasContainerTransactions()
Return true if any of my ejb's methods have been assigned transaction attributes.

	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    EjbDescriptor nextEjbDescriptor = (EjbDescriptor) itr.next();
	    if (!nextEjbDescriptor.getMethodContainerTransactions().isEmpty()) {
		return true;
	    }
	}
	return false;
    
public booleanhasEjbByName(java.lang.String name)
Returns true if I have an ejb descriptor by that name.

	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    Descriptor next = (Descriptor) itr.next();
	    if (next.getName().equals(name)) {
		return true;
	    }
	}
	return false;
    
public booleanhasEjbReferences()
Return true if I reference other ejbs, false else.

	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    EjbDescriptor nextEjbDescriptor = (EjbDescriptor) itr.next();
	    if (!nextEjbDescriptor.getEjbReferenceDescriptors().isEmpty()) {
		return true;
	    }
	}
	return false;
    
public booleanhasInterceptors()


        return (interceptors.size() > 0);

    
public booleanhasPermissionedRoles()
Returns true if I have Roles to which method permissions have been assigned.

	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    EjbDescriptor nextEjbDescriptor = (EjbDescriptor) itr.next();
	    if (!nextEjbDescriptor.getPermissionedMethodsByPermission().isEmpty()) {
		return true;
	    }
	}
	return false;
    
public booleanhasRelationship(RelationshipDescriptor rd)
Returns true if given relationship is already part of this ejb-jar.

        return relationships.contains(rd);
    
public booleanhasRelationships()

	return (relationships.size() > 0);
    
public booleanhasWebServiceClients()

return
true if this bundle descriptor defines web service clients

        for(Iterator ejbs = getEjbs().iterator();ejbs.hasNext();) {
            EjbDescriptor next = (EjbDescriptor) ejbs.next();
            Collection serviceRefs = next.getServiceReferenceDescriptors();
            if( !(serviceRefs.isEmpty()) ) {
               return true;
            }
        }
        return false;
    
public booleanisEJB11()
True if EJB version is 1.x.

        return getSpecVersion().startsWith("1");
    
public booleanisEJB20()
True if EJB version is 2.x. This is the default for any new modules.

        return !isEJB11();
    
public voidprependInterceptorBinding(InterceptorBindingDescriptor binding)

        interceptorBindings.addFirst(binding);
    
public voidprint(java.lang.StringBuffer toStringBuffer)
Returns a formatted String representing my state.

	toStringBuffer.append("EjbBundleDescriptor\n");
        super.print(toStringBuffer);
        if (cmpResourceReference!=null) {
            toStringBuffer.append("\ncmp resource ");
            ((Descriptor)cmpResourceReference).print(toStringBuffer);
        }
	toStringBuffer.append("\nclient JAR ").append(this.getEjbClientJarUri());
	for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
	    toStringBuffer.append("\n------------\n");
	    ((Descriptor)itr.next()).print(toStringBuffer);
	    toStringBuffer.append("\n------------") ;
	}
    
public voidremoveEjb(EjbDescriptor ejbDescriptor)
Remove the given ejb descriptor from my (by equality).

	ejbDescriptor.setEjbBundleDescriptor(null);
	this.getEjbs().remove(ejbDescriptor);
	super.changed();
    
public voidremoveRelationship(RelationshipDescriptor relDesc)
Add a RelationshipDescriptor which describes a CMR field between a bean/DO/entityRef in this ejb-jar.

        relationships.remove(relDesc);
        super.changed();
    
public voidremoveRole(com.sun.enterprise.deployment.Role role)
Removes the given com.sun.enterprise.deployment.Role object from me.

	if (super.getRoles().contains(role)) {
	    for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
		EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
		ejbDescriptor.removeRole(role);
	    }
	    super.removeRole(role);
	}
    
voidreplaceEjb(EjbDescriptor oldEjbDescriptor, EjbDescriptor newEjbDescriptor)
Called only from EjbDescriptor.replaceEjbDescriptor, in wizard mode.

	oldEjbDescriptor.setEjbBundleDescriptor(null);
	this.getEjbs().remove(oldEjbDescriptor);
	newEjbDescriptor.setEjbBundleDescriptor(this);
	this.getEjbs().add(newEjbDescriptor);
	//super.changed();  no need to notify listeners in wizard mode ??
    
public voidsetCMPResourceReference(ResourceReferenceDescriptor resourceReference)
Sets the resource reference I use for CMP.

	this.cmpResourceReference = resourceReference;
	this.changed();
    
public voidsetEjbClientJarUri(java.lang.String ejbClientJarUri)
Sets the ejb client JAR entry name.

	this.ejbClientJarUri = ejbClientJarUri;
	this.changed();
    
public voidsetInterceptorBindings(java.util.List bindings)

        interceptorBindings = new LinkedList<InterceptorBindingDescriptor>();
        interceptorBindings.addAll(bindings);
    
public voidsetPersistenceManagerInUse(com.sun.enterprise.deployment.runtime.PersistenceManagerInUse inuse)

	pm_inuse = inuse;
    
public voidsetPersistenceManagerInuse(java.lang.String id, java.lang.String ver)

	pm_inuse=new PersistenceManagerInUse(id, ver);
        if (_logger.isLoggable(Level.FINE))
	    _logger.fine("***IASEjbBundleDescriptor"
                + ".setPersistenceManagerInUse done -#- ");
    
public voidsetRelationshipsDescription(java.lang.String relationshipsDescription)
EJB2.0: set description for element.

	this.relationshipsDescription = relationshipsDescription;
    
public voidsetUniqueId(long id)
Sets the unique id for a stand alone ejb module. It traverses through all the ejbs in this stand alone module and sets the unique id for each of them. The traversal order is done in ascending element order.

Note: This method will not be called for application.

param
id unique id for stand alone module

        this.uniqueId  = id;

        // First sort the beans in alphabetical order.
        EjbDescriptor[] descs = (EjbDescriptor[])ejbs.toArray(
                                    new EjbDescriptor[ejbs.size()]);


        // The sorting algorithm used by this api is a modified mergesort.
        // This algorithm offers guaranteed n*log(n) performance, and 
        // can approach linear performance on nearly sorted lists. 
        Arrays.sort(descs, 
            new Comparator() {
                public int compare(Object o1, Object o2) {
                    return (((EjbDescriptor)o1).getName()).compareTo(
                                            ((EjbDescriptor)o2).getName());
                }
            }
        );

        for (int i=0; i<descs.length; i++)
        {
            // 2^16 beans max per stand alone module
            descs[i].setUniqueId( (id | i) );
        }
    
public voidvisit(com.sun.enterprise.deployment.util.DescriptorVisitor aVisitor)
visit the descriptor and all sub descriptors with a DOL visitor implementation

param
a visitor to traverse the descriptors

        if (aVisitor instanceof EjbBundleVisitor) {
            visit((EjbBundleVisitor) aVisitor);
        } else {
            super.visit(aVisitor);
        }
    
public voidvisit(com.sun.enterprise.deployment.util.EjbBundleVisitor aVisitor)
visit the descriptor and all sub descriptors with a DOL visitor implementation

param
a visitor to traverse the descriptors

        aVisitor.accept(this);
        EjbVisitor ejbVisitor = aVisitor.getEjbVisitor();
        if (ejbVisitor != null) {
            for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) {
                EjbDescriptor anEjb = (EjbDescriptor) itr.next();
                anEjb.visit(ejbVisitor);
            }
        }
        if (hasRelationships()) {
            for (Iterator itr = getRelationships().iterator();itr.hasNext();) {
                RelationshipDescriptor rd = (RelationshipDescriptor) itr.next();
                aVisitor.accept(rd);
            }
        }
        for (Iterator itr=getWebServices().getWebServices().iterator();
             itr.hasNext(); ) {
            WebService aWebService = (WebService) itr.next();
            aVisitor.accept(aWebService);
        }
        for (Iterator itr = getMessageDestinations().iterator();
                itr.hasNext();) {
            MessageDestinationDescriptor msgDestDescriptor =
                (MessageDestinationDescriptor)itr.next();
            aVisitor.accept(msgDestDescriptor);
        }