FileDocCategorySizeDatePackage
EjbBundleNode.javaAPI DocGlassfish v2 API18005Fri May 04 22:31:40 BST 2007com.sun.enterprise.deployment.node.ejb

EjbBundleNode

public class EjbBundleNode extends com.sun.enterprise.deployment.node.BundleNode implements com.sun.enterprise.deployment.node.RootXMLNode
This class handles ejb bundle xml files
author
Jerome Dochez
version

Fields Summary
public static final com.sun.enterprise.deployment.node.XMLElement
tag
public static final String
PUBLIC_DTD_ID
public static final String
PUBLIC_DTD_ID_12
public static final String
SYSTEM_ID
The system ID of an ejb-jar document.
public static final String
SYSTEM_ID_12
public static final String
SCHEMA_ID_21
public static final String
SCHEMA_ID
public static final String
SPEC_VERSION
private static final List
systemIDs
private com.sun.enterprise.deployment.EjbBundleDescriptor
descriptor
Constructors Summary
public EjbBundleNode()

       super();
       // register sub XMLNodes
       registerElementHandler(new XMLElement(EjbTagNames.SESSION),
                                                            EjbSessionNode.class);           
       registerElementHandler(new XMLElement(EjbTagNames.ENTITY), 
                                                            EjbEntityNode.class);                   
       registerElementHandler(new XMLElement(EjbTagNames.MESSAGE_DRIVEN), 
                                                            MessageDrivenBeanNode.class);          
       registerElementHandler(new XMLElement(EjbTagNames.METHOD_PERMISSION), 
                                                            MethodPermissionNode.class);                  
       registerElementHandler(new XMLElement(EjbTagNames.ROLE), 
                                                            SecurityRoleNode.class, "addRole");       
       registerElementHandler(new XMLElement(EjbTagNames.CONTAINER_TRANSACTION), 
                                                            ContainerTransactionNode.class);       
       registerElementHandler(new XMLElement(EjbTagNames.EXCLUDE_LIST), 
                                                            ExcludeListNode.class);                     
       registerElementHandler(new XMLElement(EjbTagNames.RELATIONSHIPS), 
                                                            RelationshipsNode.class);                     
       registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION),
                                             MessageDestinationNode.class,
                                             "addMessageDestination");
       registerElementHandler(new XMLElement(EjbTagNames.APPLICATION_EXCEPTION),
                                             EjbApplicationExceptionNode.class,
                                             "addApplicationException");
       registerElementHandler(new XMLElement(EjbTagNames.INTERCEPTOR),
                              EjbInterceptorNode.class,
                              "addInterceptor");

       registerElementHandler(new XMLElement(EjbTagNames.INTERCEPTOR_BINDING),
                              InterceptorBindingNode.class,
                              "appendInterceptorBinding");
   
Methods Summary
public voidaddDescriptor(java.lang.Object newDescriptor)
Adds a new DOL descriptor instance to the descriptor instance associated with this XMLNode

param
descriptor the new descriptor

       
       if (newDescriptor instanceof EjbDescriptor) {
           descriptor.addEjb((EjbDescriptor) newDescriptor);
       } else if (newDescriptor instanceof RelationshipDescriptor) {
           descriptor.addRelationship((RelationshipDescriptor) newDescriptor);
       } else if (newDescriptor instanceof MethodPermissionDescriptor) {
           MethodPermissionDescriptor   nd = (MethodPermissionDescriptor) newDescriptor;
           MethodDescriptor[] array = nd.getMethods();
           for (int i=0;i<array.length;i++) {
                EjbDescriptor target  = descriptor.getEjbByName(array[i].getEjbName());           
                MethodPermission[] mps = nd.getMethodPermissions();
                for (int j=0;j<mps.length;j++) {
                    DOLUtils.getDefaultLogger().fine("Adding mp " + mps[j] + " to " + array[i] + " for ejb " + array[i].getEjbName());
                    target.addPermissionedMethod(mps[j], array[i]);
                }
            }
       } else super.addDescriptor(newDescriptor);       
   
