KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > CmpResourceNode


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;
25
26 import java.util.Map JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Properties JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31
32 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
33 import com.sun.enterprise.deployment.NameValuePairDescriptor;
34 import com.sun.enterprise.deployment.EjbBundleDescriptor;
35 import com.sun.enterprise.deployment.node.XMLElement;
36 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
37 import com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode;
38 import com.sun.enterprise.deployment.node.PropertiesNode;
39 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
40 import com.sun.enterprise.deployment.util.DOLUtils;
41
42 /**
43  * This node handles the cmp-resource runtime xml tag
44  *
45  * @author Jerome Dochez
46  * @version
47  */

48 public class CmpResourceNode extends RuntimeDescriptorNode {
49
50     ResourceReferenceDescriptor descriptor= new ResourceReferenceDescriptor();
51     
52     /** Creates new CmpResourceNode */
53     public CmpResourceNode() {
54         registerElementHandler(new XMLElement(RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL),
55                                DefaultResourcePrincipalNode.class, "setResourcePrincipal");
56     registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
57                 RuntimeNameValuePairNode.class, "addProperty");
58         registerElementHandler(new XMLElement(RuntimeTagNames.SCHEMA_GENERATOR_PROPERTIES),
59                                 PropertiesNode.class, "setSchemaGeneratorProperties");
60     }
61     
62    /**
63     * @return the descriptor instance to associate with this XMLNode
64     */

65     public Object JavaDoc getDescriptor() {
66         return descriptor;
67     }
68
69     /**
70      * all sub-implementation of this class can use a dispatch table to map xml element to
71      * method name on the descriptor class for setting the element value.
72      *
73      * @return the map with the element name as a key, the setter method as a value
74      */

75     protected Map JavaDoc getDispatchTable() {
76         Map JavaDoc table = super.getDispatchTable();
77         table.put(RuntimeTagNames.JNDI_NAME, "setJndiName");
78         table.put(RuntimeTagNames.CREATE_TABLES_AT_DEPLOY, "setCreateTablesAtDeploy");
79         table.put(RuntimeTagNames.DROP_TABLES_AT_UNDEPLOY, "setDropTablesAtUndeploy");
80         table.put(RuntimeTagNames.DATABASE_VENDOR_NAME, "setDatabaseVendorName");
81         return table;
82     }
83     
84     /**
85      * notification of the end of XML parsing for this node
86      */

87     public void postParsing() {
88         EjbBundleDescriptor bd = (EjbBundleDescriptor) getParentNode().getDescriptor();
89         if (bd==null) {
90             DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
91                     new Object JavaDoc[]{descriptor});
92             return;
93         }
94         bd.setCMPResourceReference(descriptor);
95     }
96     
97     /**
98      * write the descriptor class to a DOM tree and return it
99      *
100      * @param parent node for the DOM tree
101      * @param the descriptor to write
102      * @return the DOM tree top node
103      */

104     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
105                                 ResourceReferenceDescriptor descriptor) {
106         Node JavaDoc cmp = super.writeDescriptor(parent, nodeName, descriptor);
107         appendTextChild(cmp, RuntimeTagNames.JNDI_NAME, descriptor.getJndiName());
108         if (descriptor.getResourcePrincipal() != null) {
109             DefaultResourcePrincipalNode drpNode = new DefaultResourcePrincipalNode();
110             drpNode.writeDescriptor(cmp, RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL,
111                 descriptor.getResourcePrincipal());
112         }
113         // properties*
114
Iterator JavaDoc properties = descriptor.getProperties();
115     if (properties!=null) {
116         RuntimeNameValuePairNode propNode = new RuntimeNameValuePairNode();
117         while (properties.hasNext()) {
118         NameValuePairDescriptor aProp = (NameValuePairDescriptor) properties.next();
119         propNode.writeDescriptor(cmp, RuntimeTagNames.PROPERTY, aProp);
120         }
121     }
122         
123         // createTableAtDeploy, dropTableAtUndeploy
124
if (descriptor.isCreateTablesAtDeploy()) {
125             appendTextChild(cmp, RuntimeTagNames.CREATE_TABLES_AT_DEPLOY, RuntimeTagNames.TRUE);
126         }
127         if (descriptor.isDropTablesAtUndeploy()) {
128             appendTextChild(cmp, RuntimeTagNames.DROP_TABLES_AT_UNDEPLOY, RuntimeTagNames.TRUE);
129         }
130         // database vendor name
131
appendTextChild(cmp, RuntimeTagNames.DATABASE_VENDOR_NAME, descriptor.getDatabaseVendorName());
132         
133         // schema-generator-properties?
134
Properties JavaDoc schemaGeneratorProps = descriptor.getSchemaGeneratorProperties();
135         if (schemaGeneratorProps!=null) {
136             PropertiesNode pn = new PropertiesNode();
137             pn.writeDescriptor(cmp, RuntimeTagNames.SCHEMA_GENERATOR_PROPERTIES, schemaGeneratorProps);
138         }
139         
140         return cmp;
141     }
142 }
143
Popular Tags