KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > connector > AdminObjectNode


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.connector;
25
26 import java.util.*;
27 import org.xml.sax.Attributes JavaDoc;
28 import com.sun.enterprise.deployment.Descriptor;
29 import com.sun.enterprise.deployment.ConnectorDescriptor;
30 import com.sun.enterprise.deployment.AdminObject;
31 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
32 import com.sun.enterprise.deployment.xml.TagNames;
33 import com.sun.enterprise.deployment.EnvironmentProperty;
34 import com.sun.enterprise.deployment.node.DescriptorFactory;
35 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
36 import com.sun.enterprise.deployment.node.ConfigurableNode;
37 import com.sun.enterprise.deployment.node.XMLElement;
38
39 import org.xml.sax.Attributes JavaDoc;
40 import org.w3c.dom.Node JavaDoc;
41
42 /**
43  * This node is responsible for handling the Connector DTD related auth-mechanism XML tag
44  *
45  * @author Sheetal Vartak
46  * @version
47  */

48 public class AdminObjectNode extends DeploymentDescriptorNode {
49     
50     private AdminObject adminObject = null;
51     
52     public AdminObjectNode() {
53     register();
54     }
55
56     /**
57      * method for registering the handlers with the various tags
58      */

59     private void register() {
60     registerElementHandler(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY),
61                    ConfigPropertyNode.class);
62     }
63
64     /**
65      * all sub-implementation of this class can use a dispatch table to map xml element to
66      * method name on the descriptor class for setting the element value.
67      *
68      * @return the map with the element name as a key, the setter method as a value
69      */

70
71     protected Map getDispatchTable() {
72         Map table = super.getDispatchTable();
73         table.put(ConnectorTagNames.ADMIN_OBJECT_INTERFACE, "setAdminObjectInterface");
74         table.put(ConnectorTagNames.ADMIN_OBJECT_CLASS, "setAdminObjectClass");
75         return table;
76     }
77
78     /**
79      * Adds a new DOL descriptor instance to the descriptor instance associated with
80      * this XMLNode
81      *
82      * @param descriptor the new descriptor
83      */

84     public void addDescriptor(Object JavaDoc obj) {
85     if (obj instanceof EnvironmentProperty) {
86         adminObject.addConfigProperty((EnvironmentProperty)obj);
87     }
88     }
89
90     /**
91     * @return the descriptor instance to associate with this XMLNode
92     */

93     public Object JavaDoc getDescriptor() {
94         if (adminObject == null) {
95             adminObject = (AdminObject) DescriptorFactory.getDescriptor(getXMLPath());
96         }
97         return adminObject;
98     }
99
100     /**
101      * write the descriptor class to a DOM tree and return it
102      *
103      * @param parent node for the DOM tree
104      * @param the descriptor to write
105      * @return the DOM tree top node
106      */

107     public Node writeDescriptor(Node parent, Descriptor descriptor) {
108
109         if (! (descriptor instanceof ConnectorDescriptor)) {
110             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
111         }
112
113     //adminObject info
114
for (Iterator adminObjects = ((ConnectorDescriptor)descriptor).getAdminObjects().iterator(); adminObjects.hasNext();) {
115         AdminObject adminObject = (AdminObject) adminObjects.next();
116         Node adminObjectNode = appendChild(parent, ConnectorTagNames.ADMIN_OBJECT);
117         appendTextChild(adminObjectNode, ConnectorTagNames.ADMIN_OBJECT_INTERFACE, adminObject.getAdminObjectInterface());
118         appendTextChild(adminObjectNode, ConnectorTagNames.ADMIN_OBJECT_CLASS, adminObject.getAdminObjectClass());
119
120         ConfigPropertyNode config = new ConfigPropertyNode();
121         adminObjectNode = config.writeDescriptor(adminObjectNode, adminObject);
122     }
123
124     return parent;
125     }
126 }
127
Popular Tags