FileDocCategorySizeDatePackage
BundleNode.javaAPI DocGlassfish v2 API11639Fri May 04 22:31:38 BST 2007com.sun.enterprise.deployment.node

BundleNode

public abstract class BundleNode extends DisplayableComponentNode implements RootXMLNode
This class defines all the common behaviour among nodes responsibles for handling bundles
author
Jerome Dochez

Fields Summary
public static final String
W3C_XML_SCHEMA
public static final String
W3C_XML_SCHEMA_INSTANCE
protected static final String
SCHEMA_LOCATION_TAG
protected String
docType
private Map
namespaceContext
Constructors Summary
Methods Summary
protected voidaddBundleNodeAttributes(org.w3c.dom.Element bundleNode, com.sun.enterprise.deployment.RootDeploymentDescriptor descriptor)
write the necessary attributes for the root node of this DDs document

        String schemaLocation;
        // the latest connector schema still use j2ee namespace
        if (descriptor instanceof ConnectorDescriptor) {
            bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", TagNames.J2EE_NAMESPACE);    
            schemaLocation = TagNames.J2EE_NAMESPACE + " " + 
                getSchemaURL();
        } else {
            bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", TagNames.JAVAEE_NAMESPACE);    
            schemaLocation = TagNames.JAVAEE_NAMESPACE + " " + 
                getSchemaURL();
        }
        bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", W3C_XML_SCHEMA_INSTANCE);    

        // add all custom global namespaces
        addNamespaceDeclaration(bundleNode, descriptor);
        String clientSchemaLocation = descriptor.getSchemaLocation();
        if (clientSchemaLocation!=null) {
            schemaLocation = schemaLocation + " " + clientSchemaLocation;
        }
        bundleNode.setAttributeNS(W3C_XML_SCHEMA_INSTANCE, SCHEMA_LOCATION_TAG, schemaLocation);
        bundleNode.setAttribute(TagNames.VERSION, getSpecVersion());        

        // Write out full attribute for DD which allows annotations.
        // The full attribute should always be written out as true since 
        // when we come here to write it out, the annotation information
        // has already been processed and saved in DD, so written out DD
        // is always a full DD.
        if (descriptor instanceof BundleDescriptor) {
            BundleDescriptor bundleDesc = (BundleDescriptor)descriptor;
            if (! bundleDesc.isDDWithNoAnnotationAllowed()) {
                bundleNode.setAttribute(TagNames.METADATA_COMPLETE, "true"); 
            }
        }
    
public voidaddPrefixMapping(java.lang.String prefix, java.lang.String uri)
notify of a new prefix mapping used in this document

        // we don't care about the default ones...
        if (uri.equals(TagNames.J2EE_NAMESPACE)) 
            return;
        if (uri.equals(TagNames.JAVAEE_NAMESPACE)) 
            return;
        if (uri.equals(W3C_XML_SCHEMA_INSTANCE)) 
            return;
        super.addPrefixMapping(prefix, uri);
    
public static org.w3c.dom.ElementappendChildNS(org.w3c.dom.Node parent, java.lang.String elementName, java.lang.String nameSpace)

        Element child = getOwnerDocument(parent).createElementNS(nameSpace, elementName);
        parent.appendChild(child);
        return child;
    
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

        Map dispatchTable = super.getDispatchTable();
        dispatchTable.put(TagNames.NAME, "setDisplayName");        
        dispatchTable.put(TagNames.VERSION, "setSpecVersion");
        return dispatchTable;
    
protected java.lang.StringgetSchemaURL()

return
the complete URL for JAVAEE schemas

       // by default, it comes from our web site
       return TagNames.JAVAEE_NAMESPACE + "/" + getSystemID();
    
public voidsetDocType(java.lang.String docType)
set the DOCTYPE as read in the input XML File

param
DOCTYPE

    
                     
        
        this.docType = docType;
        setSpecVersion();
    
public voidsetElementValue(XMLElement element, java.lang.String value)
receives notiification of the value for a particular tag

