KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Method JavaDoc;
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
29 import com.sun.enterprise.tools.verifier.*;
30 import java.lang.ClassLoader JavaDoc;
31 import com.sun.enterprise.tools.verifier.tests.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 /**
35  * Entity bean's Primary Key Class type test.
36  * If the enterprise bean is a Entity Bean, the Bean provider specifies
37  * the fully qualified name of the Entity bean's primary key class in the
38  * "primary-class" element. The Bean provider 'must' specify the primary key
39  * class for an Entity with bean managed persistence, and 'may' (but is not
40  * required to) specify the primary key class for an Entity with
41  * Container-managed persistence.
42  *
43  * Special case: Unknown primary key class
44  * In special situations, the Bean Provider may choose not to specify the
45  * primary key class for an entity bean with container-managed persistence. This
46  * case happens if the Bean Provider wants to allow the Deployer to select the
47  * primary key fields at deployment time. The Deployer uses instructions
48  * supplied by the Bean Provider (these instructions are beyond the scope of
49  * the EJB spec.) to define a suitable primary key class.
50  *
51  * In this special case, the type of the argument of the findByPrimaryKey method
52  * must be declared as java.lang.Object, and the return value of ejbCreate()
53  * must be declared as java.lang.Object. The Bean Provider must specify the
54  * primary key class in the deployment descriptor as of the type
55  * java.lang.Object.
56  *
57  * The primary key class is specified at deployment time when the Bean Provider
58  * develops enterprise beans that is intended to be used with multiple back-ends
59  * that provide persistence, and when these multiple back-ends require different
60  * primary key structures.
61  */

62 public class PrimaryKeyClassOptType extends EjbTest implements EjbCheck {
63
64
65     /**
66      * Entity bean's Primary Key Class type test.
67      * If the enterprise bean is a Entity Bean, the Bean provider specifies
68      * the fully qualified name of the Entity bean's primary key class in the
69      * "primary-class" element. The Bean provider 'must' specify the primary key
70      * class for an Entity with bean managed persistence, and 'may' (but is not
71      * required to) specify the primary key class for an Entity with
72      * Container-managed persistence.
73      *
74      * Special case: Unknown primary key class
75      * In special situations, the Bean Provider may choose not to specify the
76      * primary key class for an entity bean with container-managed persistence. This
77      * case happens if the Bean Provider wants to allow the Deployer to select the
78      * primary key fields at deployment time. The Deployer uses instructions
79      * supplied by the Bean Provider (these instructions are beyond the scope of
80      * the EJB spec.) to define a suitable primary key class.
81      *
82      * In this special case, the type of the argument of the findByPrimaryKey method
83      * must be declared as java.lang.Object, and the return value of ejbCreate()
84      * must be declared as java.lang.Object. The Bean Provider must specify the
85      * primary key class in the deployment descriptor as of the type
86      * java.lang.Object.
87      *
88      * The primary key class is specified at deployment time when the Bean Provider
89      * develops enterprise beans that is intended to be used with multiple back-ends
90      * that provide persistence, and when these multiple back-ends require different
91      * primary key structures.
92      *
93      * @param descriptor the Enterprise Java Bean deployment descriptor
94      *
95      * @return <code>Result</code> the results for this assertion
96      */

97     public Result check(EjbDescriptor descriptor) {
98
99     Result result = getInitializedResult();
100     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
101
102     if (descriptor instanceof EjbEntityDescriptor) {
103         String JavaDoc persistence =
104         ((EjbEntityDescriptor)descriptor).getPersistenceType();
105         if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
106         String JavaDoc primkey =
107             ((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName();
108
109         // primkey can be not set, via setting xml element
110
// <prim-key-class> to "java.lang.Object"
111
if (primkey.equals("java.lang.Object")) {
112             result.addGoodDetails(smh.getLocalString
113                        ("tests.componentNameConstructor",
114                     "For [ {0} ]",
115                     new Object JavaDoc[] {compName.toString()}));
116             result.passed(smh.getLocalString
117                   (getClass().getName() + ".passed",
118                    "Properly defined primary key class type [ {0} ]",
119                    new Object JavaDoc[] {"java.lang.Object"}));
120         } else {
121             result.addNaDetails(smh.getLocalString
122                        ("tests.componentNameConstructor",
123                     "For [ {0} ]",
124                     new Object JavaDoc[] {compName.toString()}));
125             result.notApplicable(smh.getLocalString
126                      (getClass().getName() + ".notApplicable1",
127                       "Primary Key Class is [ {0} ]",
128                       new Object JavaDoc[] {primkey}));
129         }
130
131         return result;
132
133         } else if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
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() + ".notApplicable2",
140                       "Entity Bean with [ {0} ] managed persistence, primkey mandatory.",
141                       new Object JavaDoc[] {persistence}));
142         return result;
143         }
144         else {
145         result.addNaDetails(smh.getLocalString
146                        ("tests.componentNameConstructor",
147                     "For [ {0} ]",
148                     new Object JavaDoc[] {compName.toString()}));
149         result.notApplicable(smh.getLocalString
150                      (getClass().getName() + ".notApplicable3",
151                       "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.",
152                       new Object JavaDoc[] {EjbEntityDescriptor.CONTAINER_PERSISTENCE,descriptor.getName(),persistence}));
153         return result;
154         }
155     } else {
156         result.addNaDetails(smh.getLocalString
157                        ("tests.componentNameConstructor",
158                     "For [ {0} ]",
159                     new Object JavaDoc[] {compName.toString()}));
160         result.notApplicable(smh.getLocalString
161                  (getClass().getName() + ".notApplicable",
162                   "[ {0} ] expected {1} bean, but called with {2} bean.",
163                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
164         return result;
165     }
166     }
167 }
168
Popular Tags