001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: EntityCmp1Desc.java 8397 2006-05-29 14:35:38Z durieuxp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.deployment.api;
025:
026: import java.lang.reflect.Field;
027: import java.lang.reflect.Method;
028: import java.util.Iterator;
029:
030: import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
031: import org.objectweb.jonas_ejb.deployment.xml.Entity;
032: import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
033: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
034: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
035:
036: /**
037: * Class to hold meta-information related to an entity of type CMP version 1.x.
038: * Created on Jun 24, 2002
039: * @author Christophe Ney [cney@batisseurs.com] : Initial developer
040: * @author Helene Joanin
041: */
042: public class EntityCmp1Desc extends EntityCmpDesc {
043:
044: protected Method isModifiedMethod = null;
045:
046: /**
047: * constructor to be used by parent node
048: */
049: public EntityCmp1Desc(ClassLoader classLoader, Entity ent,
050: AssemblyDescriptor asd, JonasEntity jEnt,
051: JLinkedList jMDRList, String fileName)
052: throws DeploymentDescException {
053:
054: super (classLoader, ent, asd, jEnt, jMDRList, fileName);
055:
056: // check if persistent fields map to fields
057: for (Iterator i = fieldDesc.keySet().iterator(); i.hasNext();) {
058: String fn = (String) i.next();
059: // check for valid field name
060: try {
061: Field f = ejbClass.getField(fn);
062: ((FieldDesc) (fieldDesc.get(fn))).setFieldType(f
063: .getType());
064: } catch (NoSuchFieldException e) {
065: throw new DeploymentDescException(
066: "Invalid field name " + fn
067: + " in field-name in bean "
068: + this .ejbName, e);
069: } catch (SecurityException e) {
070: throw new DeploymentDescException(
071: "Cannot use java reflexion on "
072: + this .ejbClass.getName());
073: }
074: }
075:
076: // isModifiedMethod
077: if (jEnt.getIsModifiedMethodName() != null) {
078: String mName = jEnt.getIsModifiedMethodName();
079: try {
080: isModifiedMethod = this .ejbClass.getMethod(mName,
081: new Class[0]);
082: } catch (NoSuchMethodException e) {
083: isModifiedMethod = null;
084: throw new DeploymentDescException(mName
085: + " is not a method of "
086: + this .ejbClass.getName());
087: } catch (SecurityException e) {
088: throw new DeploymentDescException(
089: "Cannot use java reflexion on "
090: + this .ejbClass.getName());
091: }
092: }
093: if (isUndefinedPK()) {
094: FieldDesc fd = this .newFieldDescInstance();
095: fd.setName("JONASAUTOPKFIELD");
096: fd.setPrimaryKey(true);
097: fieldDesc.put("JONASAUTOPKFIELD", fd);
098: ((FieldDesc) (fieldDesc.get("JONASAUTOPKFIELD")))
099: .setFieldType(java.lang.Integer.class);
100: ((FieldJdbcDesc) (fieldDesc.get("JONASAUTOPKFIELD")))
101: .setJdbcFieldName(this
102: .getJdbcAutomaticPkFieldName());
103: }
104: }
105:
106: /**
107: * Get descriptor for a given field
108: * @param field of the bean class
109: * @return Descriptor for the given field
110: */
111: public FieldDesc getCmpFieldDesc(Field field) {
112: FieldDesc ret = (FieldDesc) fieldDesc.get(field.getName());
113: if (ret == null)
114: throw new Error("Field " + field.getName()
115: + " is not a cmp field of class "
116: + this .ejbClass.getName());
117: return ret;
118: }
119:
120: /**
121: * Get the 'isModified' method name implemented in the bean class.
122: * (This information is JOnAS specific).
123: * @return Name of the isModified method
124: */
125: public Method getIsModifiedMethod() {
126: if (isModifiedMethod == null)
127: throw new Error("No isModified method defined for bean "
128: + this .ejbName);
129: return isModifiedMethod;
130: }
131:
132: /**
133: * Assessor for existence of a isModified method
134: * @return true of isModified method exist for the bean
135: */
136: public boolean hasIsModifiedMethod() {
137: return isModifiedMethod != null;
138: }
139:
140: /**
141: * Assessor for a CMP field
142: * @param field for which a descriptor is to be returned
143: * @return Descriptor for the given field
144: */
145: public boolean hasCmpFieldDesc(Field field) {
146: return fieldDesc.containsKey(field.getName());
147: }
148:
149: /**
150: * String representation of the object for test purpose
151: * @return String representation of this object
152: */
153: public String toString() {
154: StringBuffer ret = new StringBuffer();
155: ret.append(super .toString());
156: if (hasIsModifiedMethod())
157: ret.append("getIsModifiedMethod()="
158: + getIsModifiedMethod().toString());
159: return ret.toString();
160: }
161:
162: }
|