KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > persistence > PersistenceUnitCheckMgrImpl


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.tools.verifier.persistence;
26
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
29 import com.sun.enterprise.deployment.Descriptor;
30 import com.sun.enterprise.deployment.PersistenceUnitDescriptor;
31 import com.sun.enterprise.deployment.BundleDescriptor;
32 import com.sun.enterprise.deployment.RootDeploymentDescriptor;
33 import com.sun.enterprise.deployment.util.ModuleDescriptor;
34 import com.sun.enterprise.util.io.FileUtils;
35 import com.sun.enterprise.util.LocalStringManagerImpl;
36
37 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
38 import java.io.File JavaDoc;
39
40 /**
41  * This class is responsible for checking a PU represented by a {@link
42  * PersistenceUnitDescriptor}
43  *
44  * @author Sanjeeb.Sahoo@Sun.COM
45  */

46 public class PersistenceUnitCheckMgrImpl extends CheckMgr {
47
48     // module for which this check mgr is running the test.
49
// This string is one of the types defined in Result class.
50
private String JavaDoc moduleName;
51     private LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
52     
53
54     public PersistenceUnitCheckMgrImpl(
55             FrameworkContext frameworkContext, Context context) {
56         this.frameworkContext = frameworkContext;
57         this.context = context;
58     }
59
60     @Override JavaDoc protected void check(Descriptor descriptor) throws Exception JavaDoc {
61         PersistenceUnitDescriptor pu =
62                 PersistenceUnitDescriptor.class.cast(descriptor);
63         RootDeploymentDescriptor rootDD = pu.getParent().getParent();
64         if(rootDD.isApplication()) {
65             moduleName = Result.APP;
66         } else {
67             ModuleDescriptor mdesc =
68                     BundleDescriptor.class.cast(rootDD).getModuleDescriptor();
69             final ModuleType JavaDoc moduleType = mdesc.getModuleType();
70             if(moduleType == ModuleType.EJB) {
71                 moduleName = Result.EJB;
72             } else if (moduleType == ModuleType.WAR) {
73                 moduleName = Result.WEB;
74             } else if (moduleType == ModuleType.CAR) {
75                 moduleName = Result.APPCLIENT;
76             } else {
77                 throw new RuntimeException JavaDoc(
78                         smh.getLocalString(getClass().getName()+".exception", // NOI18N
79
"Unknown module type : {0}", // NOI18N
80
new Object JavaDoc[] {moduleType}));
81             }
82         }
83         super.check(descriptor);
84     }
85
86     /**
87      * We override here because there is nothing like sun-persistence.xml.
88      * @param uri
89      */

90     @Override JavaDoc protected void setRuntimeDDPresent(String JavaDoc uri) {
91         isDDPresent = false;
92     }
93
94     protected ComponentNameConstructor getComponentNameConstructor(
95             Descriptor descriptor) {
96         return new ComponentNameConstructor(
97                 PersistenceUnitDescriptor.class.cast(descriptor));
98     }
99
100     protected String JavaDoc getTestsListFileName() {
101         return "TestNamesPersistence.xml"; // NOI18N
102
}
103
104     protected void setModuleName(Result r) {
105         r.setModuleName(moduleName);
106     }
107
108     protected String JavaDoc getSchemaVersion(Descriptor descriptor) {
109         // A PU inherits its schema version from its parent.
110
return PersistenceUnitDescriptor.class.cast(descriptor).getParent().
111                 getSpecVersion();
112     }
113
114     protected String JavaDoc getSunONETestsListFileName() {
115         return null;
116     }
117
118     /**
119      * This method returns the path to the module.
120      * @param descriptor is a PersistenceUnitDescriptor
121      * @return the path to the module
122      */

123     protected String JavaDoc getAbstractArchiveUri(Descriptor descriptor) {
124         String JavaDoc archBase = context.getAbstractArchive().getArchiveUri();
125         RootDeploymentDescriptor rootDD =
126                 PersistenceUnitDescriptor.class.cast(descriptor).getParent().getParent();
127         if(rootDD.isApplication()) {
128             return archBase;
129         } else {
130             ModuleDescriptor mdesc =
131                     BundleDescriptor.class.cast(rootDD).getModuleDescriptor();
132             if(mdesc.isStandalone()) {
133                 return archBase;
134             } else {
135                 return archBase + File.separator +
136                         FileUtils.makeFriendlyFileName(mdesc.getArchiveUri());
137             }
138         }
139     }
140 }
141
Popular Tags