KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > webservices > EndPointImplBeanClassChecker


1
2 /*
3  * The contents of this file are subject to the terms
4  * of the Common Development and Distribution License
5  * (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the license at
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
10  * glassfish/bootstrap/legal/CDDLv1.0.txt.
11  * See the License for the specific language governing
12  * permissions and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL
15  * Header Notice in each file and include the License file
16  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
17  * If applicable, add the following below the CDDL Header,
18  * with the fields enclosed by brackets [] replaced by
19  * you own identifying information:
20  * "Portions Copyrighted [year] [name of copyright owner]"
21  *
22  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23  */

24 package com.sun.enterprise.tools.verifier.tests.webservices;
25
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import java.util.*;
29 import java.lang.reflect.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 // The condition of bean class here is that it does not implement SEI
33
// So we need to check if it implements all method signatures in SEI.
34
/*
35  * @class.setup_props: ;
36  */

37
38 /*
39  * @testName: check
40  * @assertion_ids: ;
41  * @test_Strategy:
42  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
43  */

44 public class EndPointImplBeanClassChecker extends WSTest implements WSCheck {
45
46     private Class JavaDoc sei;
47     private Class JavaDoc bean;
48     private Result result;
49     private boolean isEjbEndpoint;
50     private String JavaDoc schemaVersion;
51
52     public EndPointImplBeanClassChecker (Class JavaDoc seiClz, Class JavaDoc beanClz, Result resultInst, String JavaDoc version ) {
53
54        sei = seiClz;
55        bean = beanClz;
56        result = resultInst;
57        isEjbEndpoint = true;
58        schemaVersion = version;
59     }
60
61     public EndPointImplBeanClassChecker (Class JavaDoc seiClz, Class JavaDoc beanClz, Result resultInst,
62                                                                          boolean isEjb) {
63        sei = seiClz;
64        bean = beanClz;
65        result = resultInst;
66        isEjbEndpoint = isEjb;
67     }
68
69     /**
70      * @param descriptor the Enterprise Java Bean deployment descriptor
71      * @return <code>Result</code> the results for this assertion
72      */

73     public Result check (WebServiceEndpoint descriptor) {
74       return null;
75     }
76
77     public boolean check (ComponentNameConstructor compName) {
78
79         boolean pass = true;
80
81         // should define default public constructor
82
try {
83           bean.getConstructor(new Class JavaDoc[0]);
84           // result.pass has public default constructor
85
result.addGoodDetails(smh.getLocalString
86                                   ("tests.componentNameConstructor",
87                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
88           result.passed(smh.getLocalString (
89                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
90                        new Object JavaDoc[] {"The Service Impl Bean has a public default Constructor"}));
91
92         }catch (NoSuchMethodException JavaDoc e) {
93          //result.fail no default public constructor
94
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
95                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
96          result.failed(smh.getLocalString
97              ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
98              new Object JavaDoc[] {"The Service Impl Bean does not have a default public Constructor"}));
99          pass = false;
100         }catch (LinkageError JavaDoc e){
101             Verifier.debug(e);
102             pass = false;
103             addErrorDetails(result, compName);
104             result.failed(smh.getLocalString (
105                        "com.sun.enterprise.tools.verifier.tests.webservices.failed1",
106                             "Error: [ {0} ] class used in [ {1} ] class cannot be found.",
107                             new Object JavaDoc[] {e.getMessage().replace('/','.'), bean.getName()}));
108         }
109
110         // class should be public, not final and not abstract
111
int modifiers = bean.getModifiers();
112         if (Modifier.isPublic(modifiers)) {
113            //result.pass
114
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
115                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
116           result.passed(smh.getLocalString (
117                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
118                        new Object JavaDoc[] {"The Service Impl Bean is public"}));
119          }
120          else {
121            // result.fail EndPoint Impl class not public
122
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
123                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
124          result.failed(smh.getLocalString
125              ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
126              new Object JavaDoc[] {"The Service Impl Bean is not public"}));
127            pass = false;
128          }
129
130         if (Modifier.isFinal(modifiers)) {
131           // result.fail EndPoint Impl class declared final
132
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
133                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
134          result.failed(smh.getLocalString
135              ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
136              new Object JavaDoc[] {"The Service Impl Bean is does not implement SEI, but is decalred final"}));
137            pass = false;
138          }
139          else {
140           // result.pass
141
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
142                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
143           result.passed(smh.getLocalString (
144                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
145                        new Object JavaDoc[] {"The Service Impl Bean class is not declared final"}));
146          }
147
148          if (Modifier.isAbstract(modifiers)) {
149            // result.fail endpoint impl class cannot be asbtract
150
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
151                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
152          result.failed(smh.getLocalString
153              ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
154              new Object JavaDoc[] {"The Service Impl Bean class is decalred final"}));
155            pass = false;
156          }
157          else {
158            // result.pass
159
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
160                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
161           result.passed(smh.getLocalString (
162                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
163                        new Object JavaDoc[] {"The Service Impl Bean class is not abstract"}));
164          }
165
166         // should not define finalize()
167
try {
168           if (bean.getDeclaredMethod("finalize", new Class JavaDoc[0]) != null) {
169               //result.fail, bean should not declare finalize
170
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
171                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
172               result.failed(smh.getLocalString
173                   ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
174                   new Object JavaDoc[] {"The Service Impl Bean class defines finalize() method"}));
175               pass = false;
176            }
177         }catch(NoSuchMethodException JavaDoc e) {
178            //result.pass, does not declare finalize
179
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
180                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
181           result.passed(smh.getLocalString (
182                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
183                        new Object JavaDoc[] {"The Service Impl Bean class does not define finalize() method"}));
184         }catch (LinkageError JavaDoc e){
185             Verifier.debug(e);
186             pass = false;
187             addErrorDetails(result, compName);
188             result.failed(smh.getLocalString (
189                        "com.sun.enterprise.tools.verifier.tests.webservices.failed1",
190                             "Error: [ {0} ] class used in [ {1} ] class cannot be found.",
191                             new Object JavaDoc[] {e.getMessage().replace('/','.'), bean.getName()}));
192         }
193         if (isEjbEndpoint && !(schemaVersion.compareTo("1.1")>0)) {
194            // should define a NoArg ejbCreate()
195
try {
196              if (bean.getDeclaredMethod("ejbCreate", new Class JavaDoc[0]) != null) {
197                  //result.pass, bean has no-arg ejbCreate()
198
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
199                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
200                  result.passed(smh.getLocalString (
201                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
202                        new Object JavaDoc[] {"The Service Impl Bean class defines ejbCreate()"}));
203               }
204            }catch(NoSuchMethodException JavaDoc e) {
205               //result.fail, does not declare ejbCreate
206
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
207                                  "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
208               result.failed(smh.getLocalString
209                    ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
210                    new Object JavaDoc[] {"The Service Impl Bean class has no ejbCreate()"}));
211               pass = false;
212            }catch (LinkageError JavaDoc e){
213             Verifier.debug(e);
214             pass = false;
215             addErrorDetails(result, compName);
216             result.failed(smh.getLocalString (
217                        "com.sun.enterprise.tools.verifier.tests.webservices.failed1",
218                             "Error: [ {0} ] class used in [ {1} ] class cannot be found.",
219                             new Object JavaDoc[] {e.getMessage().replace('/','.'), bean.getName()}));
220         }
221            // should define a NoArg ejbRemove()
222
try {
223              if (bean.getDeclaredMethod("ejbRemove", new Class JavaDoc[0]) != null) {
224                  //result.pass, bean has no-arg ejbRemove()
225
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
226                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
227                  result.passed(smh.getLocalString (
228                        "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
229                        new Object JavaDoc[] {"The Service Impl Bean class defines ejbRemove()"}));
230               }
231            }catch(NoSuchMethodException JavaDoc e) {
232               //result.fail, does not declare ejbRemove
233
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
234                                  "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
235               result.failed(smh.getLocalString
236                    ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
237                    new Object JavaDoc[] {"The Service Impl Bean class has no ejbRemove()"}));
238               pass = false;
239            }catch (LinkageError JavaDoc e){
240             Verifier.debug(e);
241             pass = false;
242             addErrorDetails(result, compName);
243             result.failed(smh.getLocalString (
244                     "com.sun.enterprise.tools.verifier.tests.webservices.failed1",
245                     "Error: [ {0} ] class used in [ {1} ] class cannot be found.",
246                     new Object JavaDoc[] {e.getMessage().replace('/','.'), bean.getName()}));
247         }
248         }
249
250      return pass;
251     }
252     
253     public Vector getSEIMethodsNotImplemented() {
254  
255       Vector<String JavaDoc> ret = new Vector<String JavaDoc>();
256       // here the methods could be in the base class as well
257
Method[] beanPubMethods = bean.getMethods();
258       Method[] seiMethods = sei.getMethods();
259       for ( int i=0; i < seiMethods.length; i++) {
260           if (!hasMatchingMethod(seiMethods[i], beanPubMethods)) {
261              // doesnt have matching method
262
ret.add(seiMethods[i].toString());
263           }
264       }
265       return ret;
266     }
267
268     private boolean hasMatchingMethod(Method meth, Method[] tobeChecked) {
269
270      for (int i=0; i < tobeChecked.length; i++) {
271          if (WSTest.matchesSignatureAndReturn(meth, tobeChecked[i]))
272             return true;
273      }
274      return false;
275     }
276  }
277
278
Popular Tags