private voidaddMethodPermissions(com.sun.enterprise.deployment.EjbDescriptor ejb, java.util.Map mpToMethods, java.util.Vector excludedMethods, MethodPermissionNode mpNode, org.w3c.dom.Node assemblyNode)

                
        if (mpToMethods==null || mpToMethods.size()==0) {
            return;
        }
        
        for (Iterator mpIterator = mpToMethods.keySet().iterator();mpIterator.hasNext();) {
            MethodPermission mp = (MethodPermission) mpIterator.next();
            if (mp.isExcluded()) {
                // we need to be sure the method descriptors knows who owns them
                Set methods = (Set) mpToMethods.get(mp);
                excludedMethods.addAll(methods);
            } else {
                MethodPermissionDescriptor mpd = new MethodPermissionDescriptor();
                mpd.addMethodPermission(mp);
                mpd.addMethods((Set) mpToMethods.get(mp));
                mpNode.writeDescriptor(assemblyNode, EjbTagNames.METHOD_PERMISSION, mpd, ejb);
            }
        }
    
public java.lang.ObjectgetDescriptor()

return
the descriptor instance to associate with this XMLNode

        
        if (descriptor==null) {
            descriptor = (EjbBundleDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
        }
        return descriptor;
    
protected java.util.MapgetDispatchTable()
all sub-implementation of this class can use a dispatch table to map xml element to method name on the descriptor class for setting the element value.

return
the map with the element name as a key, the setter method as a value

        // no need to be synchronized for now
        Map table = super.getDispatchTable();
        table.put(EjbTagNames.EJB_CLIENT_JAR, "setEjbClientJarUri");
        return table;
    
public java.lang.StringgetDocType()

return
the DOCTYPE of the XML file

        return null;
    
public java.lang.StringgetSpecVersion()

return
the default spec version level this node complies to

        return SPEC_VERSION;
    
public java.lang.StringgetSystemID()

return
the SystemID of the XML file

        return SCHEMA_ID;
    
public java.util.ListgetSystemIDs()

return
the list of SystemID of the XML schema supported

        return systemIDs;
    
protected com.sun.enterprise.deployment.node.XMLElementgetXMLRootTag()

return
the XML tag associated with this XMLNode

        return tag;
    
private static java.util.ListinitSystemIDs()

        ArrayList<String> systemIDs = new ArrayList<String>();
        systemIDs.add(SCHEMA_ID);
        systemIDs.add(SCHEMA_ID_21);
        return Collections.unmodifiableList(systemIDs);
   
public static java.lang.StringregisterBundle(java.util.Map publicIDToDTD)
register this node as a root node capable of loading entire DD files

param
publicIDToDTD is a mapping between xml Public-ID to DTD
return
the doctype tag name


                                     
        
        publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID);
        publicIDToDTD.put(PUBLIC_DTD_ID_12, SYSTEM_ID_12);
        return tag.getQName();
   
private voidwriteAssemblyDescriptor(org.w3c.dom.Node parentNode, com.sun.enterprise.deployment.EjbBundleDescriptor bundleDescriptor)
write assembly-descriptor related xml information to the DOM tree

       Node assemblyNode = parentNode.getOwnerDocument().createElement(EjbTagNames.ASSEMBLY_DESCRIPTOR);
       
       // security-role*
       SecurityRoleNode roleNode = new SecurityRoleNode();
       for (Iterator e = bundleDescriptor.getRoles().iterator();e.hasNext();) {
           roleNode.writeDescriptor(assemblyNode, EjbTagNames.ROLE, (Role) e.next());
       }
       
       // method-permission*       
       Map excludedMethodsByEjb = new HashMap();
       MethodPermissionNode mpNode = new MethodPermissionNode();       
       for (Iterator e = bundleDescriptor.getEjbs().iterator();e.hasNext();) {
           EjbDescriptor ejbDesc = (EjbDescriptor) e.next();
           if (ejbDesc instanceof EjbMessageBeanDescriptor)                
               continue;
           Vector excludedMethods = new Vector();
           addMethodPermissions(ejbDesc, ejbDesc.getPermissionedMethodsByPermission(), excludedMethods,  mpNode, assemblyNode);
           addMethodPermissions(ejbDesc, ejbDesc.getStyledPermissionedMethodsByPermission(), excludedMethods, mpNode, assemblyNode);
           if (excludedMethods.size()>0) {
               excludedMethodsByEjb.put(ejbDesc, excludedMethods);
           }
       }
       
       // container-transaction*
       ContainerTransactionNode ctNode = new ContainerTransactionNode();
       for (Iterator e = bundleDescriptor.getEjbs().iterator();e.hasNext();) {
           EjbDescriptor ejbDesc = (EjbDescriptor) e.next();
           ctNode.writeDescriptor(assemblyNode, EjbTagNames.CONTAINER_TRANSACTION, ejbDesc);
       }

       // interceptor-binding*
       Set ejbsForInterceptors = bundleDescriptor.getEjbs();
       InterceptorBindingNode interceptorBindingNode = new 
           InterceptorBindingNode();

        for(Iterator itr = ejbsForInterceptors.iterator(); itr.hasNext();) {

            EjbDescriptor ejbDesc = (EjbDescriptor) itr.next();
            if( ejbDesc.getInterceptorClasses().size() > 0 ) {
                interceptorBindingNode.writeBindings(assemblyNode, 
                                                     ejbDesc);
            }

        }
       

       // message-destination*
       writeMessageDestinations
           (assemblyNode, bundleDescriptor.getMessageDestinations().iterator());
                                
       // exclude-list*              
       if (excludedMethodsByEjb.size()>0) {
           Node excludeListNode = this.appendChild(assemblyNode, EjbTagNames.EXCLUDE_LIST);
           for (Iterator ejbs = excludedMethodsByEjb.keySet().iterator(); ejbs.hasNext();) {
               EjbDescriptor ejbDesc = (EjbDescriptor) ejbs.next();
               Vector excludedMethods = (Vector) excludedMethodsByEjb.get(ejbDesc);
               
               MethodPermissionDescriptor mpd = new MethodPermissionDescriptor();
               mpd.addMethodPermission(MethodPermission.getExcludedMethodPermission());
               mpd.addMethods(excludedMethods);
               mpNode.writeDescriptorInNode(excludeListNode, mpd, ejbDesc);
           }
       }
       
       for(EjbApplicationExceptionInfo next : 
               bundleDescriptor.getApplicationExceptions()) {

           EjbApplicationExceptionNode node = new EjbApplicationExceptionNode();
           
           node.writeDescriptor(assemblyNode, EjbTagNames.APPLICATION_EXCEPTION,
                                next);

       }

       if (assemblyNode.hasChildNodes()) {
           parentNode.appendChild(assemblyNode);
       }
    
