KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import java.util.Iterator JavaDoc;
26
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30
31 /**
32  * The ejb-name must be unique amoung the names of the enterprise beans within
33  * the same ejb-jar file.
34  */

35 public class EjbNameUnique extends EjbTest implements EjbCheck {
36
37     /**
38      * The ejb-name must be unique amoung the names of the enterprise beans within
39      * the same ejb-jar file.
40      *
41      * @param descriptor the Enterprise Java Bean deployment descriptor
42      *
43      * @return <code>Result</code> the results for this assertion
44      */

45     public Result check(EjbDescriptor descriptor) {
46
47         Result result = getInitializedResult();
48         String JavaDoc ejbName = descriptor.getName();
49         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
50
51         // initialize needed by ejb loop
52
int found = 0;
53
54         // The ejb-name must be unique amoung the names of the enterprise beans
55
// within the same ejb-jar file.
56
// i.e. need to loop through all ejb's within this jar and get their
57
// respective ejbName's, then do a string compare and make sure their are
58
// no duplicates.
59
for (Iterator JavaDoc itr =descriptor.getEjbBundleDescriptor().getEjbs().iterator();
60              itr.hasNext();) {
61             EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
62             if (ejbDescriptor.getName().equals(ejbName)) {
63                 found++;
64                 if (found > 1) {
65                     addErrorDetails(result, compName);
66                     result.failed(smh.getLocalString
67                             (getClass().getName() + ".failed",
68                             "Error: [ {0} ] has found [ {1} ] duplicate ejb name(s) within the same jar.",
69                             new Object JavaDoc[] {ejbName, new Integer JavaDoc((found - 1))}));
70                 }
71             }
72         }
73         
74         if (result.getStatus() != Result.FAILED) {
75             addGoodDetails(result, compName);
76             result.passed(smh.getLocalString
77                     (getClass().getName() + ".passed",
78                     "Valid: [ {0} ] was found once within jar, ejb-name is unique.",
79                     new Object JavaDoc[] {ejbName}));
80         }
81         return result;
82     }
83 }
84
Popular Tags