FileDocCategorySizeDatePackage
CacheMappingNode.javaAPI DocGlassfish v2 API9009Fri May 04 22:31:48 BST 2007com.sun.enterprise.deployment.node.runtime.web

CacheMappingNode

public class CacheMappingNode extends WebRuntimeNode
node for cache-mapping tag
author
Jerome Dochez

Fields Summary
Constructors Summary
public CacheMappingNode()

	
        registerElementHandler(new XMLElement(RuntimeTagNames.CONSTRAINT_FIELD), 
                               ConstraintFieldNode.class, "addNewConstraintField"); 			       
    
Methods Summary
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(RuntimeTagNames.SERVLET_NAME, "setServletName");
	dispatchTable.put(RuntimeTagNames.URL_PATTERN, "setUrlPattern");
	dispatchTable.put(RuntimeTagNames.CACHE_HELPER_REF, "setCacheHelperRef");	
	dispatchTable.put(RuntimeTagNames.TIMEOUT, "setTimeout");
	dispatchTable.put(RuntimeTagNames.HTTP_METHOD, "addNewHttpMethod");	
	dispatchTable.put(RuntimeTagNames.DISPATCHER, "addNewDispatcher");	
	return dispatchTable;
    
public voidstartElement(com.sun.enterprise.deployment.node.XMLElement element, org.xml.sax.Attributes attributes)

        CacheMapping descriptor = (CacheMapping) getRuntimeDescriptor();
	if (descriptor==null) {
	    throw new RuntimeException("Trying to set values on a null descriptor");
	} 	
	if (element.getQName().equals(RuntimeTagNames.TIMEOUT)) {
            for (int i=0; i<attributes.getLength();i++) {
                if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) {
		    descriptor.setAttributeValue(CacheMapping.TIMEOUT, CacheMapping.NAME, attributes.getValue(i));
                } else 
                if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) {
                    int index=0;
                    while (descriptor.getAttributeValue(CacheMapping.TIMEOUT, index, CacheMapping.NAME)!=null) {
                        index++;
                    }
		    descriptor.setAttributeValue(CacheMapping.TIMEOUT, index-1, CacheMapping.SCOPE, attributes.getValue(i));
	        }  
            }
 	} else 
	if (element.getQName().equals(RuntimeTagNames.REFRESH_FIELD)) {
	    descriptor.setRefreshField(true);
            for (int i=0; i<attributes.getLength();i++) {
	        if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) {
		    descriptor.setAttributeValue(CacheMapping.REFRESH_FIELD, 0, CacheMapping.NAME, attributes.getValue(i));
	        } else
	        if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) { 
                    descriptor.setAttributeValue(CacheMapping.REFRESH_FIELD, 0, CacheMapping.SCOPE, attributes.getValue(i));
                }
	    }  
	} else
	if (element.getQName().equals(RuntimeTagNames.KEY_FIELD)) {
	    descriptor.addKeyField(true);
            for (int i=0; i<attributes.getLength();i++) {
                if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) {
		    descriptor.setAttributeValue(CacheMapping.KEY_FIELD, CacheMapping.NAME, attributes.getValue(i));
	        } else
                if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) {
                    int index = descriptor.sizeKeyField();               
	            descriptor.setAttributeValue(CacheMapping.KEY_FIELD, index-1, CacheMapping.SCOPE, attributes.getValue(i));
	        } 
            }
	} else super.startElement(element, attributes);
    
public org.w3c.dom.NodewriteDescriptor(org.w3c.dom.Node parent, java.lang.String nodeName, com.sun.enterprise.deployment.runtime.web.CacheMapping descriptor)
write the descriptor class to a DOM tree and return it

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

 
	Node cacheMapping = super.writeDescriptor(parent, nodeName, descriptor);
	if (descriptor.getServletName()!=null) {
	    appendTextChild(cacheMapping, RuntimeTagNames.SERVLET_NAME, descriptor.getServletName());
	} else {
	    appendTextChild(cacheMapping, RuntimeTagNames.URL_PATTERN, descriptor.getUrlPattern());
	}
	
	// cache-helper-ref 
	appendTextChild(cacheMapping, RuntimeTagNames.CACHE_HELPER_REF, 
			(String) descriptor.getValue(CacheMapping.CACHE_HELPER_REF));
	
	//dispatcher* 
	String[] dispatchers = descriptor.getDispatcher();
	if (dispatchers!=null) {
	    for (int i=0;i<dispatchers.length;i++) {
		appendTextChild(cacheMapping, RuntimeTagNames.DISPATCHER, dispatchers[i]);
	    }
	}

	// timeout?
	Element timeout = (Element) forceAppendTextChild(cacheMapping, RuntimeTagNames.TIMEOUT, 
			(String) descriptor.getValue(CacheMapping.TIMEOUT));
        // timeout attributes
        String name = descriptor.getAttributeValue(CacheMapping.TIMEOUT, CacheMapping.NAME);
        if (name!=null) {
            setAttribute(timeout, RuntimeTagNames.NAME, name);
        }
        String scope = descriptor.getAttributeValue(CacheMapping.TIMEOUT, CacheMapping.SCOPE);
        if (scope!=null) {
            setAttribute(timeout, RuntimeTagNames.SCOPE, scope);
        }
	
        //refresh-field?, 
	if (descriptor.isRefreshField()) {
	    Element refreshField = (Element) appendChild(cacheMapping, RuntimeTagNames.REFRESH_FIELD);
	    setAttribute(refreshField, RuntimeTagNames.NAME, 
			(String) descriptor.getAttributeValue(CacheMapping.REFRESH_FIELD, CacheMapping.NAME));
	    setAttribute(refreshField, RuntimeTagNames.SCOPE, 
			(String) descriptor.getAttributeValue(CacheMapping.REFRESH_FIELD, CacheMapping.SCOPE));
	}
	
	//http-method* 
	String[] httpMethods = descriptor.getHttpMethod();
	if (httpMethods!=null) {
	    for (int i=0;i<httpMethods.length;i++) {
		appendTextChild(cacheMapping, RuntimeTagNames.HTTP_METHOD, httpMethods[i]);
	    }
	}
	
	//key-field*
	if (descriptor.sizeKeyField()>0) {
	    for (int i=0;i<descriptor.sizeKeyField();i++) {
		
		if (descriptor.isKeyField(i)) {
		    Element keyField = (Element) appendChild(cacheMapping, RuntimeTagNames.KEY_FIELD);
		    setAttribute(keyField, RuntimeTagNames.NAME, 
			(String) descriptor.getAttributeValue(CacheMapping.KEY_FIELD, i, CacheMapping.NAME));
		    setAttribute(keyField, RuntimeTagNames.SCOPE, 
			(String) descriptor.getAttributeValue(CacheMapping.KEY_FIELD, i, CacheMapping.SCOPE));
		}
	    }
	}
	
	//constraint-field*
	if (descriptor.sizeConstraintField()>0) {
            ConstraintField[] constraintFields = descriptor.getConstraintField();
            ConstraintFieldNode cfn = new ConstraintFieldNode();
	    cfn.writeDescriptor(cacheMapping, RuntimeTagNames.CONSTRAINT_FIELD, constraintFields);
	}
	
	return cacheMapping;