KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import java.util.Iterator JavaDoc;
26
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbReferenceDescriptor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
31
32 /**
33  * The ejb-ref-name element contains the name of an EJB reference. The EJB
34  * reference is an entry in the enterprise bean's environment. It is
35  * recommended that name is prefixed with "ejb/".
36  */

37 public class EjbRefNamePrefixed extends EjbTest implements EjbCheck {
38
39     /**
40      * The ejb-ref-name element contains the name of an EJB reference. The EJB
41      * reference is an entry in the enterprise bean's environment. It is
42      * recommended that name is prefixed with "ejb/".
43      *
44      * @param descriptor the Enterprise Java Bean deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(EjbDescriptor descriptor) {
49
50         Result result = getInitializedResult();
51         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52
53         if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
54             for (Iterator JavaDoc itr = descriptor.getEjbReferenceDescriptors().iterator();
55                  itr.hasNext();) {
56                 EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
57                 String JavaDoc ejbRefName = nextEjbReference.getName();
58                 if (!ejbRefName.startsWith("ejb/")) {
59                     addWarningDetails(result, compName);
60                     result.addWarningDetails(smh.getLocalString
61                             (getClass().getName() + ".warning",
62                             "Warning: [ {0} ] is not prefixed with recommended string " +
63                             "ejb/ within bean [ {1} ]",
64                             new Object JavaDoc[] {ejbRefName,descriptor.getName()}));
65                 }
66             }
67         }
68         if (result.getStatus() != Result.WARNING) {
69             addGoodDetails(result, compName);
70             result.passed(smh.getLocalString
71                     (getClass().getName() + ".passed",
72                     "ejb-ref-name is properly defined within bean [ {0} ]",
73                     new Object JavaDoc[] {descriptor.getName()}));
74         }
75         return result;
76     }
77 }
78
Popular Tags