KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * The Bean Provider must declare all enterprise bean's references to the homes
34  * of other enterprise beans as specified in section 14.3.2 of the Moscone spec.
35  * Check for one within the same jar file, can't check outside of jar file.
36  * Load/locate & check other bean's home/remote/bean, ensure they match with
37  * what the linking bean says they should be; check for pair of referencing and
38  * referenced beans exist.
39  */

40 public class AppClientEjbReferencesElement extends AppClientTest implements AppClientCheck {
41
42
43     /**
44      * The Bean Provider must declare all enterprise bean's references to the homes
45      * of other enterprise beans as specified in section 14.3.2 of the Moscone spec.
46      * Check for one within the same jar file, can't check outside of jar file.
47      * Load/locate & check other bean's home/remote/bean, ensure they match with
48      * what the linking bean says they should be; check for pair of referencing and
49      * referenced beans exist.
50      *
51      * @param descriptor the Application client deployment descriptor
52      *
53      * @return <code>Result</code> the results for this assertion
54      */

55     public Result check(ApplicationClientDescriptor descriptor) {
56
57     Result result = getInitializedResult();
58     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
59
60     if (descriptor instanceof ApplicationClientDescriptor) {
61         // RULE: References to other beans must be declared in the form of
62
// references to other beans homes as specified in section
63
// 14.3.2 of the Moscone spec.
64

65         // check for one bean within the same jar file; can't check outside of
66
// jar file. need to load/locate and check other beans remote, home, bean
67
// match with the linking bean says they should be. i.e. check for pair
68
// of referencing & referenced bean exist, using reflection API
69

70         EjbReferenceDescriptor ejbReference;
71         Set references = descriptor.getEjbReferenceDescriptors();
72         Iterator iterator = references.iterator();
73       
74         if (iterator.hasNext()) {
75             boolean oneFailed = false;
76         while (iterator.hasNext()) {
77             ejbReference = (EjbReferenceDescriptor) iterator.next();
78
79             String JavaDoc homeClassName = ejbReference.getHomeClassName();
80             if(homeClassName == null) {
81                 oneFailed = true;
82                 result.addErrorDetails(smh.getLocalString
83                                         ("tests.componentNameConstructor",
84                                         "For [ {0} ]",
85                                         new Object JavaDoc[] {compName.toString()}));
86                 result.failed(smh.getLocalString
87                                       (getClass().getName() + ".failed1",
88                                        "Error: {0} class cannot be null.",
89                                        new Object JavaDoc[] {"home"}));
90             } else {
91                 try {
92                     Class.forName(homeClassName, false, getVerifierContext().getClassLoader());
93                 } catch (ClassNotFoundException JavaDoc e) {
94                     Verifier.debug(e);
95                     oneFailed = true;
96                     result.addErrorDetails(smh.getLocalString
97                                ("tests.componentNameConstructor",
98                                 "For [ {0} ]",
99                                 new Object JavaDoc[] {compName.toString()}));
100                     result.failed(smh.getLocalString
101                           (getClass().getName() + ".failed",
102                            "Error: [ {0} ] class [ {1} ] cannot be found within this jar [ {2} ].",
103                            new Object JavaDoc[] {ejbReference.getName(), homeClassName,
104                                          descriptor.getModuleDescriptor().getArchiveUri()}));
105                 }
106                 result.addGoodDetails(smh.getLocalString
107                                         ("tests.componentNameConstructor",
108                                         "For [ {0} ]",
109                                         new Object JavaDoc[] {compName.toString()}));
110                 result.passed(smh.getLocalString
111                     (getClass().getName() + ".passed2",
112                     "The referenced bean's home interface [ {0} ] exists and is loadable within [ {1} ].",
113                     new Object JavaDoc[] {ejbReference.getHomeClassName(),
114                                   descriptor.getModuleDescriptor().getArchiveUri()}));
115             }
116             
117             String JavaDoc remoteClassName = ejbReference.getEjbInterface();
118             if(remoteClassName == null) {
119                 oneFailed = true;
120                 result.addErrorDetails(smh.getLocalString
121                         ("tests.componentNameConstructor",
122                         "For [ {0} ]",
123                         new Object JavaDoc[] {compName.toString()}));
124                 result.failed(smh.getLocalString
125                         (getClass().getName() + ".failed1",
126                        "Error: {0} class cannot be null.",
127                         new Object JavaDoc[] {"remote"}));
128             } else {
129                 try {
130                     Class.forName(remoteClassName, false, getVerifierContext().getClassLoader());
131                 } catch (ClassNotFoundException JavaDoc e) {
132                     Verifier.debug(e);
133                     oneFailed = true;
134                     result.addErrorDetails(smh.getLocalString
135                                ("tests.componentNameConstructor",
136                                 "For [ {0} ]",
137                                 new Object JavaDoc[] {compName.toString()}));
138                     result.failed(smh.getLocalString
139                           (getClass().getName() + ".failed",
140                            "Error: [ {0} ] class [ {1} ] cannot be found within this jar [ {2} ].",
141                            new Object JavaDoc[] {ejbReference.getName(), remoteClassName,
142                                          descriptor.getModuleDescriptor().getArchiveUri()}));
143                 }
144                 result.addGoodDetails(smh.getLocalString
145                         ("tests.componentNameConstructor",
146                         "For [ {0} ]",
147                         new Object JavaDoc[] {compName.toString()}));
148                 result.passed(smh.getLocalString
149                         (getClass().getName() + ".passed3",
150                         "The referenced bean's remote interface [ {0} ] exists and is loadable within [ {1} ].",
151                         new Object JavaDoc[] {ejbReference.getEjbInterface(),
152                                       descriptor.getModuleDescriptor().getArchiveUri()}));
153             }
154         }
155         if (oneFailed) {
156             result.setStatus(result.FAILED);
157         } else {
158             result.setStatus(result.PASSED);
159         }
160         } else {
161             result.addNaDetails(smh.getLocalString
162                            ("tests.componentNameConstructor",
163                         "For [ {0} ]",
164                         new Object JavaDoc[] {compName.toString()}));
165             result.notApplicable(smh.getLocalString
166                          (getClass().getName() + ".notApplicable1",
167                           "There are no ejb references to other beans within this application client [ {0} ]",
168                           new Object JavaDoc[] {descriptor.getName()}));
169         }
170  
171         return result;
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                     "[ {0} ] not called with a application client.",
180                     new Object JavaDoc[] {getClass()}));
181         return result;
182     }
183     }
184 }
185
186
187
Popular Tags