KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ComponentNameConstructor


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.tools.verifier.tests;
24 import com.sun.enterprise.deployment.*;
25 import com.sun.enterprise.deployment.util.ModuleDescriptor;
26
27 /**
28  * This class constructs the name of the app client/bean/connector as
29  * appName.jarName.componentName
30  *
31  * @author Sheetal Vartak
32  */

33
34 public class ComponentNameConstructor {
35
36     private String JavaDoc appName = "";
37     private String JavaDoc jarName = "";
38     private String JavaDoc componentName = "";
39     
40     public ComponentNameConstructor(EjbDescriptor ejbDsc) {
41         EjbBundleDescriptor ejbBundle = ejbDsc.getEjbBundleDescriptor();
42         ModuleDescriptor moduleDesc = ejbBundle.getModuleDescriptor();
43         if(!moduleDesc.isStandalone()){ // print app name only for embedded ones
44
this.appName = ejbBundle.getApplication().getRegistrationName();
45         }
46         this.jarName = moduleDesc.getArchiveUri();
47         this.componentName = ejbDsc.getName();
48     }
49
50     // this takes care of all bundle descriptors.
51
public ComponentNameConstructor(BundleDescriptor bundleDesc) {
52         ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
53         if(!moduleDesc.isStandalone()){ // print app name only for embedded ones
54
this.appName = bundleDesc.getApplication().getRegistrationName();
55         }
56         this.jarName = moduleDesc.getArchiveUri();
57         // there is no point in printing comp name since it is bundle desc.
58
}
59
60     public ComponentNameConstructor(String JavaDoc appName, String JavaDoc jarName, String JavaDoc componentName) {
61         this.appName = appName;
62         this.jarName = jarName;
63         this.componentName = componentName;
64     }
65
66     public ComponentNameConstructor(WebServiceEndpoint wse) {
67         BundleDescriptor bundleDesc = wse.getBundleDescriptor();
68         ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
69         if(!moduleDesc.isStandalone()){ // print app name only for embedded ones
70
this.appName = bundleDesc.getApplication().getRegistrationName();
71         }
72         this.jarName = moduleDesc.getArchiveUri();
73         // WebServiceEndpoint path is WebServices->WebService->WebServiceEndpoint
74
this.componentName = wse.getWebService().getName()+"#"+wse.getEndpointName(); // NOI18N
75
}
76
77     public ComponentNameConstructor(ServiceReferenceDescriptor srd) {
78         BundleDescriptor bundleDesc = srd.getBundleDescriptor();
79         ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
80         if(!moduleDesc.isStandalone()){ // print app name only for embedded ones
81
this.appName = bundleDesc.getApplication().getRegistrationName();
82         }
83         this.jarName = moduleDesc.getArchiveUri();
84         this.componentName = srd.getName();
85     }
86
87     public ComponentNameConstructor(WebService wsDsc) {
88         BundleDescriptor bundleDesc = wsDsc.getBundleDescriptor();
89         ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
90         if(!moduleDesc.isStandalone()){ // print app name only for embedded ones
91
this.appName = bundleDesc.getApplication().getRegistrationName();
92         }
93         this.jarName = moduleDesc.getArchiveUri();
94         this.componentName = wsDsc.getName();
95     }
96
97     public ComponentNameConstructor(Application application) {
98         this.appName = application.getRegistrationName();
99     }
100
101     public ComponentNameConstructor(PersistenceUnitDescriptor
102             descriptor) {
103         PersistenceUnitsDescriptor persistenceUnitsDescriptor =
104                 descriptor.getParent();
105         RootDeploymentDescriptor container = persistenceUnitsDescriptor.getParent();
106         if(container.isApplication()) {
107             this.appName = Application.class.cast(container).getRegistrationName();
108             this.componentName = persistenceUnitsDescriptor.getPuRoot() +
109                     "#"+descriptor.getName(); // NOI18N
110
} else { // this PU is bundled inside a module
111
BundleDescriptor bundleDesc = BundleDescriptor.class.cast(container);
112             ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
113             if(!moduleDesc.isStandalone()){ // print app name only for embedded ones
114
this.appName = bundleDesc.getApplication().getRegistrationName();
115             }
116             this.jarName = moduleDesc.getArchiveUri();
117             String JavaDoc puRoot = persistenceUnitsDescriptor.getPuRoot();
118             // for EJB module, PURoot is empty, so to avoid ## in report, this check is needed.
119
this.componentName = ("".equals(puRoot) ? "" : puRoot + "#") + descriptor.getName(); // NOI18N
120
}
121     }
122
123     public String JavaDoc toString() {
124         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
125         if(!isNullOrEmpty(appName)){
126             sb.append(appName);
127         }
128         if(!isNullOrEmpty(jarName)){
129             if(!isNullOrEmpty(appName)) sb.append("#"); // NOI18N
130
sb.append(jarName);
131         }
132         if(!isNullOrEmpty(componentName)){
133             if(!isNullOrEmpty(jarName) || !isNullOrEmpty(appName)) sb.append("#"); // NOI18N
134
sb.append(componentName);
135         }
136         return sb.toString();
137     }
138
139     private static boolean isNullOrEmpty(String JavaDoc s) {
140         return s == null || s.length() == 0;
141     }
142
143 }
144
Popular Tags