KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
27 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
31 import com.sun.enterprise.tools.verifier.*;
32 import java.lang.ClassLoader JavaDoc;
33 import com.sun.enterprise.tools.verifier.tests.*;
34
35 /**
36  * Define primary key class which must be legal Value Type in RMI-IIOP test.
37  *
38  * Enterprise Bean's primary key class
39  * The Bean provider must specify a primary key class in the deployment
40  * descriptor. The primary key class must be a legal Value Type in RMI-IIOP.
41  *
42  */

43 public class EjbPrimaryKeyClassRmiIIOP extends EjbTest implements EjbCheck {
44
45
46     /**
47      * Define primary key class which must be legal Value Type in RMI-IIOP test.
48      *
49      * Enterprise Bean's primary key class
50      * The Bean provider must specify a primary key class in the deployment
51      * descriptor. The primary key class must be a legal Value Type in RMI-IIOP.
52      *
53      * @param descriptor the Enterprise Java Bean deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(EjbDescriptor descriptor) {
58
59     Result result = getInitializedResult();
60     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
61
62     if (descriptor instanceof EjbEntityDescriptor) {
63         boolean isLegalRMIIIOPValueType = false;
64         boolean oneFailed = false;
65   
66         // retrieve the EJB primary key class
67
String JavaDoc primaryKeyType = ((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName();
68       
69         if (!primaryKeyType.equals("")) {
70         try {
71             Context context = getVerifierContext();
72             ClassLoader JavaDoc jcl = context.getClassLoader();
73             Class JavaDoc c = Class.forName(((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
74             if (RmiIIOPUtils.isValidRmiIIOPValueType(c)) {
75             // this is the right primary key class
76
isLegalRMIIIOPValueType = true;
77             } // return valid
78

79             if (isLegalRMIIIOPValueType) {
80             result.addGoodDetails(smh.getLocalString
81                           ("tests.componentNameConstructor",
82                            "For [ {0} ]",
83                            new Object JavaDoc[] {compName.toString()}));
84             result.addGoodDetails(smh.getLocalString
85                           (getClass().getName() + ".debug1",
86                            "For EJB primary key class [ {0} ]",
87                            new Object JavaDoc[] {primaryKeyType}));
88             result.addGoodDetails(smh.getLocalString
89                           (getClass().getName() + ".passed",
90                            "A primary key class which must be legal Value Type in RMI-IIOP was defined in the deployment descriptor."));
91             } else if (!isLegalRMIIIOPValueType) {
92             oneFailed = true;
93             result.addErrorDetails(smh.getLocalString
94                           ("tests.componentNameConstructor",
95                            "For [ {0} ]",
96                            new Object JavaDoc[] {compName.toString()}));
97             result.addErrorDetails(smh.getLocalString
98                            (getClass().getName() + ".debug1",
99                         "For EJB primary key class [ {0} ]",
100                         new Object JavaDoc[] {primaryKeyType}));
101             result.addErrorDetails(smh.getLocalString
102                            (getClass().getName() + ".failed",
103                         "Error: A primary key class which must be legal Value Type in RMI-IIOP was not defined in the deployment descriptor."));
104             }
105         } catch (ClassNotFoundException JavaDoc e) {
106             Verifier.debug(e);
107             result.addErrorDetails(smh.getLocalString
108                        ("tests.componentNameConstructor",
109                         "For [ {0} ]",
110                         new Object JavaDoc[] {compName.toString()}));
111             result.failed(smh.getLocalString
112                   (getClass().getName() + ".failedException",
113                    "Error: [ {0} ] class not found.",
114                    new Object JavaDoc[] {primaryKeyType}));
115             oneFailed = true;
116         }
117         } else {
118         oneFailed = true;
119         result.addErrorDetails(smh.getLocalString
120                           ("tests.componentNameConstructor",
121                            "For [ {0} ]",
122                            new Object JavaDoc[] {compName.toString()}));
123         result.addErrorDetails(smh.getLocalString
124                        (getClass().getName() + ".debug1",
125                     "For EJB primary key class [ {0} ]",
126                     new Object JavaDoc[] {primaryKeyType}));
127         result.addErrorDetails(smh.getLocalString
128                        (getClass().getName() + ".failed1",
129                     "Error: A primary key class was not defined in the deployment descriptor."));
130         }
131
132         if (oneFailed) {
133         result.setStatus(result.FAILED);
134         } else {
135         result.setStatus(result.PASSED);
136         }
137   
138         return result;
139
140     } else {
141         result.addNaDetails(smh.getLocalString
142                           ("tests.componentNameConstructor",
143                            "For [ {0} ]",
144                            new Object JavaDoc[] {compName.toString()}));
145         result.notApplicable(smh.getLocalString
146                  (getClass().getName() + ".notApplicable",
147                   "[ {0} ] expected {1} bean, but called with {2} bean.",
148                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
149         return result;
150     }
151     }
152 }
153
Popular Tags