FileDocCategorySizeDatePackage
ApplicationRuntimeNode.javaAPI DocGlassfish v2 API10740Fri May 04 22:31:46 BST 2007com.sun.enterprise.deployment.node.runtime.application

ApplicationRuntimeNode

public class ApplicationRuntimeNode extends com.sun.enterprise.deployment.node.runtime.RuntimeBundleNode
This node handles all runtime-information pertinent to applications The reading needs to be backward compatible with J2EE 1.2 and 1.3 where all runtime information was saved at the .ear file level in an unique sun-ri.xml file. In J2EE 1.4, each sub archivist is responsible for saving its runtime-info at his level.
author
Jerome Dochez
version

Fields Summary
private com.sun.enterprise.deployment.Application
descriptor
private String
currentWebUri
Constructors Summary
public ApplicationRuntimeNode(com.sun.enterprise.deployment.Application descriptor)

    
       
        super(descriptor);
	this.descriptor=descriptor;	
    
Methods Summary
protected voidInit()
Initialize the child handlers

     
        super.Init();                          
        registerElementHandler(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING), 
                               SecurityRoleMappingNode.class);              
    
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 SecurityRoleMapping) {
            SecurityRoleMapping roleMap = (SecurityRoleMapping) newDescriptor;
            descriptor.addSecurityRoleMapping(roleMap);
            if (descriptor!=null && !descriptor.isVirtual()) {
                Role role = new Role(roleMap.getRoleName());
                SecurityRoleMapper rm = descriptor.getRoleMapper();
                if (rm != null) {
                    List<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames();
                    for (int i = 0; i < principals.size(); i++) {
                        rm.assignRole(principals.get(i).getPrincipal(),
                            role, descriptor);
                    }
                    List<String> groups = roleMap.getGroupNames();
                    for (int i = 0; i < groups.size(); i++) {
                        rm.assignRole(new Group(groups.get(i)),
                            role, 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

    
        Map table = super.getDispatchTable();
        table.put(RuntimeTagNames.REALM, "setRealm");
        return table;
    
public java.lang.StringgetDocType()

return
the DOCTYPE that should be written to the XML file

	return DTDRegistry.SUN_APPLICATION_500_DTD_PUBLIC_ID;
    
public java.lang.StringgetSystemID()

return
the SystemID of the XML file

	return DTDRegistry.SUN_APPLICATION_500_DTD_SYSTEM_ID;
    
public java.util.ListgetSystemIDs()

return
NULL for all runtime nodes.

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

return
the XML tag associated with this XMLNode

        return new XMLElement(RuntimeTagNames.S1AS_APPLICATION_RUNTIME_TAG);
    
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(DTDRegistry.SUN_APPLICATION_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_130_DTD_SYSTEM_ID);
       publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140_DTD_SYSTEM_ID);       
       publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_141_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_141_DTD_SYSTEM_ID);       
       publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_500_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_500_DTD_SYSTEM_ID);       
       if (!restrictDTDDeclarations()) {
           publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_140beta_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140beta_DTD_SYSTEM_ID);       
       }
       return RuntimeTagNames.S1AS_APPLICATION_RUNTIME_TAG;
   
public voidsetElementValue(com.sun.enterprise.deployment.node.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

	if (element.getQName().equals(RuntimeTagNames.PASS_BY_REFERENCE)) {
	    descriptor.setPassByReference("true".equalsIgnoreCase(value));
	} else 
	if (element.getQName().equals(RuntimeTagNames.UNIQUE_ID)) {
	    descriptor.setUniqueId(Long.parseLong(value));
	} else
	if (element.getQName().equals(RuntimeTagNames.WEB_URI)) {
	    currentWebUri=value;
	} else 
	if (element.getQName().equals(RuntimeTagNames.CONTEXT_ROOT)) {
	    if (currentWebUri!=null) {
		ModuleDescriptor md = descriptor.getModuleDescriptorByUri(currentWebUri);
                if (md==null) {
                    throw new RuntimeException("No bundle in application with uri " + currentWebUri);
                }
		currentWebUri=null;
		if (md.getModuleType().equals(ModuleType.WAR)) {
		    md.setContextRoot(value);
		} else {
		    throw new RuntimeException(currentWebUri + " uri does not point to a web bundle");
		} 
	    } else {
		throw new RuntimeException("No uri provided for this context-root " + value);
	    }
	} else super.setElementValue(element, value);
    
public org.w3c.dom.NodewriteDescriptor(org.w3c.dom.Node parent, java.lang.String nodeName, 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 Application)) {
            throw new IllegalArgumentException(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
        }
        Application application = (Application) descriptor;
        Node appNode = super.writeDescriptor(parent, nodeName, descriptor);
	
        // web*
	for (Iterator modules=application.getModules();modules.hasNext();) {
	    ModuleDescriptor module = (ModuleDescriptor) modules.next();
	    if (module.getModuleType().equals(ModuleType.WAR)) {
		Node web = appendChild(appNode, RuntimeTagNames.WEB);
		appendTextChild(web, RuntimeTagNames.WEB_URI, module.getArchiveUri());
		appendTextChild(web, RuntimeTagNames.CONTEXT_ROOT, module.getContextRoot());
	    }
	}
	
	// pass-by-reference ?
	if (application.isPassByReferenceDefined()) {
	    appendTextChild(appNode, RuntimeTagNames.PASS_BY_REFERENCE, String.valueOf(application.getPassByReference()));
	}
	
	// unique-id
	appendTextChild(appNode, RuntimeTagNames.UNIQUE_ID, String.valueOf(application.getUniqueId()));
	
        // security-role-mapping*
        List<SecurityRoleMapping> roleMappings = application.getSecurityRoleMappings();
        for (int i = 0; i < roleMappings.size(); i++) { 
            SecurityRoleMappingNode srmn = new SecurityRoleMappingNode();
            srmn.writeDescriptor(appNode, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMappings.get(i));
        }
        
        // realm?
        appendTextChild(appNode, RuntimeTagNames.REALM, application.getRealm());
        
        return appNode;