KickJava   Java API By Example, From Geeks To Geeks.

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


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.Cache;
32 import com.sun.enterprise.deployment.runtime.web.CacheHelper;
33 import com.sun.enterprise.deployment.runtime.web.DefaultHelper;
34 import com.sun.enterprise.deployment.runtime.web.CacheMapping;
35 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
36 import com.sun.enterprise.deployment.node.XMLElement;
37
38 /**
39 * node for cache tag
40 *
41 * @author Jerome Dochez
42 */

43 public class CacheNode extends WebRuntimeNode {
44     
45     public CacheNode() {
46     
47     registerElementHandler(new XMLElement(RuntimeTagNames.CACHE_HELPER),
48                 CacheHelperNode.class, "addNewCacheHelper");
49     registerElementHandler(new XMLElement(RuntimeTagNames.DEFAULT_HELPER),
50                 WebPropertyNode.class, "setDefaultHelper");
51     registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
52                 WebPropertyNode.class, "addWebProperty");
53     registerElementHandler(new XMLElement(RuntimeTagNames.CACHE_MAPPING),
54                 CacheMappingNode.class, "addNewCacheMapping");
55     }
56     /**
57      * parsed an attribute of an element
58      *
59      * @param the element name
60      * @param the attribute name
61      * @param the attribute value
62      * @return true if the attribute was processed
63      */

64     protected boolean setAttributeValue(XMLElement elementName, XMLElement attributeName, String JavaDoc value) {
65     RuntimeDescriptor descriptor = (RuntimeDescriptor) getRuntimeDescriptor();
66     if (descriptor==null) {
67         throw new RuntimeException JavaDoc("Trying to set values on a null descriptor");
68     }
69     if (attributeName.getQName().equals(RuntimeTagNames.MAX_ENTRIES)) {
70         descriptor.setAttributeValue(Cache.MAX_ENTRIES, value);
71         return true;
72     } else
73     if (attributeName.getQName().equals(RuntimeTagNames.TIMEOUT_IN_SECONDS)) {
74         descriptor.setAttributeValue(Cache.TIMEOUT_IN_SECONDS, value);
75         return true;
76     } else
77     if (attributeName.getQName().equals(RuntimeTagNames.ENABLED)) {
78         descriptor.setAttributeValue(Cache.ENABLED, value);
79         return true;
80     } else
81     return false;
82     }
83     
84     /**
85      * write the descriptor class to a DOM tree and return it
86      *
87      * @param parent node for the DOM tree
88      * @param node name
89      * @param the descriptor to write
90      * @return the DOM tree top node
91      */

92     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, Cache descriptor) {
93
94     Element JavaDoc cache = (Element JavaDoc) super.writeDescriptor(parent, nodeName, descriptor);
95     
96     // cache-helpers*
97
CacheHelper[] cacheHelpers = descriptor.getCacheHelper();
98     if (cacheHelpers!=null && cacheHelpers.length>0) {
99         CacheHelperNode chn = new CacheHelperNode();
100         for (int i=0;i<cacheHelpers.length;i++) {
101         chn.writeDescriptor(cache, RuntimeTagNames.CACHE_HELPER, cacheHelpers [i]);
102         }
103     }
104     
105     WebPropertyNode wpn = new WebPropertyNode();
106     
107     // default-helper?
108
DefaultHelper dh = descriptor.getDefaultHelper();
109     if (dh!=null && dh.getWebProperty()!=null) {
110         Node JavaDoc dhn = appendChild(cache, RuntimeTagNames.DEFAULT_HELPER);
111         wpn.writeDescriptor(dhn, RuntimeTagNames.PROPERTY, dh.getWebProperty());
112     }
113     
114     // property*
115
wpn.writeDescriptor(cache, RuntimeTagNames.PROPERTY, descriptor.getWebProperty());
116     
117     // cache-mapping
118
CacheMapping[] mappings = descriptor.getCacheMapping();
119     if (mappings!=null && mappings.length>0) {
120         CacheMappingNode cmn = new CacheMappingNode();
121         for (int i=0;i<mappings.length;i++) {
122         cmn.writeDescriptor(cache, RuntimeTagNames.CACHE_MAPPING, mappings[i]);
123         }
124     }
125     
126     // max-entries, timeout-in-seconds, enabled
127
setAttribute(cache, RuntimeTagNames.MAX_ENTRIES, (String JavaDoc) descriptor.getAttributeValue(Cache.MAX_ENTRIES));
128     setAttribute(cache, RuntimeTagNames.TIMEOUT_IN_SECONDS, (String JavaDoc) descriptor.getAttributeValue(Cache.TIMEOUT_IN_SECONDS));
129     setAttribute(cache, RuntimeTagNames.ENABLED, (String JavaDoc) descriptor.getAttributeValue(Cache.ENABLED));
130     
131     return cache;
132     }
133 }
134
Popular Tags