KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.ClassLoader JavaDoc;
27 import com.sun.enterprise.tools.verifier.tests.*;
28 import java.lang.reflect.Field JavaDoc;
29 import java.util.*;
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 /**
35  * Any CMP entity bean should have at least one cmp field defined in the DDs
36  */

37 public class CMPFieldExistence extends EjbTest implements EjbCheck {
38
39
40     /**
41      * Any CMP entity bean should have at least one cmp field defined in the DDs
42      *
43      * @param descriptor the Enterprise Java Bean deployment descriptor
44      *
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(EjbDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50         if (descriptor instanceof EjbEntityDescriptor) {
51         String JavaDoc persistentType =
52         ((EjbEntityDescriptor)descriptor).getPersistenceType();
53         if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
54                 EjbCMPEntityDescriptor cmpDesc = (EjbCMPEntityDescriptor) descriptor;
55                 PersistenceDescriptor persDesc = cmpDesc.getPersistenceDescriptor();
56                 if (persDesc.getCMPFields().size()==0) {
57                     result.failed(smh.getLocalString
58                                            (getClass().getName()+"failed",
59                                             "For CMP entity bean [ {0} ], no cmp field are defined",
60                                             new Object JavaDoc[] {descriptor.getName()}));
61                 } else {
62                     result.passed(smh.getLocalString
63                                            (getClass().getName() + ".passed",
64                                             "For CMP entity bean [ {0} ], some cmp fields are defined",
65                                             new Object JavaDoc[] {descriptor.getName()}));
66                 }
67                 return result;
68             }
69         }
70         
71         // everything else is NA
72
result.notApplicable(smh.getLocalString
73                 (getClass().getName() + ".notApplicable",
74                  "The EJB [ {0} ] is not an CMP entity bean",
75                  new Object JavaDoc[] {descriptor.getName()}));
76          return result;
77     }
78 }
79
Popular Tags