KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > PersistenceUnitsDescriptor


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;
26
27 import com.sun.enterprise.deployment.util.ModuleDescriptor;
28 import com.sun.enterprise.util.io.FileUtils;
29
30 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collections JavaDoc;
34
35 /**
36  * This descriptor represents contents for one persistence.xml file.
37  *
38  * @author Sanjeeb.Sahoo@Sun.COM
39  */

40 public class PersistenceUnitsDescriptor extends RootDeploymentDescriptor {
41
42     /** the parent descriptor that contains this descriptor */
43     private RootDeploymentDescriptor parent;
44
45     /**
46      * The relative path from the parent {@link RootDeploymentDescriptor}
47      * to the root of this persistence unit. e.g.
48      * WEB-INF/classes -- if persistence.xml is in WEB-INF/classes/META-INF,
49      * WEB-INF/lib/foo.jar -- if persistence.xml is in WEB-INF/lib/foo.jar/META-INF,
50      * "" -- if persistence.xml is in some ejb.jar, or
51      * util/bar.jar -- if persistence.xml is in a.ear/util/bar.jar
52      */

53     private String JavaDoc puRoot;
54
55     List JavaDoc<PersistenceUnitDescriptor> persistenceUnitDescriptors =
56             new ArrayList JavaDoc<PersistenceUnitDescriptor>();
57
58     private static final String JavaDoc JPA_1_0 = "1.0";
59
60     public PersistenceUnitsDescriptor() {
61     }
62
63     public RootDeploymentDescriptor getParent() {
64         return parent;
65     }
66
67     public void setParent(RootDeploymentDescriptor parent) {
68         this.parent = parent;
69     }
70
71     public String JavaDoc getPuRoot() {
72         return puRoot;
73     }
74
75     public void setPuRoot(String JavaDoc puRoot) {
76         this.puRoot = puRoot;
77     }
78
79     public String JavaDoc getDefaultSpecVersion() {
80         return JPA_1_0;
81     }
82
83     public String JavaDoc getModuleID() {
84         throw new RuntimeException JavaDoc();
85     }
86
87     public ModuleType JavaDoc getModuleType() {
88         throw new RuntimeException JavaDoc();
89     }
90
91     public ClassLoader JavaDoc getClassLoader() {
92         return parent.getClassLoader();
93     }
94
95     public boolean isApplication() {
96         return false;
97     }
98
99     /**
100      * This method does not do any validation like checking for unique names
101      * of PersistenceUnits.
102      * @param pud the PersistenceUnitDescriptor to be added.
103      */

104     public void addPersistenceUnitDescriptor(PersistenceUnitDescriptor pud){
105         persistenceUnitDescriptors.add(pud);
106         pud.setParent(this);
107     }
108
109     /**
110      * @return an unmodifiable list.
111      */

112     public List JavaDoc<PersistenceUnitDescriptor> getPersistenceUnitDescriptors() {
113         return Collections.unmodifiableList(persistenceUnitDescriptors);
114     }
115
116     /**
117      * This is a utility method which calculates the absolute path of the
118      * root of a PU. Absolute path is not the path with regards to
119      * root of file system. It is the path from the root of the Java EE
120      * application this persistence unit belongs to.
121      * Like {@link #getPuRoot()} returned path always uses '/' as path separator.
122      * @return the absolute path of the root of this persistence unit
123      * @see #getPuRoot()
124      */

125     public String JavaDoc getAbsolutePuRoot() {
126         RootDeploymentDescriptor rootDD = getParent();
127         if(rootDD.isApplication()){
128             return getPuRoot();
129         } else {
130             ModuleDescriptor module = BundleDescriptor.class.cast(rootDD).
131                     getModuleDescriptor();
132             if(module.isStandalone()) {
133                 return getPuRoot();
134             } else {
135                 final String JavaDoc moduleLocation = FileUtils.makeFriendlyFileName(
136                         module.getArchiveUri());
137                 return moduleLocation + '/' + getPuRoot(); // see we always '/'
138
}
139         }
140     }
141
142 }
143
Popular Tags