KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > appclient > elements > AppClientEjbLinkOnlyOne


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.appclient.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.appclient.AppClientTest;
26 import com.sun.enterprise.tools.verifier.tests.appclient.AppClientCheck;
27 import java.util.*;
28 import java.util.logging.Level JavaDoc;
29
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.*;
33
34 /**
35  * For each application client ejb-link element, there must be only one
36  * corresponding ejb that fullfils that dependancy in the scope of the
37  * application.
38  */

39 public class AppClientEjbLinkOnlyOne extends AppClientTest implements AppClientCheck {
40
41     /**
42      * For each application client ejb-link element, there must be only one
43      * corresponding ejb that fullfils that dependancy in the scope of the
44      * application.
45      *
46      * @param descriptor the Application client deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check(ApplicationClientDescriptor descriptor) {
51
52     Result result = getInitializedResult();
53     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54
55     int resolved = 0;
56     boolean oneFailed = false;
57     int na = 0;
58     boolean pathPrefix = false;
59     String JavaDoc jar_name = "";
60 /*
61         if (Verifier.getEarFile() == null) {
62             // this appclient is not part of an .ear file
63         result.addNaDetails(smh.getLocalString
64                        ("tests.componentNameConstructor",
65                     "For [ {0} ]",
66                     new Object[] {compName.toString()}));
67             result.notApplicable
68                 (smh.getLocalString
69                     (getClass().getName() + ".no_ear",
70                     "This Application Client [ {0} ] is not part of a J2EE Archive.",
71                      new Object[] {descriptor.getName()}));
72             return result;
73         }
74 */

75 // String applicationName = null;
76

77     // The value of the ejb-link element must be the ejb-name of an enterprise
78
// bean in the same ejb-jar file.
79
if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
80         for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator();
81          itr.hasNext();) {
82         EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
83         if (nextEjbReference.isLinked()) {
84             String JavaDoc ejb_link = nextEjbReference.getLinkName();
85             if (ejb_link.indexOf("#") != -1) {
86             jar_name = ejb_link.substring(0,ejb_link.indexOf("#"));
87             ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1);
88             pathPrefix = true;
89             }
90             // get the application descriptor and check all ejb-jars in the application
91
try {
92             // iterate through the ejb jars in this J2EE Application
93
Set ejbBundles = descriptor.getApplication().getEjbBundleDescriptors();
94             Iterator ejbBundlesIterator = ejbBundles.iterator();
95             EjbBundleDescriptor ejbBundle = null;
96                         resolved = 0;
97
98             while (ejbBundlesIterator.hasNext()) {
99                 ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next();
100                 String JavaDoc ejbBundleName = ejbBundle.getModuleDescriptor().getArchiveUri();
101                 // Kumar: this code here seems like dead code to me, because tmpFile is
102
// not being used. and extractBundleToFile, does not modify ejbBundle
103
//((Application)application).getApplicationArchivist().
104
//extractBundleToFile(ejbBundle, tmpFile);
105
for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext();) {
106                 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
107                 if (ejbDescriptor.getName().equals(ejb_link)) {
108                     if ((pathPrefix == true && jar_name.equals(ejbBundleName)) || pathPrefix == false) {
109                     resolved++;
110                     logger.log(Level.FINE, getClass().getName() + ".debug",
111                             new Object JavaDoc[] {ejb_link, ejbDescriptor.getName(), descriptor.getName()});
112                     }
113                 }
114                 if (resolved > 0) {
115                     break;
116                 }
117
118                 }
119                 if (resolved > 0) {
120                 break;
121                 }
122             }
123             }catch (Exception JavaDoc e) {
124             logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint",
125                     new Object JavaDoc[] {"[" + getClass() + "] Error: " + e.getMessage()});
126             if (!oneFailed) {
127                             oneFailed = true;
128                         }
129             }
130
131
132             // before you go onto the next ejb-link, tell me whether you
133
// resolved the last ejb-link okay
134
if (resolved == 0) {
135             if (!oneFailed) {
136                             oneFailed = true;
137                         }
138             result.addErrorDetails(smh.getLocalString
139                        ("tests.componentNameConstructor",
140                     "For [ {0} ]",
141                     new Object JavaDoc[] {compName.toString()}));
142             result.addErrorDetails(smh.getLocalString
143                            (getClass().getName() + ".failed",
144                         "Error: Failed to resolve EJB reference [ {0} ] to a unique EJB in this application.",
145                         new Object JavaDoc[] {nextEjbReference.getLinkName()}));
146             } else if (resolved == 1 || (pathPrefix == true && resolved > 0)) {
147             // clear the resolved counter for the next ejb-link
148
resolved=0;
149             result.addGoodDetails(smh.getLocalString
150                        ("tests.componentNameConstructor",
151                     "For [ {0} ]",
152                     new Object JavaDoc[] {compName.toString()}));
153             result.addGoodDetails
154                 (smh.getLocalString
155                  (getClass().getName() + ".passed",
156                   "EJB reference [ {0} ] is successfully resolved.",
157                   new Object JavaDoc[] {nextEjbReference.getLinkName()}));
158            
159             } else {
160             // Cannot get the link name of an ejb reference referring
161
// to an external bean, The value of the ejb-link element
162
// must be the ejb-name of an enterprise bean in the same
163
// ejb-ear file.
164
result.addNaDetails(smh.getLocalString
165                         ("tests.componentNameConstructor",
166                          "For [ {0} ]",
167                          new Object JavaDoc[] {compName.toString()}));
168             result.addNaDetails
169                 (smh.getLocalString
170                  (getClass().getName() + ".notApplicable1",
171                   "Warning: Cannot verify the existence of an ejb reference [ {0} ] to external bean within different .ear file.",
172                   new Object JavaDoc[] {nextEjbReference.getName()}));
173             }
174         }else {
175             // Cannot get the link name of an ejb reference referring
176
// to an external bean, The value of the ejb-link element
177
// must be the ejb-name of an enterprise bean in the same
178
// ejb-ear file.
179
result.addNaDetails(smh.getLocalString
180                        ("tests.componentNameConstructor",
181                     "For [ {0} ]",
182                     new Object JavaDoc[] {compName.toString()}));
183             result.addNaDetails
184             (smh.getLocalString
185              (getClass().getName() + ".notApplicable1",
186               "Not Applicable: Cannot verify the existence of an ejb reference [ {0} ] to external bean within different .ear file.",
187               new Object JavaDoc[] {nextEjbReference.getName()}));
188             na++;
189         }
190         }
191
192         if (oneFailed) {
193         result.setStatus(result.FAILED);
194         } else if (na == descriptor.getEjbReferenceDescriptors().size()) {
195         result.setStatus(result.NOT_APPLICABLE);
196         } else {
197         result.setStatus(result.PASSED);
198         }
199 // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
200
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
201
// tmpFile.delete();
202
return result;
203
204     } else {
205         result.addNaDetails(smh.getLocalString
206                        ("tests.componentNameConstructor",
207                     "For [ {0} ]",
208                     new Object JavaDoc[] {compName.toString()}));
209         result.notApplicable(smh.getLocalString
210                  (getClass().getName() + ".notApplicable",
211                   "There are no ejb references to other beans within this application client [ {0} ]",
212                   new Object JavaDoc[] {descriptor.getName()}));
213     }
214
215     return result;
216     }
217 }
218
Popular Tags