KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > EjbLinkElement


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.web;
24
25 import java.util.*;
26 import java.util.logging.Level JavaDoc;
27 import com.sun.enterprise.deployment.WebBundleDescriptor;
28 import com.sun.enterprise.deployment.EjbBundleDescriptor;
29 import com.sun.enterprise.deployment.EjbReferenceDescriptor;
30 import com.sun.enterprise.deployment.Application;
31 import com.sun.enterprise.deployment.EjbDescriptor;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.*;
34 import com.sun.enterprise.tools.verifier.tests.*;
35
36
37 /** The value of the ejb-link element is the ejb-name of an enterprise
38  * bean in the same J2EE Application archive.
39  */

40 public class EjbLinkElement extends WebTest implements WebCheck {
41
42
43     /** The value of the ejb-link element is the ejb-name of an enterprise
44      * bean in the same J2EE Application archive.
45      *
46      * @param descriptor the Web Application deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check(WebBundleDescriptor descriptor) {
51
52     Result result = getInitializedResult();
53     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54
55     boolean resolved = false;
56     boolean oneFailed = false;
57     int na = 0;
58
59     // The value of the ejb-link element must be the ejb-name of an enterprise
60
// bean in the same J2EE Application archive.
61
String JavaDoc applicationName = null;
62     if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
63         for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator();
64          itr.hasNext();) {
65         EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
66         if (nextEjbReference.isLinked()) {
67             String JavaDoc ejb_link = nextEjbReference.getLinkName();
68             ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1);
69             // get the application descriptor and check all ejb-jars in the application
70
try {
71                         Application application = descriptor.getApplication();
72                         applicationName = application.getName();
73 // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
74
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
75
// iterate through the ejb jars in this J2EE Application
76
Set ejbBundles = application.getEjbBundleDescriptors();
77                         Iterator ejbBundlesIterator = ejbBundles.iterator();
78                         EjbBundleDescriptor ejbBundle = null;
79                         while (ejbBundlesIterator.hasNext()) {
80                             ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next();
81 // if (Verifier.getEarFile() != null){
82
// archivist.extractEntry(ejbBundle.getModuleDescriptor().getArchiveUri(), tmpFile);
83
// }
84
for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext();) {
85                                 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
86                                 if (ejbDescriptor.getName().equals(ejb_link)) {
87                                     resolved = true;
88                                     logger.log(Level.FINE, getClass().getName() + ".passed",
89                                             new Object JavaDoc[] {ejb_link,ejbDescriptor.getName()});
90                                     result.addGoodDetails(smh.getLocalString
91                        ("tests.componentNameConstructor",
92                         "For [ {0} ]",
93                         new Object JavaDoc[] {compName.toString()}));
94                     result.addGoodDetails
95                     (smh.getLocalString
96                      (getClass().getName() + ".passed",
97                       "ejb-link [ {0} ] found same value as EJB [ {1} ]",
98                       new Object JavaDoc[] {ejb_link,ejbDescriptor.getName()}));
99                     break;
100                                 }
101                             }
102                         }
103                     } catch (Exception JavaDoc e) {
104
105
106             logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint {0}", new Object JavaDoc[] {"[" + getClass() + "] Error: " + e.getMessage()});
107             if (!oneFailed) {
108                             oneFailed = true;
109                         }
110             }
111
112             // before you go onto the next ejb-link, tell me whether you
113
// resolved the last ejb-link okay
114
if (!resolved) {
115             if (!oneFailed) {
116                             oneFailed = true;
117                         }
118             result.addErrorDetails(smh.getLocalString
119                            ("tests.componentNameConstructor",
120                         "For [ {0} ]",
121                         new Object JavaDoc[] {compName.toString()}));
122             result.addErrorDetails(smh.getLocalString
123                            (getClass().getName() + ".failed",
124                         "Error: No EJB matching [ {0} ] found within [ {1} ] ear file.",
125                         new Object JavaDoc[] {ejb_link, applicationName}));
126             } else {
127             // clear the resolved flag for the next ejb-link
128
resolved =false;
129             }
130
131         } else {
132             // Cannot get the link name of an ejb reference referring
133
// to an external bean
134
result.addNaDetails(smh.getLocalString
135                        ("tests.componentNameConstructor",
136                         "For [ {0} ]",
137                         new Object JavaDoc[] {compName.toString()}));
138             result.addNaDetails
139             (smh.getLocalString
140              (getClass().getName() + ".notApplicable1",
141               "Not Applicable: Cannot verify the existance of an ejb reference [ {0} ] to external bean within different .ear file.",
142               new Object JavaDoc[] {nextEjbReference.getName()}));
143             na++;
144         }
145         }
146
147         if (oneFailed) {
148         result.setStatus(result.FAILED);
149         } else if (na == descriptor.getEjbReferenceDescriptors().size()) {
150         result.setStatus(result.NOT_APPLICABLE);
151         } else {
152         result.setStatus(result.PASSED);
153         }
154 // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
155
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
156
// tmpFile.delete();
157
return result;
158
159     } else {
160         result.notApplicable(smh.getLocalString
161                  (getClass().getName() + ".notApplicable",
162                   "There are no ejb references to other beans within this web archive [ {0} ]",
163                   new Object JavaDoc[] {descriptor.getName()}));
164     }
165     return result;
166     }
167 }
168
Popular Tags