KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > web > CacheHelperNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.node.runtime.web;
25
26 import java.util.Map JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29
30 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor;
31 import com.sun.enterprise.deployment.runtime.web.CacheHelper;
32 import com.sun.enterprise.deployment.runtime.web.WebProperty;
33 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
34 import com.sun.enterprise.deployment.node.XMLElement;
35
36 /**
37 * node for cache-helper tag
38 *
39 * @author Jerome Dochez
40 */

41 public class CacheHelperNode extends WebRuntimeNode {
42     
43     public CacheHelperNode() {
44     
45         registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
46                                WebPropertyNode.class, "addWebProperty");
47     }
48
49     /**
50      * parsed an attribute of an element
51      *
52      * @param the element name
53      * @param the attribute name
54      * @param the attribute value
55      * @return true if the attribute was processed
56      */

57     protected boolean setAttributeValue(XMLElement elementName, XMLElement attributeName, String JavaDoc value) {
58     RuntimeDescriptor descriptor = (RuntimeDescriptor) getRuntimeDescriptor();
59     if (descriptor==null) {
60         throw new RuntimeException JavaDoc("Trying to set values on a null descriptor");
61     }
62     if (attributeName.getQName().equals(RuntimeTagNames.NAME)) {
63         descriptor.setAttributeValue(CacheHelper.NAME, value);
64         return true;
65     } else
66     if (attributeName.getQName().equals(RuntimeTagNames.CLASS_NAME)) {
67         descriptor.setAttributeValue(CacheHelper.CLASS_NAME, value);
68         return true;
69     }
70     return false;
71     }
72     
73     /**
74      * write the descriptor class to a DOM tree and return it
75      *
76      * @param parent node for the DOM tree
77      * @param node name
78      * @param the descriptor to write
79      * @return the DOM tree top node
80      */

81     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, CacheHelper descriptor) {
82
83     Element JavaDoc cacheHelper = (Element JavaDoc) super.writeDescriptor(parent, nodeName, descriptor);
84     
85     // property*
86
WebProperty[] properties = descriptor.getWebProperty();
87     if (properties.length>0) {
88         WebPropertyNode wpn = new WebPropertyNode();
89         wpn.writeDescriptor(cacheHelper, RuntimeTagNames.PROPERTY, properties);
90     }
91     
92     // name, class-name attribute
93
setAttribute(cacheHelper, RuntimeTagNames.NAME, (String JavaDoc) descriptor.getAttributeValue(CacheHelper.NAME));
94     setAttribute(cacheHelper, RuntimeTagNames.CLASS_NAME, (String JavaDoc) descriptor.getAttributeValue(CacheHelper.CLASS_NAME));
95     
96     return cacheHelper;
97     }
98 }
99
Popular Tags