KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 import java.util.Map JavaDoc;
31 import java.util.HashMap JavaDoc;
32
33 import org.xml.sax.Attributes JavaDoc;
34
35 /**
36  * This node is responsible for reading details about one <persistence-unit/>
37  * @author Sanjeeb.Sahoo@Sun.COM
38  */

39 public class PersistenceUnitNode extends DeploymentDescriptorNode {
40
41     /**
42      * map of element names to method names in {@link PersistenceUnitDescriptor}
43      */

44     private Map JavaDoc<String JavaDoc, String JavaDoc> dispatchTable;
45
46     /**
47      * This is the default constructor which is also called from other
48      * constructors of this class. Inside this constructor, we clear the
49      * handlers set up by super classes' constructors because they are
50      * not applicable in the context of PersistenceNode because
51      * unlike standard Java EE schemas, persistence.xsd does not include
52      * javaee_5.xsd for things like description, version etc.
53      */

54     public PersistenceUnitNode() {
55         // clear all the handlers set up by super classes
56
// because that sets up a handler for description which we are not
57
// interested in.
58
if (handlers != null) handlers.clear();
59         initDispatchTable();
60     }
61
62     @Override JavaDoc public void startElement(
63             XMLElement element, Attributes JavaDoc attributes) {
64         if (PersistenceTagNames.PROPERTY.equals(element.getQName())) {
65             assert(attributes.getLength() == 2);
66             assert(attributes.getIndex(PersistenceTagNames.PROPERTY_NAME) !=
67                     -1);
68             assert(attributes.getIndex(PersistenceTagNames.PROPERTY_VALUE) !=
69                     -1);
70             PersistenceUnitDescriptor persistenceUnitDescriptor = (PersistenceUnitDescriptor) getDescriptor();
71             String JavaDoc propName = attributes.getValue(
72                     PersistenceTagNames.PROPERTY_NAME);
73             String JavaDoc propValue = attributes.getValue(
74                     PersistenceTagNames.PROPERTY_VALUE);
75             persistenceUnitDescriptor.addProperty(propName, propValue);
76             return;
77         }
78         super.startElement(element, attributes);
79     }
80
81     /**
82      * This returns the dispatch table for this node.
83      * Please note, unlike Java EE schemas persistence.xsd does not include
84      * standard elements or attributes (e.g. version, descriptionGroupRef etc.)
85      * from javaee_5.xsd, we don't use super classes' dispatch table.
86      * @return map of element names to method names in PersistenceUnitDescriptor
87      * @see super#getDispatchTable()
88      * @see #initDispatchTable()
89      */

90     protected Map JavaDoc getDispatchTable() {
91         return dispatchTable;
92     }
93
94     /**
95      * Please note, unlike Java EE schemas persistence.xsd does not include
96      * standard elements or attributes (e.g. version, descriptionGroupRef etc.)
97      * from javaee_5.xsd, we don't use super classes' dispatch table.
98      */

99     private void initDispatchTable() {
100         assert(dispatchTable == null);
101
102         // we don't do super.getDispatchTable() because we are not
103
// interested in any of super classes' disptcah table entries.
104
Map JavaDoc<String JavaDoc, String JavaDoc> table = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
105
106         // the values being put into the map represent method names
107
// in PersistenceUnitDescriptor class.
108
table.put(PersistenceTagNames.NAME, "setName");
109         table.put(PersistenceTagNames.TRANSACTION_TYPE, "setTransactionType");
110         table.put(PersistenceTagNames.DESCRIPTION, "setDescription");
111         table.put(PersistenceTagNames.PROVIDER, "setProvider");
112         table.put(PersistenceTagNames.JTA_DATA_SOURCE, "setJtaDataSource");
113         table.put(PersistenceTagNames.NON_JTA_DATA_SOURCE,
114                 "setNonJtaDataSource");
115         table.put(PersistenceTagNames.MAPPING_FILE, "addMappingFile");
116         table.put(PersistenceTagNames.JAR_FILE, "addJarFile");
117         table.put(PersistenceTagNames.EXCLUDE_UNLISTED_CLASSES, "setExcludeUnlistedClasses");
118         table.put(PersistenceTagNames.CLASS, "addClass");
119         this.dispatchTable = table;
120     }
121
122 }
123
Popular Tags