public org.w3c.dom.NodewriteDescriptor(org.w3c.dom.Node parent, com.sun.enterprise.deployment.Descriptor descriptor)
write the descriptor class to a DOM tree and return it

param
parent node for the DOM tree
param
the descriptor to write
return
the DOM tree top node

        
        if (! (descriptor instanceof EjbBundleDescriptor)) {
            throw new IllegalArgumentException(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
        }
        EjbBundleDescriptor ejbDesc = (EjbBundleDescriptor) descriptor;
        Node jarNode = super.writeDescriptor(parent, ejbDesc);           
        Node entrepriseBeansNode = appendChild(jarNode, EjbTagNames.EJBS);
        for (Iterator ejbs = ejbDesc.getEjbs().iterator();ejbs.hasNext();) {
            EjbDescriptor ejb = (EjbDescriptor) ejbs.next();
            if (EjbSessionDescriptor.TYPE.equals(ejb.getType())) {
                EjbNode subNode = new EjbSessionNode();
                subNode.writeDescriptor(entrepriseBeansNode, 
                                                                            EjbTagNames.SESSION, ejb);
            }  else if (EjbEntityDescriptor.TYPE.equals(ejb.getType())) {
                EjbNode subNode = new EjbEntityNode();
                subNode.writeDescriptor(entrepriseBeansNode, 
                                                                            EjbTagNames.ENTITY, ejb);
            } else if (EjbMessageBeanDescriptor.TYPE.equals(ejb.getType())) {
                EjbNode subNode = new MessageDrivenBeanNode();
                subNode.writeDescriptor(entrepriseBeansNode, 
                                                                            EjbTagNames.MESSAGE_DRIVEN, ejb);
            }  else {
                throw new IllegalStateException("Unknow ejb type " + ejb.getType());
            }
        }

        if( ejbDesc.hasInterceptors() ) {

            Node interceptorsNode = appendChild(jarNode, 
                                                EjbTagNames.INTERCEPTORS);
            EjbInterceptorNode interceptorNode = new EjbInterceptorNode();
            for(EjbInterceptor next : ejbDesc.getInterceptors()) {
                interceptorNode.writeDescriptor( interceptorsNode,
                                                 EjbTagNames.INTERCEPTOR, next);
            }

        }
        
        // relationships*
        if (ejbDesc.hasRelationships()) {
            (new RelationshipsNode()).writeDescriptor(jarNode, EjbTagNames.RELATIONSHIPS, ejbDesc);
        }
        
        // assembly-descriptor
        writeAssemblyDescriptor(jarNode, ejbDesc);
        
        appendTextChild(jarNode, EjbTagNames.EJB_CLIENT_JAR, ejbDesc.getEjbClientJarUri());        
        return jarNode;