KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.deployment.node.runtime;
24
25 import java.util.Map JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28
29 import com.sun.enterprise.deployment.node.XMLElement;
30 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
31 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor;
32 import com.sun.enterprise.deployment.runtime.IASEjbCMPFinder;
33 import com.sun.enterprise.deployment.runtime.PrefetchDisabledDescriptor;
34 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
35 import com.sun.enterprise.deployment.PersistenceDescriptor;
36 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
37 import com.sun.enterprise.deployment.ResourcePrincipal;
38
39 /**
40  * This node handles the cmp runtime deployment descriptors
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public class CmpNode extends DeploymentDescriptorNode {
46
47     protected IASEjbCMPEntityDescriptor descriptor=null;
48     
49     /** Creates new CmpNode */
50     public CmpNode() {
51         registerElementHandler(new XMLElement(RuntimeTagNames.FINDER), FinderNode.class);
52         registerElementHandler(new XMLElement(RuntimeTagNames.PREFETCH_DISABLED), PrefetchDisabledNode.class);
53     }
54     
55    /**
56     * @return the descriptor instance to associate with this XMLNode
57     */

58     public Object JavaDoc getDescriptor() {
59         if (descriptor == null) {
60             Object JavaDoc desc = getParentNode().getDescriptor();
61             if (desc instanceof IASEjbCMPEntityDescriptor) {
62                 descriptor = (IASEjbCMPEntityDescriptor) desc;
63             }
64         }
65         return descriptor;
66     }
67     
68     /**
69      * all sub-implementation of this class can use a dispatch table to map xml element to
70      * method name on the descriptor class for setting the element value.
71      *
72      * @return the map with the element name as a key, the setter method as a value
73      */

74     protected Map JavaDoc getDispatchTable() {
75     Map JavaDoc dispatchTable = super.getDispatchTable();
76     dispatchTable.put(RuntimeTagNames.MAPPING_PROPERTIES, "setMappingProperties");
77         // deprecated element, will be ignored at reading
78
dispatchTable.put(RuntimeTagNames.IS_ONE_ONE_CMP, null);
79     return dispatchTable;
80     }
81     
82     /**
83      * Adds a new DOL descriptor instance to the descriptor instance associated with
84      * this XMLNode
85      *
86      * @param descriptor the new descriptor
87      */

88     public void addDescriptor(Object JavaDoc newDescriptor) {
89         getDescriptor();
90         if (newDescriptor instanceof IASEjbCMPFinder ) {
91             descriptor.addOneOneFinder((IASEjbCMPFinder ) newDescriptor);
92         }
93          else if (newDescriptor instanceof PrefetchDisabledDescriptor) {
94             descriptor.setPrefetchDisabledDescriptor((PrefetchDisabledDescriptor)newDescriptor);
95         } else super.addDescriptor(descriptor);
96     }
97
98     /**
99      * write the descriptor class to a DOM tree and return it
100      *
101      * @param parent node for the DOM tree
102      * @param node name for the descriptor
103      * @param the descriptor to write
104      * @return the DOM tree top node
105      */

106     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, IASEjbCMPEntityDescriptor ejbDescriptor) {
107     Node JavaDoc cmpNode = super.writeDescriptor(parent, nodeName, ejbDescriptor);
108     appendTextChild(cmpNode, RuntimeTagNames.MAPPING_PROPERTIES, ejbDescriptor.getMappingProperties());
109     Map JavaDoc finders = ejbDescriptor.getOneOneFinders();
110     if (!finders.isEmpty()) {
111         Node JavaDoc findersNode = appendChild(cmpNode, RuntimeTagNames.ONE_ONE_FINDERS);
112         FinderNode fn = new FinderNode();
113         for (Iterator JavaDoc finderIterator = finders.values().iterator();finderIterator.hasNext();) {
114         IASEjbCMPFinder aFinder = (IASEjbCMPFinder) finderIterator.next();
115         fn.writeDescriptor(findersNode, RuntimeTagNames.FINDER, aFinder);
116         }
117     }
118         
119         // prefetch-disabled
120
PrefetchDisabledDescriptor prefetchDisabledDesc =
121             ejbDescriptor.getPrefetchDisabledDescriptor();
122         if (prefetchDisabledDesc != null) {
123             PrefetchDisabledNode prefetchDisabledNode =
124                 new PrefetchDisabledNode();
125             prefetchDisabledNode.writeDescriptor(cmpNode,
126                 RuntimeTagNames.PREFETCH_DISABLED, prefetchDisabledDesc);
127         }
128
129     return cmpNode;
130     }
131 }
132
Popular Tags