KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ejb30 > BusinessIntfAnnotationValue


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 package com.sun.enterprise.tools.verifier.tests.ejb.ejb30;
22
23 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
24 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
25 import com.sun.enterprise.tools.verifier.Result;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27
28 import javax.ejb.Remote JavaDoc;
29 import javax.ejb.Local JavaDoc;
30 import java.util.Set JavaDoc;
31
32 /**
33  * It is an error if @Local or @Remote is specified both on the bean class and
34  * on the referenced interface and the values differ. (Expert Group discussions)
35  *
36  * @author Vikas Awasthi
37  */

38 public class BusinessIntfAnnotationValue extends EjbTest {
39
40     private Result result;
41     private ComponentNameConstructor compName;
42     private Class JavaDoc<Remote JavaDoc> remoteAnn = Remote JavaDoc.class;
43     private Class JavaDoc<Local JavaDoc> localAnn = Local JavaDoc.class;
44     
45     public Result check(EjbDescriptor descriptor) {
46         result = getInitializedResult();
47         compName = getVerifierContext().getComponentNameConstructor();
48
49         testInterfaces(descriptor.getLocalBusinessClassNames(), remoteAnn);
50         testInterfaces(descriptor.getRemoteBusinessClassNames(), localAnn);
51     
52         if(result.getStatus() != Result.FAILED) {
53             addGoodDetails(result, compName);
54             result.passed(smh.getLocalString
55                             (getClass().getName() + ".passed",
56                             "Valid annotations used in business interface(s)."));
57         }
58         return result;
59     }
60     
61     private void testInterfaces(Set JavaDoc<String JavaDoc> interfaces, Class JavaDoc annot) {
62         // used in failure message
63
Class JavaDoc cls = (annot.equals(localAnn))? remoteAnn : localAnn;
64
65         for (String JavaDoc intf : interfaces) {
66             try {
67                 Class JavaDoc intfCls = Class.forName(intf,
68                                              false,
69                                              getVerifierContext().getClassLoader());
70                 if(intfCls.getAnnotation(annot)!=null) {
71                     addErrorDetails(result, compName);
72                     result.failed(smh.getLocalString
73                                  (getClass().getName() + ".failed",
74                                  "{0} annotation is used in {1} interface [ {2} ].",
75                                  new Object JavaDoc[]{annot.getSimpleName(),
76                                              cls.getSimpleName(),
77                                              intfCls.getName()}));
78                 }
79             } catch (ClassNotFoundException JavaDoc e) {
80              //ignore as it will be caught in other tests
81
}
82         }
83     }
84 }
85
Popular Tags