KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > primarykeyclass > PrimaryKeyClassElement


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.entity.primarykeyclass;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.deployment.EjbEntityDescriptor;
28 import com.sun.enterprise.tools.verifier.*;
29 import java.lang.ClassLoader JavaDoc;
30 import java.util.logging.Level JavaDoc;
31
32 import com.sun.enterprise.tools.verifier.tests.*;
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 /**
36  * Entity bean's Primary Key Class test.
37  * If the enterprise bean is a Entity Bean, the Bean provider specifies
38  * the fully qualified name of the Entity bean's primary key class in the
39  * "primary-class" element. The Bean provider 'must' specify the primary key
40  * class for an Entity with bean managed persistence, and 'may' (but is not
41  * required to) specify the primary key class for an Entity with
42  * Container-managed persistence.
43  */

44 public class PrimaryKeyClassElement extends EjbTest implements EjbCheck {
45
46     /**
47      * Entity bean's Primary Key Class test.
48      * If the enterprise bean is a Entity Bean, the Bean provider specifies
49      * the fully qualified name of the Entity bean's primary key class in the
50      * "primary-class" element. The Bean provider 'must' specify the primary key
51      * class for an Entity with bean managed persistence, and 'may' (but is not
52      * required to) specify the primary key class for an Entity with
53      * Container-managed persistence.
54      *
55      * @param descriptor the Enterprise Java Bean deployment descriptor
56      *
57      * @return <code>Result</code> the results for this assertion
58      */

59     public Result check(EjbDescriptor descriptor) {
60
61     Result result = getInitializedResult();
62     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
63
64     if (descriptor instanceof EjbEntityDescriptor) {
65         String JavaDoc persistence =
66         ((EjbEntityDescriptor)descriptor).getPersistenceType();
67         if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
68         logger.log(Level.FINE, getClass().getName() + ".debug1",
69                 new Object JavaDoc[] {descriptor.getName(), "bean"});
70         String JavaDoc primkey =
71             ((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName();
72
73         if (!primkey.equals("java.lang.String")) {
74             try {
75             Class JavaDoc c = Class.forName(primkey, false, getVerifierContext().getClassLoader());
76
77             result.addGoodDetails(smh.getLocalString
78                           ("tests.componentNameConstructor",
79                            "For [ {0} ]",
80                            new Object JavaDoc[] {compName.toString()}));
81             result.passed(smh.getLocalString
82                       (getClass().getName() + ".passed",
83                        "Primary Key Class [ {0} ] exist and is loadable",
84                        new Object JavaDoc[] {primkey}));
85             } catch (Exception JavaDoc e) {
86             Verifier.debug(e);
87             result.addErrorDetails(smh.getLocalString
88                            ("tests.componentNameConstructor",
89                         "For [ {0} ]",
90                         new Object JavaDoc[] {compName.toString()}));
91             result.failed(smh.getLocalString
92                       (getClass().getName() + ".failedException",
93                        "Error: Loading Primary Key Class [ {0} ]",
94                        new Object JavaDoc[] {primkey}));
95             return result;
96             }
97         } else {
98             result.addGoodDetails(smh.getLocalString
99                       ("tests.componentNameConstructor",
100                        "For [ {0} ]",
101                        new Object JavaDoc[] {compName.toString()}));
102
103             result.passed(smh.getLocalString
104                   (getClass().getName() + ".passed1",
105                    "Primary Key Class is [ {0} ]",
106                    new Object JavaDoc[] {primkey}));
107         }
108
109         return result;
110
111         } else if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
112         result.addNaDetails(smh.getLocalString
113                     ("tests.componentNameConstructor",
114                      "For [ {0} ]",
115                      new Object JavaDoc[] {compName.toString()}));
116         result.notApplicable(smh.getLocalString
117                      (getClass().getName() + ".notApplicable1",
118                       "Entity Bean [ {0} ] with [ {1} ] managed persistence, primkey optional.",
119                       new Object JavaDoc[] {descriptor.getName(),persistence}));
120         return result;
121         }
122         else {
123         result.addNaDetails(smh.getLocalString
124                     ("tests.componentNameConstructor",
125                      "For [ {0} ]",
126                      new Object JavaDoc[] {compName.toString()}));
127         result.notApplicable(smh.getLocalString
128                      (getClass().getName() + ".notApplicable2",
129                       "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.",
130                       new Object JavaDoc[] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence}));
131         return result;
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                   "[ {0} ] expected {1} bean, but called with {2} bean.",
141                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
142         return result;
143     }
144     }
145 }
146
Popular Tags