param
element the xml element
param
value it's associated value

    
        if (SCHEMA_LOCATION_TAG.equals(element.getCompleteName())) {    
            // we need to keep all the non j2ee/javaee schemaLocation tags
            StringTokenizer st = new StringTokenizer(value);
            StringBuffer sb = new StringBuffer();
            while (st.hasMoreElements()) {
                String namespace = (String) st.nextElement();
		String schema;
		if (st.hasMoreElements()) {
		    schema = (String) st.nextElement();
		} else {
		    schema = namespace;
		    namespace = TagNames.JAVAEE_NAMESPACE;
		}
                if (namespace.equals(TagNames.J2EE_NAMESPACE)) 
                    continue;
                if (namespace.equals(TagNames.JAVAEE_NAMESPACE)) 
                    continue;
                if (namespace.equals(W3C_XML_SCHEMA)) 
                    continue;
                sb.append(namespace);
                sb.append(" ");
                sb.append(schema);
            }
            String clientSchemaLocation = sb.toString();
            if (clientSchemaLocation!=null && clientSchemaLocation.length()!=0) {
                Object o = getDescriptor();
                if (o instanceof RootDeploymentDescriptor) {
                    ((RootDeploymentDescriptor) o).setSchemaLocation(clientSchemaLocation);
                }
            }
        } else if (element.getQName().equals(TagNames.METADATA_COMPLETE)) {
            Object o = getDescriptor();
            if (o instanceof BundleDescriptor) {
                ((BundleDescriptor) o).setFullAttribute(value);
            }
        } else {
            super.setElementValue(element, value);
        }
    
protected voidsetSpecVersion()
Sets the specVersion for this descriptor depending on the docType

        if (docType==null)
            return;
        StringTokenizer st = new StringTokenizer(docType, "//");        
        while (st.hasMoreElements()) {
            String tmp = st.nextToken();
            if (tmp.startsWith("DTD")) {
                // this is the string we are interested in
                StringTokenizer versionST = new StringTokenizer(tmp);
                while (versionST.hasMoreElements()) {
                    String versionStr = versionST.nextToken();
                    try {
                        Float.valueOf(versionStr);
                        RootDeploymentDescriptor rdd = (RootDeploymentDescriptor) getDescriptor();
                        rdd.setSpecVersion(versionStr);
                        return;
                    } catch(NumberFormatException nfe) {
                        // ignore, this is just the other info of the publicID
                    }
                }
            }
        }            
    
public org.w3c.dom.NodewriteDescriptor(org.w3c.dom.Node parent, com.sun.enterprise.deployment.RootDeploymentDescriptor 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

        Node bundleNode;
        if (getDocType()==null) {
            // we are using schemas for this DDs
 
            // connector schema still use j2ee name space
            if (descriptor instanceof ConnectorDescriptor) {
                bundleNode = appendChildNS(parent, getXMLRootTag().getQName(),
                    TagNames.J2EE_NAMESPACE);    
            } else {
                bundleNode = appendChildNS(parent, getXMLRootTag().getQName(),
                    TagNames.JAVAEE_NAMESPACE);    
            }
            addBundleNodeAttributes((Element) bundleNode, descriptor);
        } else {              
            bundleNode = appendChild(parent, getXMLRootTag().getQName());
        }
        // description, display-name, icons...
        writeDisplayableComponentInfo(bundleNode, descriptor);
       
        
        return bundleNode;
    
protected voidwriteMessageDestinations(org.w3c.dom.Node parentNode, java.util.Iterator msgDestinations)

        if ( (msgDestinations == null) || !msgDestinations.hasNext() ) 
            return;
        
        MessageDestinationNode subNode = new MessageDestinationNode();
        for (;msgDestinations.hasNext();) {
            MessageDestinationDescriptor next = 
                (MessageDestinationDescriptor) msgDestinations.next();
            subNode.writeDescriptor(parentNode, 
                                    TagNames.MESSAGE_DESTINATION, next);
        }