KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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