KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > elements > 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.ejb.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
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  * The value of the ejb-link element must be the ejb-name of an enterprise
36  * bean in the same ejb-jar file.
37  */

38 public class EjbLinkElement extends EjbTest implements EjbCheck {
39
40     /**
41      * The referenced bean must be an enterprise bean in the same ear file.
42      *
43      * @param descriptor the Enterprise Java Bean deployment descriptor
44      * @return <code>Result</code> the results for this assertion
45      */

46     public Result check(EjbDescriptor descriptor) {
47
48     Result result = getInitializedResult();
49     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
50
51     boolean resolved = false;
52     boolean oneFailed = false;
53     int na = 0;
54
55     // The value of the ejb-link element must be the ejb-name of an enterprise
56
// bean in the same J2EE Application archive.
57
/*
58     if (Verifier.getEarFile() == null) {
59         // this ejb-jar is not part of an .ear file
60         result.addNaDetails(smh.getLocalString
61                   ("tests.componentNameConstructor",
62                    "For [ {0} ]",
63                    new Object[] {compName.toString()}));
64         result.notApplicable
65         (smh.getLocalString(getClass().getName() + ".no_ear",
66                 "This ejb jar [ {0} ] is not part of a J2EE Archive.",
67                  new Object[] {descriptor.getName()}));
68         return result;
69     }
70          */

71
72 // String applicationName = null;
73
// The value of the ejb-link element must be the ejb-name of an enterprise
74
// bean in the same application .ear file.
75
if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
76         for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator();
77          itr.hasNext();) {
78         EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
79         if (nextEjbReference.isLinked()) {
80             String JavaDoc ejb_link = nextEjbReference.getLinkName();
81             ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1);
82
83             try {
84                     
85 // applicationName = application.getName();
86
// File tmpFile = new File(System.getProperty("java.io.tmpdir"));
87
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
88
Set ejbBundles = descriptor.getApplication().getEjbBundleDescriptors();
89                 Iterator ejbBundlesIterator = ejbBundles.iterator();
90                 EjbBundleDescriptor ejbBundle = null;
91  
92             while (ejbBundlesIterator.hasNext()) {
93                 ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next();
94 // if (Verifier.getEarFile() != null){
95
// archivist.extractEntry(ejbBundle.getModuleDescriptor().getArchiveUri(), tmpFile);
96
// }
97
for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext();) {
98
99                 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
100                 if (ejbDescriptor.getName().equals(ejb_link)) {
101                     resolved = true;
102                     logger.log(Level.FINE, getClass().getName() + ".passed",
103                             new Object JavaDoc[] {ejb_link,ejbDescriptor.getName()});
104                     addGoodDetails(result, compName);
105                     result.addGoodDetails
106                     (smh.getLocalString
107                      (getClass().getName() + ".passed",
108                       "Valid referenced bean [ {0} ].",
109                       new Object JavaDoc[] {ejb_link}));
110                     break;
111                 }
112                 }
113     
114             }
115             } catch(Exception JavaDoc e) {
116             addErrorDetails(result, compName);
117             result.addErrorDetails(smh.getLocalString
118                            (getClass().getName() + ".failedException1",
119                         "Exception occured while opening or saving the J2EE archive.",
120                         new Object JavaDoc[] {}));
121                 logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint",
122                         new Object JavaDoc[] {"[" + getClass() + "] Error: " + e.getMessage()});
123
124                         if (!oneFailed) {
125                             oneFailed = true;
126                         }
127             }
128     
129             // before you go onto the next ejb-link, tell me whether you
130
// resolved the last ejb-link okay
131
if (!resolved) {
132                         if (!oneFailed) {
133                             oneFailed = true;
134                         }
135             addErrorDetails(result, compName);
136             result.addErrorDetails(smh.getLocalString
137                            (getClass().getName() + ".failed",
138                         "Error: No EJB matching [ {0} ] found within [ {1} ] jar file.",
139                         new Object JavaDoc[] {ejb_link, descriptor.getName()}));
140             } else {
141             // clear the resolved flag for the next ejb-link
142
resolved =false;
143             }
144     
145         } else {
146             // Cannot get the link name of an ejb reference referring
147
// to an external bean, The value of the ejb-link element
148
// must be the ejb-name of an enterprise bean in the same
149
// ejb-ear file.
150
addNaDetails(result, compName);
151             result.addNaDetails
152             (smh.getLocalString
153              (getClass().getName() + ".notApplicable1",
154               "Warning: Cannot verify the existence of an ejb reference [ {0} ] to external bean within different .ear file.",
155               new Object JavaDoc[] {nextEjbReference.getName()}));
156             na++;
157         }
158         }
159
160         if (oneFailed) {
161         result.setStatus(Result.FAILED);
162         } else if (na == descriptor.getEjbReferenceDescriptors().size()) {
163         result.setStatus(Result.NOT_APPLICABLE);
164         } else {
165         result.setStatus(Result.PASSED);
166         }
167 // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
168
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
169
// tmpFile.delete();
170
return result;
171
172     } else {
173         addNaDetails(result, compName);
174         result.notApplicable(smh.getLocalString
175                  (getClass().getName() + ".notApplicable",
176                   "There are no ejb references to other beans within this bean [ {0} ]",
177                   new Object JavaDoc[] {descriptor.getName()}));
178     }
179
180     return result;
181     }
182 }
183
Popular Tags