KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > PersistenceNode


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
25 package com.sun.enterprise.deployment.node;
26
27 import com.sun.enterprise.deployment.xml.PersistenceTagNames;
28 import com.sun.enterprise.deployment.PersistenceUnitDescriptor;
29 import com.sun.enterprise.deployment.PersistenceUnitsDescriptor;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * Represents the top level node, i.e. persistence node in persistence.xsd.
36  * Since this is a top level node, it extends {@link BundleNode}. This class
37  * registers a handler {@link PersistenceNode} which is responsible for reading
38  * the persistence-unit elements.
39  *
40  * @author Sanjeeb.Sahoo@Sun.COM
41  */

42 public class PersistenceNode extends BundleNode {
43
44     public final static String JavaDoc SCHEMA_NS =
45             "http://java.sun.com/xml/ns/persistence"; // NOI18N
46

47     public final static String JavaDoc SCHEMA_ID = "persistence_1_0.xsd"; // NOI18N
48

49     private static List JavaDoc<String JavaDoc> systemIDs = null;
50
51     // The XML tag associated with this Node
52
public final static XMLElement ROOT_ELEMENT = new XMLElement(
53             PersistenceTagNames.PERSISTENCE);
54
55     private PersistenceUnitsDescriptor persistenceUnitsDescriptor;
56
57     private static final String JavaDoc SPEC_VERSION = "1.0";
58
59     /**
60      * This is the default constructor which is also called from other
61      * constructors of this class. Inside this constructor, we clear the
62      * handlers set up by super classes' constructors because they are
63      * not applicable in the context of PersistenceNode because
64      * unlike standard Java EE schemas, persistence.xsd does not include
65      * javaee_5.xsd for things like description, version etc.
66      */

67     public PersistenceNode() {
68         // clear all the handlers set up by super classes.
69
if (handlers != null) handlers.clear();
70         registerElementHandler(
71                 new XMLElement(PersistenceTagNames.PERSISTENCE_UNIT),
72                 PersistenceUnitNode.class);
73     }
74
75     public PersistenceNode(PersistenceUnitsDescriptor persistenceUnitsDescriptor) {
76         this();
77         this.persistenceUnitsDescriptor = persistenceUnitsDescriptor;
78     }
79
80     @Override JavaDoc
81     public PersistenceUnitsDescriptor getDescriptor() {
82         return persistenceUnitsDescriptor;
83     }
84
85     // This method is called when parser has parsed one <persistence-unit>
86
@Override JavaDoc
87     public void addDescriptor(Object JavaDoc descriptor) {
88         final PersistenceUnitDescriptor pud = PersistenceUnitDescriptor.class.cast(descriptor);
89         getDescriptor().addPersistenceUnitDescriptor(pud);
90     }
91
92     public String JavaDoc getDocType() {
93         return null;
94     }
95
96     public String JavaDoc getSystemID() {
97         return SCHEMA_ID;
98     }
99
100     public String JavaDoc getNameSpace() {
101         return SCHEMA_NS;
102     }
103
104     /**
105      * @return the XML tag associated with this XMLNode
106      */

107     protected XMLElement getXMLRootTag() {
108         return ROOT_ELEMENT;
109     }
110
111     public List JavaDoc<String JavaDoc> getSystemIDs() {
112         if (systemIDs != null) {
113             return systemIDs;
114         }
115         systemIDs = new ArrayList JavaDoc<String JavaDoc>();
116         systemIDs.add(SCHEMA_ID);
117         return systemIDs;
118     }
119
120     public String JavaDoc getSpecVersion() {
121         return SPEC_VERSION;
122     }
123
124     // Currently this method is commented because
125
// it is not needed now as we are not writing out
126
// persistence.xml file to generated directory. When we decide to
127
// write out a "full" persistence.xml file, we will need this method.
128
// When you uncomment, you need to check the actual logic as well.
129
// @Override public Node writeDescriptor(Node parent, Descriptor descriptor) {
130
// if(descriptor instanceof PersistenceUnitDescriptor) {
131
// Element child = getOwnerDocument(parent).createElementNS(TagNames.PERSISTENCE_XML_NAMESPACE, PersistenceTagNames.ENTITY_MANAGER);
132
// Element bundleNode = (Element)parent.appendChild(child);
133
// bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", TagNames.PERSISTENCE_XML_NAMESPACE);
134
// bundleNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", W3C_XML_SCHEMA_INSTANCE);
135
//
136
// String schemaLocation = TagNames.PERSISTENCE_XML_NAMESPACE + " " + getSchemaURL();
137
// String clientSchemaLocation = PersistenceUnitDescriptor.class.cast(descriptor).getSchemaLocation();
138
// if (clientSchemaLocation!=null) {
139
// schemaLocation = schemaLocation + " " + clientSchemaLocation;
140
// }
141
// bundleNode.setAttributeNS(W3C_XML_SCHEMA_INSTANCE, SCHEMA_LOCATION_TAG, schemaLocation);
142
// TODO: Code for all other elements for this node goes here.
143
// return bundleNode;
144
// } else {
145
// return super.writeDescriptor(parent, descriptor);
146
// }
147
// }
148
}
149
Popular Tags