KickJava   Java API By Example, From Geeks To Geeks.

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


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.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
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 import com.sun.enterprise.tools.verifier.XpathPrefixResolver;
33
34 /**
35  * The ejb-ref-type element must be one of the following:
36  * Entity
37  * Session
38  */

39 public class EjbRefTypeElement extends EjbTest implements EjbCheck {
40
41     // Logger to log messages
42
/**
43      * The ejb-ref-type element must be one of the following:
44      * Entity
45      * Session
46      *
47      * @param descriptor the Enterprise Java Bean deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(EjbDescriptor descriptor) {
52
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55     boolean failed = false;
56
57     //The ejb-ref-type element must be one of the following:
58
// Entity
59
// Session
60
if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
61         for (Iterator itr = descriptor.getEjbReferenceDescriptors()
62                 .iterator(); itr.hasNext();) {
63         EjbReferenceDescriptor nextEjbReference =
64                 (EjbReferenceDescriptor) itr.next();
65
66                 // Need to use XPath, because if DOL sees an inconsistent
67
// ref-type, it gives a warning and changes the type
68
//String ejbRefTypeStr = nextEjbReference.getType();
69
String JavaDoc refStr = (nextEjbReference.isLocal()) ?
70                                 "ejb-local-ref" : "ejb-ref";
71                 String JavaDoc beanType = (descriptor.getType()).toLowerCase();
72                 String JavaDoc xpathQuery = null;
73                 if (getVerifierContext().getDocument().getDoctype() != null) {
74                    xpathQuery = "/ejb-jar/enterprise-beans/" +
75                    beanType + "[ejb-name=\"" + descriptor.getName()
76                    +"\"]/" + refStr + "[ejb-ref-name=\""
77                    + nextEjbReference.getName() + "\"]/ejb-ref-type";
78                 }
79                 else {
80                    String JavaDoc prefix = XpathPrefixResolver.fakeXPrefix;
81                    xpathQuery = prefix + ":" + "ejb-jar/" +
82                     prefix + ":" + "enterprise-beans/" +
83                     prefix + ":" + beanType +
84                     "[" + prefix + ":ejb-name=\"" + descriptor.getName()
85                     +"\"]/" +
86                     prefix + ":" + refStr + "[" + prefix + ":ejb-ref-name=\""
87                     + nextEjbReference.getName() + "\"]/" +
88                     prefix + ":" + "ejb-ref-type";
89                 }
90            
91         String JavaDoc ejbRefTypeStr = getXPathValueForNonRuntime(xpathQuery);
92                 EjbDescriptor rdesc = nextEjbReference.getEjbDescriptor();
93
94                 /*if (rdesc == null) {
95                    logger.log(Level.SEVERE, getClass().getName() + ".Warn",
96                    new Object[] {nextEjbReference.getBeanClassName()});
97                 }*/

98
99                 // XPath queries seem to fail for XSD Descriptors
100
if (ejbRefTypeStr == null) {
101                    ejbRefTypeStr = nextEjbReference.getType();
102                 }
103
104             if (!((ejbRefTypeStr.equals(EjbSessionDescriptor.TYPE)) ||
105                 (ejbRefTypeStr.equals(EjbEntityDescriptor.TYPE)))) {
106               result.addErrorDetails(smh.getLocalString
107                        ("tests.componentNameConstructor",
108                         "For [ {0} ]",
109                         new Object JavaDoc[] {compName.toString()}));
110               result.failed(smh.getLocalString
111                   (getClass().getName() + ".failed",
112                    "Error: ejb-ref-type [ {0} ] within \n bean [ {1} ] is not valid. \n Must be [ {2} ] or [ {3} ]",
113                    new Object JavaDoc[] {ejbRefTypeStr,descriptor.getName(),EjbEntityDescriptor.TYPE,EjbSessionDescriptor.TYPE}));
114               failed = true;
115           }
116                   else if (rdesc != null ) {
117                     String JavaDoc actualRefType = rdesc.getType();
118                     if (!ejbRefTypeStr.equals(actualRefType)) {
119                        result.addErrorDetails(smh.getLocalString
120                                            ("tests.componentNameConstructor",
121                                             "For [ {0} ]",
122                                             new Object JavaDoc[] {compName.toString()}));
123                         result.failed(smh.getLocalString
124                            (getClass().getName() + ".failed2",
125                             "Error: ejb-ref-type [ {0} ] was specifed for ejb-ref [ {1} ], within bean [ {2} ], when it should have been [ {3} ].",
126                             new Object JavaDoc[] {ejbRefTypeStr,
127                             nextEjbReference.getName(),
128                             descriptor.getName(), actualRefType}));
129                     failed = true;
130                   }
131           }
132             }
133     } else {
134         result.addNaDetails(smh.getLocalString
135                 ("tests.componentNameConstructor",
136                  "For [ {0} ]",
137                  new Object JavaDoc[] {compName.toString()}));
138         result.notApplicable(smh.getLocalString
139                  (getClass().getName() + ".notApplicable",
140                   "There are no ejb references to other beans within this bean [ {0} ]",
141                   new Object JavaDoc[] {descriptor.getName()}));
142         return result;
143     }
144
145     if (failed)
146         {
147         result.setStatus(Result.FAILED);
148         } else {
149         result.addGoodDetails(smh.getLocalString
150                       ("tests.componentNameConstructor",
151                        "For [ {0} ]",
152                        new Object JavaDoc[] {compName.toString()}));
153         result.passed
154             (smh.getLocalString
155              (getClass().getName() + ".passed",
156               "All ejb-ref-type elements are valid. They are all [ {0} ] or [ {1} ] within this bean [ {2} ]",
157               new Object JavaDoc[] {EjbEntityDescriptor.TYPE,EjbSessionDescriptor.TYPE,descriptor.getName()}));
158         }
159     return result;
160
161     }
162 }
163
Popular Tags