KickJava   Java API By Example, From Geeks To Geeks.

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


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  * The value of the application client ejb-link element must be the ejb-name
36  * of an enterprise bean in the same ejb .ear file.
37  */

38 public class AppClientEjbLinkElement extends AppClientTest implements AppClientCheck {
39
40     /**
41      * The value of the application client ejb-link element must be the ejb-name
42      * of an enterprise bean in the same ejb-jar file.
43      *
44      * @param descriptor the Application client deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

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

71 // String applicationName = null;
72
// The value of the ejb-link element must be the ejb-name of an enterprise
73
// bean in the same ejb-jar file.
74
if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
75         for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator();
76          itr.hasNext();) {
77         EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
78         if (nextEjbReference.isLinked()) {
79             String JavaDoc ejb_link = nextEjbReference.getLinkName();
80             ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1);
81             // get the application descriptor and check all ejb-jars in the application
82
try {
83 // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
84
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
85

86             // iterate through the ejb jars in this J2EE Application
87
Set ejbBundles = descriptor.getApplication().getEjbBundleDescriptors();
88             Iterator ejbBundlesIterator = ejbBundles.iterator();
89             EjbBundleDescriptor ejbBundle = null;
90
91             while (ejbBundlesIterator.hasNext()) {
92                 ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next();
93             // Kumar: this code here seems like dead code to me, because tmpFile is
94
// not being used. and extractBundleToFile, does not modify ejbBundle
95
//((Application)application).getApplicationArchivist().
96
// extractBundleToFile(ejbBundle, tmpFile);
97

98                 for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext();) {
99                 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
100                 if (ejbDescriptor.getName().equals(ejb_link)) {
101                     resolved = true;
102                     result.addGoodDetails(smh.getLocalString
103                        ("tests.componentNameConstructor",
104                     "For [ {0} ]",
105                     new Object JavaDoc[] {compName.toString()}));
106                     result.addGoodDetails
107                     (smh.getLocalString
108                      (getClass().getName() + ".passed",
109                       "EJB reference [ {0} ] is successfully resolved.",
110                       new Object JavaDoc[] {nextEjbReference.getLinkName()}));
111                     break;
112                 }
113                 }
114             }
115             }catch (Exception JavaDoc e) {
116                 logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint",
117                         new Object JavaDoc[] {"[" + getClass() + "] Error: " + e.getMessage()});
118                 if (!oneFailed) {
119                 oneFailed = true;
120                         }
121                     }
122
123             // before you go onto the next ejb-link, tell me whether you
124
// resolved the last ejb-link okay
125
if (!resolved) {
126                 if (!oneFailed) {
127                 oneFailed = true;
128                         }
129             result.addErrorDetails(smh.getLocalString
130                        ("tests.componentNameConstructor",
131                     "For [ {0} ]",
132                     new Object JavaDoc[] {compName.toString()}));
133             result.addErrorDetails(smh.getLocalString
134                            (getClass().getName() + ".failed",
135                         "Error: Failed to resolve EJB reference [ {0} ].",
136                         new Object JavaDoc[] {nextEjbReference.getLinkName()}));
137             } else {
138             // clear the resolved flag for the next ejb-link
139
resolved =false;
140             }
141
142         } else {
143             // Cannot get the link name of an ejb reference referring
144
// to an external bean, The value of the ejb-link element
145
// must be the ejb-name of an enterprise bean in the same
146
// ejb-ear file.
147
result.addNaDetails(smh.getLocalString
148                        ("tests.componentNameConstructor",
149                     "For [ {0} ]",
150                     new Object JavaDoc[] {compName.toString()}));
151             result.addNaDetails
152             (smh.getLocalString
153              (getClass().getName() + ".notApplicable1",
154               "Not Applicable: 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         result.addNaDetails(smh.getLocalString
174                        ("tests.componentNameConstructor",
175                     "For [ {0} ]",
176                     new Object JavaDoc[] {compName.toString()}));
177         result.notApplicable(smh.getLocalString
178                  (getClass().getName() + ".notApplicable",
179                   "There are no ejb references to other beans within this application client [ {0} ]",
180                   new Object JavaDoc[] {descriptor.getName()}));
181     }
182
183     return result;
184     }
185 /*
186     Application getApplication(File file) throws ArchiveException {
187
188       try {
189         // There is an ApplicationArchivist lying in appserver-core/com/sun/enterprise/deployment
190         com.sun.enterprise.deployment.archivist.Archivist arch =
191         ArchivistFactory.getArchivistForArchive(file);
192         return (Application)(arch.open(file));
193       }
194       catch(Exception e) {
195         throw new ArchiveException(e.getMessage());
196       }
197     }
198  */

199     
200 }
201
Popular Tags