KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package com.sun.enterprise.tools.verifier.tests.ejb.entity;
25
26 import com.sun.enterprise.tools.verifier.Result;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
30 import com.sun.enterprise.deployment.EjbDescriptor;
31 import com.sun.enterprise.deployment.EjbEntityDescriptor;
32 import com.sun.enterprise.deployment.EjbCMPEntityDescriptor;
33
34 /**
35  * @author Sudipto Ghosh
36  *
37  */

38 public class AbstractSchemaNameIsValidJavaIdentifier extends EjbTest implements EjbCheck{
39     /**
40      * For an entity-bean the abstract-schema-name must be a valid Java identifier.
41      * See ejb specification 2.1 section 10.3.13
42      * @param descriptor the Enterprise Java Bean deployment descriptor
43      * @return <code>Result</code> the results for this assertion
44      */

45     public Result check(EjbDescriptor descriptor){
46         Result result = getInitializedResult();
47         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
48         String JavaDoc abstractSchema = null;
49
50         if(descriptor instanceof EjbEntityDescriptor) {
51             if (((EjbEntityDescriptor)descriptor).getPersistenceType().equals(EjbEntityDescriptor.CONTAINER_PERSISTENCE)) {
52                 if (((EjbCMPEntityDescriptor) descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_2_x) {
53                     abstractSchema = ((EjbCMPEntityDescriptor)descriptor).getAbstractSchemaName();
54                     if(abstractSchema!=null) {
55                         boolean isJavaIdentifier=true;
56                         boolean startChar=Character.isJavaIdentifierStart(abstractSchema.charAt(0));
57                         if (startChar) {
58                             for(int i=1;i<abstractSchema.length();i++)
59                                 if(!Character.isJavaIdentifierPart(abstractSchema.charAt(i))) {
60                                     isJavaIdentifier=false;
61                                     break;
62                                 }
63                         } else {
64                             isJavaIdentifier=false;
65                         }
66                         if(isJavaIdentifier) {
67                             result.addGoodDetails(smh.getLocalString
68                                     ("tests.componentNameConstructor",
69                                             "For [ {0} ]",
70                                             new Object JavaDoc[] {compName.toString()}));
71                             result.passed(smh.getLocalString
72                                     (getClass().getName() + ".passed",
73                                             "abstract-schema-name [ {0} ] within bean [ {1} ] is a valid java identifier",
74                                             new Object JavaDoc[] {abstractSchema, descriptor.getName()}));
75                         }else{
76                             result.addErrorDetails(smh.getLocalString
77                                     ("tests.componentNameConstructor",
78                                             "For [ {0} ]",
79                                             new Object JavaDoc[] {compName.toString()}));
80                             result.failed(smh.getLocalString
81                                     (getClass().getName() + ".failed",
82                                             "abstract-schema-name [ {0} ] within bean [ {1} ] is not a valid java identifier",
83                                             new Object JavaDoc[] {abstractSchema, descriptor.getName()}));
84                         }
85                     }
86                 }
87             }
88         }
89         if(abstractSchema==null){
90             result.addNaDetails(smh.getLocalString
91                     ("tests.componentNameConstructor",
92                             "For [ {0} ]",
93                             new Object JavaDoc[] {compName.toString()}));
94             result.notApplicable(smh.getLocalString
95                     (getClass().getName() + ".notApplicable",
96                             "abstract-schema-name is not defined or this is not applicable for this bean"));
97         }
98         return result;
99     }
100 }
101
Popular Tags