KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > api > EntityCmp1Desc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EntityCmp1Desc.java,v 1.9 2004/09/17 09:44:19 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.deployment.api;
27
28 import java.lang.reflect.Field JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
33 import org.objectweb.jonas_ejb.deployment.xml.Entity;
34 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
35 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
36 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
37
38 /**
39  * Class to hold meta-information related to an entity of type CMP version 1.x.
40  * Created on Jun 24, 2002
41  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
42  * @author Helene Joanin
43  */

44 public class EntityCmp1Desc extends EntityCmpDesc {
45
46     protected Method JavaDoc isModifiedMethod = null;
47
48     /**
49      * constructor to be used by parent node
50      */

51     public EntityCmp1Desc(ClassLoader JavaDoc classLoader, Entity ent,
52               AssemblyDescriptor asd, JonasEntity jEnt,
53               JLinkedList jMDRList, String JavaDoc fileName)
54     throws DeploymentDescException {
55     
56         super(classLoader, ent, asd, jEnt, jMDRList, fileName);
57
58         // check if persistent fields map to fields
59
for (Iterator JavaDoc i = fieldDesc.keySet().iterator();i.hasNext();) {
60             String JavaDoc fn = (String JavaDoc)i.next();
61             // check for valid field name
62
try {
63                 Field JavaDoc f = ejbClass.getField(fn);
64                 ((FieldDesc)(fieldDesc.get(fn))).setFieldType(f.getType());
65             } catch (NoSuchFieldException JavaDoc e) {
66                 throw new DeploymentDescException("Invalid field name "+fn+" in field-name in bean "+this.ejbName,e);
67             } catch (SecurityException JavaDoc e) {
68                 throw new DeploymentDescException("Cannot use java reflexion on "+this.ejbClass.getName());
69             }
70         }
71
72         // isModifiedMethod
73
if (jEnt.getIsModifiedMethodName() != null) {
74             String JavaDoc mName = jEnt.getIsModifiedMethodName();
75             try {
76                 isModifiedMethod = this.ejbClass.getMethod(mName, new Class JavaDoc[0]);
77             } catch (NoSuchMethodException JavaDoc e) {
78                 isModifiedMethod = null;
79                 throw new DeploymentDescException(mName + " is not a method of " + this.ejbClass.getName());
80             } catch (SecurityException JavaDoc e) {
81                 throw new DeploymentDescException("Cannot use java reflexion on " + this.ejbClass.getName());
82             }
83         }
84         if (isUndefinedPK()) {
85            FieldDesc fd = this.newFieldDescInstance();
86            fd.setName("JONASAUTOPKFIELD");
87            fd.setPrimaryKey(true);
88            fieldDesc.put("JONASAUTOPKFIELD", fd);
89            ((FieldDesc) (fieldDesc.get("JONASAUTOPKFIELD"))).setFieldType(java.lang.Integer JavaDoc.class);
90            ((FieldJdbcDesc) (fieldDesc.get("JONASAUTOPKFIELD"))).setJdbcFieldName(this.getJdbcAutomaticPkFieldName());
91         }
92     }
93
94     /**
95      * Get descriptor for a given field
96      * @param field of the bean class
97      * @return Descriptor for the given field
98      */

99     public FieldDesc getCmpFieldDesc(Field JavaDoc field) {
100         FieldDesc ret = (FieldDesc) fieldDesc.get(field.getName());
101         if (ret == null)
102             throw new Error JavaDoc("Field " + field.getName() + " is not a cmp field of class " + this.ejbClass.getName());
103         return ret;
104     }
105
106
107     /**
108      * Get the 'isModified' method name implemented in the bean class.
109      * (This information is JOnAS specific).
110      * @return Name of the isModified method
111      */

112     public Method JavaDoc getIsModifiedMethod(){
113         if (isModifiedMethod == null)
114             throw new Error JavaDoc("No isModified method defined for bean " + this.ejbName);
115         return isModifiedMethod;
116     }
117
118     /**
119      * Assessor for existence of a isModified methoe
120      * @return true of isModified method exist for the bean
121      */

122     public boolean hasIsModifiedMethod(){
123         return isModifiedMethod != null;
124     }
125
126     /**
127      * Assessor for a CMP field
128      * @param field for which a descriptor is to be returned
129      * @return Descriptor for the given field
130      */

131     public boolean hasCmpFieldDesc(Field JavaDoc field) {
132         return fieldDesc.containsKey(field.getName());
133     }
134
135     /**
136      * String representation of the object for test purpose
137      * @return String representation of this object
138      */

139     public String JavaDoc toString() {
140         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
141         ret.append(super.toString());
142         if (hasIsModifiedMethod())
143             ret.append("getIsModifiedMethod()=" + getIsModifiedMethod().toString());
144         return ret.toString();
145     }
146
147 }
148
Popular Tags