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

ExtensionElementNode

public class ExtensionElementNode extends DeploymentDescriptorNode
This node is responsible for loading and saving any type of xml node and store them in a DeploymentExtensionElement
author
Jerome Dochez

Fields Summary
com.sun.enterprise.deployment.ExtensionElementDescriptor
descriptor
Constructors Summary
public ExtensionElementNode()
Creates a new instance of DynamicDescriptorNode

        descriptor = new ExtensionElementDescriptor();
    
Methods Summary
protected voidaddNodeDescriptor(DeploymentDescriptorNode node)
Adds a new DOL descriptor instance to the descriptor associated with this XMLNode

param
XMLNode the sub-node adding the descriptor;
param
descriptor the new descriptor

        // nodes are added upon creation
        ExtensionElementDescriptor dad = (ExtensionElementDescriptor) node.getDescriptor();
        Iterator itr = dad.getElementNames();
        // jump over first element;
        if (itr.hasNext()) itr.next();
        
        if (itr.hasNext() && !dad.hasAttributes()) {
            descriptor.addElement(node.getXMLRootTag().getCompleteName(), dad);
        } else {
            descriptor.addElement(node.getXMLRootTag().getCompleteName(), dad.getElement(node.getXMLRootTag().getCompleteName()));
        }
    
public org.w3c.dom.ElementappendChildNS(org.w3c.dom.Node parent, java.lang.String elementName, com.sun.enterprise.deployment.Descriptor descriptor)

Append a new element child to the current node

param
parentNode is the parent node for the new child element
param
elementName is new element tag name
return
the newly created child node

        if (elementName.indexOf(':")!=-1) {
            String prefix = elementName.substring(0, elementName.indexOf(':"));
            elementName = elementName.substring(elementName.indexOf(':")+1);
            
            String namespace = getNamespaceFor(descriptor, parent, prefix);
            
            Element child = getOwnerDocument(parent).createElementNS(namespace, elementName);            
            child.setPrefix(prefix);
            parent.appendChild(child);
            return child;
        }
        return super.appendChild(parent, elementName);
    
public org.w3c.dom.NodeappendTextChildNS(org.w3c.dom.Node parent, java.lang.String elementName, java.lang.String text, com.sun.enterprise.deployment.Descriptor descriptor)

Append a new text child

param
parent for the new child element
param
elementName is the new element tag name
param
text the text for the new element
result
the newly create child node

        
        if (text == null || text.length()==0) 
            return null;
        
        Node child = appendChildNS(parent, elementName, descriptor);
        child.appendChild(getOwnerDocument(child).createTextNode(text));        
        return child;
    
public booleanendElement(XMLElement element)
receives notification of the end of an XML element by the Parser

param
element the xml tag identification
return
true if this node is done processing the XML sub tree

        boolean allDone = element.getCompleteName().equals(getXMLRootTag().getCompleteName()) || element.getQName().equals(TagNames.EXTENSION_ELEMENT);        
        if (allDone) {
            postParsing();    
            ((DeploymentDescriptorNode) getParentNode()).addNodeDescriptor(this);            
        }
        return allDone;        
    
public java.lang.ObjectgetDescriptor()

return
the descriptor instance to associate with this XMLNode

    
        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

   
        return null;
    
public XMLNodegetHandlerFor(XMLElement element)

return
the handler registered for the subtag element of the curent XMLNode

        ExtensionElementNode subNode = new ExtensionElementNode();        
        subNode.setParentNode(this);
        subNode.setXMLRootTag(new XMLElement(element.getCompleteName()));
        return subNode;
    
private java.lang.StringgetNamespaceFor(com.sun.enterprise.deployment.Descriptor descriptor, org.w3c.dom.Node parent, java.lang.String prefix)
look in the mapping defined in this descriptor and in all parent nodes for the right namespace for the passed prefix

        
        Map prefixMapping = descriptor.getPrefixMapping();
        String namespace = null;
        if (prefixMapping!=null) {
            namespace = (String) prefixMapping.get(prefix);
        }
        if (namespace==null) {
            Element currentNode = (Element) parent;
            namespace="";
            while (currentNode!=null && namespace.length()==0) {
                namespace = currentNode.getAttributeNS("http://www.w3.org/2000/xmlns/", prefix);
                if (namespace.length()==0) 
                    currentNode = (Element) currentNode.getParentNode();
            }
        }
        return namespace;
    
public booleanhandlesElement(XMLElement element)

return
true if the element tag can be handled by any registered sub nodes of the current XMLNode

        // we are never handling xml fragment only leaf nodes, we create subnodes for that.
        return false;
    
public voidsetElementValue(XMLElement element, java.lang.String value)
receives notification of the value for a particular tag

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

        descriptor.addElement(element.getCompleteName(), value);
    
public voidstartElement(XMLElement element, org.xml.sax.Attributes attributes)
SAX Parser API implementation, we don't really care for now.

        if (attributes.getLength()>0) {
            for (int i=0;i<attributes.getLength();i++) {        
                if (attributes.getLocalName(i).equals("type")) {
                    // type declaration... replace the standard xml declaration with ours...
                    descriptor.getAttributes().addExtraAttribute("xsi:type", attributes.getValue(i));
                } else {
                    descriptor.getAttributes().addExtraAttribute(attributes.getQName(i), attributes.getValue(i));                
                }
            }
        }
    
protected voidwriteDescriptor(org.w3c.dom.Node parentNode, java.lang.String tagName, com.sun.enterprise.deployment.ExtensionElementDescriptor descriptor)
write the deployment extensions nodes associated with this node

param
parent node for the DOM tree
param
deployment extension element

        Element node = appendChildNS(parentNode, tagName, descriptor);
        if (descriptor.hasAttributes()) {
            Map attributes = descriptor.getAttributes().getExtraAttributes();
            for (Iterator itr = attributes.keySet().iterator();itr.hasNext();) {
                String key = (String) itr.next();
                String value = (String) attributes.get(key);
                String namespace = "";
                if (key.indexOf(':")!=-1) {
                    String prefix = key.substring(0, key.indexOf(':"));
                    namespace = getNamespaceFor(descriptor, parentNode, prefix);
                }                
                node.setAttributeNS(namespace, key, value);
            }
        }
        addNamespaceDeclaration(node, descriptor);
        for (Iterator itr = descriptor.getElementNames();itr.hasNext();) {
            String elementName = (String) itr.next();
            Object value = descriptor.getElement(elementName);
            if (value instanceof ExtensionElementDescriptor) {
                writeDescriptor(node, elementName, (ExtensionElementDescriptor) value);
            } else 
            if (value instanceof String) {
                appendTextChildNS(node, elementName, (String) value, descriptor);
            }
        }