KickJava   Java API By Example, From Geeks To Geeks.

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


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.tests.ejb.EjbTest;
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * The abstract schema name for every CMP bean within a jar file should be unique.
34  *
35  * @author Sheetal Vartak
36  *
37  */

38 public class UniqueAbstractSchemaName extends EjbTest implements EjbCheck {
39
40
41     /**
42      * The abstract schema name for every CMP bean within a jar file should be unique.
43      *
44      *
45      * @param descriptor the Enterprise Java Bean deployment descriptor
46      *
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(EjbDescriptor descriptor) {
50
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53     boolean oneFailed = false;
54     String JavaDoc abstractSchema = null;
55
56     if (descriptor instanceof EjbEntityDescriptor) {
57         if (((EjbEntityDescriptor)descriptor).getPersistenceType().equals(EjbEntityDescriptor.CONTAINER_PERSISTENCE)) {
58                 
59                 if (((EjbCMPEntityDescriptor) descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_2_x) {
60                     abstractSchema = ((EjbCMPEntityDescriptor)descriptor).getAbstractSchemaName();
61                     if (abstractSchema==null) {
62                         result.addErrorDetails(smh.getLocalString
63                        ("tests.componentNameConstructor",
64                         "For [ {0} ]",
65                         new Object JavaDoc[] {compName.toString()}));
66                         result.failed(smh.getLocalString
67                                         (getClass().getName() + ".failed2",
68                                         "No Abstract Schema Name specified for a CMP 2.0 Entity Bean {0} ",
69                                         new Object JavaDoc[] {descriptor.getName()}));
70                         return result;
71                     }
72                 }
73             }
74             if (abstractSchema ==null) {
75                 result.addNaDetails(smh.getLocalString
76                     ("tests.componentNameConstructor",
77                     "For [ {0} ]",
78                     new Object JavaDoc[] {compName.toString()}));
79                 result.notApplicable(smh.getLocalString
80                     (getClass().getName() + ".notApplicable",
81                     "This test is only for CMP 2.0 beans. Abstract Schema Names should be unique within an ejb JAR file."));
82                     return result;
83         }
84
85         EjbBundleDescriptor bundle = descriptor.getEjbBundleDescriptor();
86         Iterator iterator = (bundle.getEjbs()).iterator();
87         Vector<String JavaDoc> schemaNames = new Vector<String JavaDoc>();
88         while(iterator.hasNext()) {
89         EjbDescriptor entity = (EjbDescriptor) iterator.next();
90         if (entity instanceof EjbEntityDescriptor) {
91             if (!entity.equals(descriptor)) {
92             if (((EjbEntityDescriptor)entity).getPersistenceType().equals(EjbEntityDescriptor.CONTAINER_PERSISTENCE)) {
93                 schemaNames.addElement(((EjbCMPEntityDescriptor)entity).getAbstractSchemaName());
94             }
95             }
96         }
97         }
98
99         for (int i = 0; i < schemaNames.size(); i++) {
100         if (abstractSchema.equals(schemaNames.elementAt(i))) {
101             result.addErrorDetails(smh.getLocalString
102                        ("tests.componentNameConstructor",
103                         "For [ {0} ]",
104                         new Object JavaDoc[] {compName.toString()}));
105             result.addErrorDetails
106             (smh.getLocalString
107              (getClass().getName() + ".failed",
108               "Abstract Schema Names should be unique within an ejb JAR file. Abstract Schema Name [ {0} ] is not unique.",
109               new Object JavaDoc[] {abstractSchema}));
110             oneFailed = true;
111         }
112         }
113         if (oneFailed == false) {
114         result.addGoodDetails(smh.getLocalString
115                       ("tests.componentNameConstructor",
116                        "For [ {0} ]",
117                        new Object JavaDoc[] {compName.toString()}));
118         result.passed
119         (smh.getLocalString
120          (getClass().getName() + ".passed",
121           "PASSED : Abstract Schema Names for all beans within the ejb JAR file are unique."));
122         }
123         else result.setStatus(Result.FAILED);
124         
125     } else {
126         addNaDetails(result, compName);
127         result.notApplicable(smh.getLocalString
128             (getClass().getName() + ".notApplicable",
129             "This test is only for CMP 2.0 beans. Abstract Schema Names should be unique within an ejb JAR file."));
130     }
131     return result;
132     }
133 }
134
Popular Tags