User: starksm
Date: 01/11/20 01:42:51
Modified: src/main/org/jboss/ejb/plugins/jaws/metadata Tag: Branch_2_4
CMPFieldMetaData.java JawsApplicationMetaData.java
JawsXmlFileLoader.java MappingMetaData.java
Log:
Change to the unified log4j based org.jboss.logging.Logger class.
Revision Changes Path
No revision
No revision
1.6.4.2 +450 -374
jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/CMPFieldMetaData.java
Index: CMPFieldMetaData.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/CMPFieldMetaData.java,v
retrieving revision 1.6.4.1
retrieving revision 1.6.4.2
diff -u -r1.6.4.1 -r1.6.4.2
--- CMPFieldMetaData.java 2001/11/02 08:42:34 1.6.4.1
+++ CMPFieldMetaData.java 2001/11/20 09:42:51 1.6.4.2
@@ -19,7 +19,6 @@
import org.jboss.metadata.MetaData;
import org.jboss.metadata.EjbRefMetaData;
-import org.jboss.logging.Log;
import org.jboss.logging.Logger;
/**
@@ -30,411 +29,488 @@
* @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Dirk Zimmermann</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Harcq</a>
- * @version $Revision: 1.6.4.1 $
+ * @version $Revision: 1.6.4.2 $
*/
-public class CMPFieldMetaData extends MetaData implements XmlLoadable {
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // the entity this field belongs to
- private JawsEntityMetaData jawsEntity;
-
- // name of the field
- private String name;
-
- // the actual Field in the bean implementation
- private Field field;
-
- // the jdbc type (see java.sql.Types), used in PreparedStatement.setParameter
- private int jdbcType;
- // true if jdbcType has been initialized
- private boolean validJdbcType;
-
- // the sql type, used for table creation.
- private String sqlType;
-
- // the column name in the table
- private String columnName;
-
- private boolean isAPrimaryKeyField;
-
-
- /**
- * We need this for nested field retrieval.
- */
- private String ejbClassName;
-
- /**
- * We need this for nested fields. We could compute it from ejbClassName on
the fly,
- * but it's faster to set it once and cache it.
- */
- private Class ejbClass;
-
- /**
- * Is true for fields like "data.categoryPK".
- */
- private boolean isNested;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
- public CMPFieldMetaData(String name, JawsEntityMetaData jawsEntity) throws
DeploymentException {
- this.name = name;
- this.jawsEntity = jawsEntity;
-
- // save the class name for nested fields
- ejbClassName = jawsEntity.getEntity().getEjbClass();
- ejbClassName = jawsEntity.getEntity().getEjbClass();
-
- try {
- // save the class for nested fields
- ejbClass =
jawsEntity.getJawsApplication().getClassLoader().loadClass(ejbClassName);
- field = ejbClass.getField(name);
- } catch (ClassNotFoundException e) {
- throw new DeploymentException("ejb class not found: " +
ejbClassName);
- } catch (NoSuchFieldException e) {
- // we can't throw an Exception here, because we could have a
nested field
- checkField();
- }
-
- // default, may be overridden by importXml
- columnName = getLastComponent(name);
-
- // cannot set defaults for jdbctype/sqltype, type mappings are not
loaded yet.
- }
-
-
- // Public --------------------------------------------------------
- public String getName() { return name; }
-
- public Field getField() { return field; }
-
- public int getJDBCType() {
- if (! validJdbcType) {
- // set the default
- if (field!=null)
- jdbcType =
jawsEntity.getJawsApplication().getTypeMapping().getJdbcTypeForJavaType(field.getType());
- else{
- try{
- jdbcType =
jawsEntity.getJawsApplication().getTypeMapping().getJdbcTypeForJavaType(ValueObjectHelper.getNestedFieldType(ejbClass,name));
- } catch(NoSuchMethodException e){
- Log.getLog().warning("ERROR : Nested Field does not have a get
method");
- }
- }
- validJdbcType = true;
- }
- return jdbcType;
- }
-
- public String getSQLType() {
- if (sqlType == null) {
- // set the default
- if (field!=null)
- sqlType =
jawsEntity.getJawsApplication().getTypeMapping().getSqlTypeForJavaType(field.getType());
- else{
- try{
- sqlType =
jawsEntity.getJawsApplication().getTypeMapping().getSqlTypeForJavaType(ValueObjectHelper.getNestedFieldType(ejbClass,name));
- } catch(NoSuchMethodException e){
- Log.getLog().warning("ERROR : Nested Field does not have a get
method");
- }
- }
- }
- return sqlType;
- }
-
- public String getColumnName() { return columnName; }
-
- public boolean isEJBReference() { return jdbcType == Types.REF; }
-
- public boolean isAPrimaryKeyField() { return isAPrimaryKeyField; }
-
- public JawsEntityMetaData getJawsEntity() { return jawsEntity; }
-
- /**
- * Returns the last component of a composite fieldName. E.g., for
"data.categoryPK" it
- * will return "categoryPK".
- */
- public static String getLastComponent(String name) {
- String fieldName = name;
- StringTokenizer st = new StringTokenizer(name, ".");
- while(st.hasMoreTokens()) {
- fieldName = st.nextToken();
- }
- return fieldName;
- }
-
- /**
- * Returns the first component of a composite fieldName. E.g., for
"data.categoryPK" it
- * will return "data".
- */
- public static String getFirstComponent(String name) {
- String fieldName;
- StringTokenizer st = new StringTokenizer(name, ".");
- if (st.hasMoreTokens()) {
- fieldName = st.nextToken();
- }
- else {
- fieldName = null;
- }
- return fieldName;
- }
-
- /**
- * Detects the actual field of a nested field and sets field accordingly.
- * If field doesn't exist, throws a DeploymentException.
- */
- private void checkField() throws DeploymentException {
- try {
- field = verifyNestedField();
- }
- catch(DeploymentException e) {
- // try it again, but debug Class before :))
- debugClass(ejbClass);
- field = verifyNestedField();
- Log.getLog().warning("!!! using buggy hotspot, try to upgrade
... !!!");
- }
- }
-
- /**
- * Traverses and verifies a nested field, so that every field given in jaws.xml
- * exists in the Bean.
- */
- private Field verifyNestedField() throws DeploymentException {
- String fieldName = null;
- Field tmpField = null;
- Class tmpClass = ejbClass;
- StringTokenizer st = new StringTokenizer(name, ".");
-
- if (st.countTokens() > 1) {
- isNested = true;
- }
-
- while(st.hasMoreTokens()) {
- fieldName = st.nextToken();
- try {
- //debugClass(tmpClass);
- tmpField = tmpClass.getField(fieldName);
- tmpClass = tmpField.getType();
- Log.getLog().debug("(Dependant Object) "+tmpField.getName());
- }
- catch (NoSuchFieldException e) {
- // we can have a private attribute, then we will use fieldName
- // to find the get/set methods, but still have to set
jdbcType/SQLType
- // but can not yet do it sowe have to set field to null so that
- // getJDBCType will not use the parent Field to find the types
- field = null;
- return null;
- }
- }
- return tmpField;
- }
-
- /**
- * We don't rely on the field alone for getting the type since we support
nested field
- * like 'data.categoryPK'.
- */
- public Class getFieldType() {
- if (field != null) {
- // The default case as it always was :)
- return field.getType();
- }
-
- // We obviously have a nested field (or an erroneous one)
- Field tmpField = null;
- Class tmpClass = ejbClass;
- String fieldName = null;
- StringTokenizer st = new StringTokenizer(name, ".");
- while(st.hasMoreTokens()) {
- fieldName = st.nextToken();
- try {
- tmpField = tmpClass.getField(fieldName);
- tmpClass = tmpField.getType();
- }
- catch (NoSuchFieldException e) {
- // We have a nested Field
- try{
- return ValueObjectHelper.getNestedFieldType(ejbClass,name);
- }
- catch (NoSuchMethodException ne){
- Log.getLog().warning("Nested field "+fieldName+" does not have
a get method on "+ejbClass.getName());
- return null;
- }
- }
- }
- return tmpField.getType();
- }
-
- /**
- * Is used mainly for nested fields. Sets the value of a nested field.
- */
- public void set(Object instance, Object value) {
- Field tmpField = null;
- String fieldName = null;
- Object currentObject = instance;
- Object oldObject;
- StringTokenizer st = new StringTokenizer(name, ".");
- //Log.getLog().debug("set on cmp-field "+name+"="+value);
+public class CMPFieldMetaData extends MetaData implements XmlLoadable
+{
+ // Constants -----------------------------------------------------
+ static Logger log = Logger.getLogger(CMPFieldMetaData.class);
+ // Attributes ----------------------------------------------------
+
+ // the entity this field belongs to
+ private JawsEntityMetaData jawsEntity;
+
+ // name of the field
+ private String name;
+
+ // the actual Field in the bean implementation
+ private Field field;
+
+ // the jdbc type (see java.sql.Types), used in PreparedStatement.setParameter
+ private int jdbcType;
+ // true if jdbcType has been initialized
+ private boolean validJdbcType;
+
+ // the sql type, used for table creation.
+ private String sqlType;
+
+ // the column name in the table
+ private String columnName;
+
+ private boolean isAPrimaryKeyField;
+
+
+ /**
+ * We need this for nested field retrieval.
+ */
+ private String ejbClassName;
+
+ /**
+ * We need this for nested fields. We could compute it from ejbClassName on the
fly,
+ * but it's faster to set it once and cache it.
+ */
+ private Class ejbClass;
+
+ /**
+ * Is true for fields like "data.categoryPK".
+ */
+ private boolean isNested;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+ public CMPFieldMetaData(String name, JawsEntityMetaData jawsEntity) throws
DeploymentException
+ {
+ this.name = name;
+ this.jawsEntity = jawsEntity;
+
+ // save the class name for nested fields
+ ejbClassName = jawsEntity.getEntity().getEjbClass();
+ ejbClassName = jawsEntity.getEntity().getEjbClass();
+
+ try
+ {
+ // save the class for nested fields
+ ejbClass =
jawsEntity.getJawsApplication().getClassLoader().loadClass(ejbClassName);
+ field = ejbClass.getField(name);
+ } catch (ClassNotFoundException e)
+ {
+ throw new DeploymentException("ejb class not found: " + ejbClassName);
+ } catch (NoSuchFieldException e)
+ {
+ // we can't throw an Exception here, because we could have a nested field
+ checkField();
+ }
+
+ // default, may be overridden by importXml
+ columnName = getLastComponent(name);
+
+ // cannot set defaults for jdbctype/sqltype, type mappings are not loaded yet.
+ }
+
+
+ // Public --------------------------------------------------------
+ public String getName()
+ { return name; }
+
+ public Field getField()
+ { return field; }
+
+ public int getJDBCType()
+ {
+ if (! validJdbcType)
+ {
+ // set the default
+ if (field!=null)
+ jdbcType =
jawsEntity.getJawsApplication().getTypeMapping().getJdbcTypeForJavaType(field.getType());
+ else
+ {
+ try
+ {
+ jdbcType =
jawsEntity.getJawsApplication().getTypeMapping().getJdbcTypeForJavaType(ValueObjectHelper.getNestedFieldType(ejbClass,name));
+ } catch(NoSuchMethodException e)
+ {
+ log.warn("ERROR : Nested Field does not have a get method");
+ }
+ }
+ validJdbcType = true;
+ }
+ return jdbcType;
+ }
+
+ public String getSQLType()
+ {
+ if (sqlType == null)
+ {
+ // set the default
+ if (field!=null)
+ sqlType =
jawsEntity.getJawsApplication().getTypeMapping().getSqlTypeForJavaType(field.getType());
+ else
+ {
+ try
+ {
+ sqlType =
jawsEntity.getJawsApplication().getTypeMapping().getSqlTypeForJavaType(ValueObjectHelper.getNestedFieldType(ejbClass,name));
+ } catch(NoSuchMethodException e)
+ {
+ log.warn("ERROR : Nested Field does not have a get method");
+ }
+ }
+ }
+ return sqlType;
+ }
+
+ public String getColumnName()
+ { return columnName; }
+
+ public boolean isEJBReference()
+ { return jdbcType == Types.REF; }
+
+ public boolean isAPrimaryKeyField()
+ { return isAPrimaryKeyField; }
+
+ public JawsEntityMetaData getJawsEntity()
+ { return jawsEntity; }
+
+ /**
+ * Returns the last component of a composite fieldName. E.g., for
"data.categoryPK" it
+ * will return "categoryPK".
+ */
+ public static String getLastComponent(String name)
+ {
+ String fieldName = name;
+ StringTokenizer st = new StringTokenizer(name, ".");
+ while(st.hasMoreTokens())
+ {
+ fieldName = st.nextToken();
+ }
+ return fieldName;
+ }
+
+ /**
+ * Returns the first component of a composite fieldName. E.g., for
"data.categoryPK" it
+ * will return "data".
+ */
+ public static String getFirstComponent(String name)
+ {
+ String fieldName;
+ StringTokenizer st = new StringTokenizer(name, ".");
+ if (st.hasMoreTokens())
+ {
+ fieldName = st.nextToken();
+ }
+ else
+ {
+ fieldName = null;
+ }
+ return fieldName;
+ }
+
+ /**
+ * Detects the actual field of a nested field and sets field accordingly.
+ * If field doesn't exist, throws a DeploymentException.
+ */
+ private void checkField() throws DeploymentException
+ {
+ try
+ {
+ field = verifyNestedField();
+ }
+ catch(DeploymentException e)
+ {
+ // try it again, but debug Class before :))
+ debugClass(ejbClass);
+ field = verifyNestedField();
+ log.warn("!!! using buggy hotspot, try to upgrade ... !!!");
+ }
+ }
+
+ /**
+ * Traverses and verifies a nested field, so that every field given in jaws.xml
+ * exists in the Bean.
+ */
+ private Field verifyNestedField() throws DeploymentException
+ {
+ String fieldName = null;
+ Field tmpField = null;
+ Class tmpClass = ejbClass;
+ StringTokenizer st = new StringTokenizer(name, ".");
+
+ if (st.countTokens() > 1)
+ {
+ isNested = true;
+ }
+
+ while(st.hasMoreTokens())
+ {
+ fieldName = st.nextToken();
+ try
+ {
+ //debugClass(tmpClass);
+ tmpField = tmpClass.getField(fieldName);
+ tmpClass = tmpField.getType();
+ log.debug("(Dependant Object) "+tmpField.getName());
+ }
+ catch (NoSuchFieldException e)
+ {
+ // we can have a private attribute, then we will use fieldName
+ // to find the get/set methods, but still have to set jdbcType/SQLType
+ // but can not yet do it sowe have to set field to null so that
+ // getJDBCType will not use the parent Field to find the types
+ field = null;
+ return null;
+ }
+ }
+ return tmpField;
+ }
+
+ /**
+ * We don't rely on the field alone for getting the type since we support nested
field
+ * like 'data.categoryPK'.
+ */
+ public Class getFieldType()
+ {
+ if (field != null)
+ {
+ // The default case as it always was :)
+ return field.getType();
+ }
+
+ // We obviously have a nested field (or an erroneous one)
+ Field tmpField = null;
+ Class tmpClass = ejbClass;
+ String fieldName = null;
+ StringTokenizer st = new StringTokenizer(name, ".");
+ while(st.hasMoreTokens())
+ {
+ fieldName = st.nextToken();
+ try
+ {
+ tmpField = tmpClass.getField(fieldName);
+ tmpClass = tmpField.getType();
+ }
+ catch (NoSuchFieldException e)
+ {
+ // We have a nested Field
+ try
+ {
+ return ValueObjectHelper.getNestedFieldType(ejbClass,name);
+ }
+ catch (NoSuchMethodException ne)
+ {
+ log.warn("Nested field "+fieldName+" does not have a get method on
"+ejbClass.getName());
+ return null;
+ }
+ }
+ }
+ return tmpField.getType();
+ }
+
+ /**
+ * Is used mainly for nested fields. Sets the value of a nested field.
+ */
+ public void set(Object instance, Object value)
+ {
+ Field tmpField = null;
+ String fieldName = null;
+ Object currentObject = instance;
+ Object oldObject;
+ StringTokenizer st = new StringTokenizer(name, ".");
+ //log.debug("set on cmp-field "+name+"="+value);
// First we instanciate nested objects if they do not already exist
int i=1;
int tot=st.countTokens();
- while (st.hasMoreTokens() && (i < tot) ){
+ while (st.hasMoreTokens() && (i < tot) )
+ {
i++;
fieldName = st.nextToken();
- //Log.getLog().debug("initialize "+fieldName+ " on
"+currentObject.getClass());
+ //log.debug("initialize "+fieldName+ " on "+currentObject.getClass());
oldObject = currentObject;
- try{
+ try
+ {
tmpField = currentObject.getClass().getField(fieldName);
currentObject = tmpField.get(currentObject);
// On our path, we have to instantiate every intermediate object
- if (currentObject == null) {
+ if (currentObject == null)
+ {
currentObject = tmpField.getType().newInstance();
tmpField.set(oldObject, currentObject);
}
}
- catch (NoSuchFieldException ne){
- try{
+ catch (NoSuchFieldException ne)
+ {
+ try
+ {
currentObject = ValueObjectHelper.getValue(currentObject,fieldName);
- if (currentObject == null) {
+ if (currentObject == null)
+ {
currentObject =
ValueObjectHelper.getNestedFieldType(oldObject.getClass(),fieldName).newInstance();
ValueObjectHelper.setValue(oldObject,fieldName,currentObject);
}
}
- catch (NoSuchMethodException e){
- Log.getLog().warning("set method not found for " + fieldName + " on
" + oldObject.getClass().getName());
+ catch (NoSuchMethodException e)
+ {
+ log.warn("set method not found for " + fieldName + " on " +
oldObject.getClass().getName());
}
- catch (InvocationTargetException e) {
- Log.getLog().warning("set method not invocable " + fieldName + " on
" + currentObject.getClass().getName());
+ catch (InvocationTargetException e)
+ {
+ log.warn("set method not invocable " + fieldName + " on " +
currentObject.getClass().getName());
}
- catch (IllegalAccessException e) {
- Log.getLog().warning("!!! Deployment Failure !!!" + e);
+ catch (IllegalAccessException e)
+ {
+ log.warn("!!! Deployment Failure !!!" + e);
}
- catch (InstantiationException e) {
- Log.getLog().warning("could not instantiate " + tmpField);
+ catch (InstantiationException e)
+ {
+ log.warn("could not instantiate " + tmpField);
}
}
- catch (IllegalAccessException e) {
- Log.getLog().warning("!!! Deployment Failure !!!" + e);
+ catch (IllegalAccessException e)
+ {
+ log.warn("!!! Deployment Failure !!!" + e);
}
- catch (InstantiationException e) {
- Log.getLog().warning("could not instantiate " + tmpField);
+ catch (InstantiationException e)
+ {
+ log.warn("could not instantiate " + tmpField);
}
- catch (Exception e) {
- Log.getLog().warning("Exception " + e);
+ catch (Exception e)
+ {
+ log.warn("Exception " + e);
}
}
- //Log.getLog().debug("initialization of nested objects done for "+name);
+ //log.debug("initialization of nested objects done for "+name);
// Now we set the value of the last component into the created object
- try{
- try{
+ try
+ {
+ try
+ {
Field dataField =
currentObject.getClass().getField(getLastComponent(name));
dataField.set(currentObject, value);
}
- catch (NoSuchFieldException nse){
- //Log.getLog().debug("set on "+getLastComponent(name)+ " on
"+currentObject.getClass()+ "="+value);
+ catch (NoSuchFieldException nse)
+ {
+ //log.debug("set on "+getLastComponent(name)+ " on
"+currentObject.getClass()+ "="+value);
ValueObjectHelper.setValue(currentObject,getLastComponent(name),value);
}
- }
- catch (IllegalAccessException e) {
- Log.getLog().warning("!!! Deployment Failure !!!" + e);
- }
- catch (InvocationTargetException e) {
- Log.getLog().warning("set method not invocable " +
getLastComponent(name) + " on " + currentObject.getClass().getName());
- }
- catch (NoSuchMethodException e) {
- Log.getLog().warning("set method not found for " +
getLastComponent(name) + " on " + currentObject.getClass().getName());
- }
- }
-
- /**
- * Returns the value of this field.
- */
- public Object getValue(Object instance) {
- String fieldName;
- Object currentObject = instance;
- Field currentField;
- //Object currentValue = null;
-
- try {
- if (!isNested()) {
- return getField().get(instance);
- }
- else {
- StringTokenizer st = new StringTokenizer(name, ".");
- while(st.hasMoreTokens()) {
- fieldName = st.nextToken();
- if (currentObject == null) return null;
- try{
- currentField =
currentObject.getClass().getField(fieldName);
- currentObject =
currentField.get(currentObject);
- }
- catch(NoSuchFieldException e){
- currentField = null;
- currentObject =
ValueObjectHelper.getValue(currentObject,fieldName);
- }
- }
- return currentObject;
- }
- }
- catch (IllegalAccessException e) {
- // We have already checked the presence of this field in the
constructor,
- // so there is no need to throw an exception here.
- Log.getLog().warning("!!! CMPFieldMetaData.getValue() ERROR
!!! " + e);
- }
- catch (InvocationTargetException e){
- Log.getLog().warning("!!! CMPFieldMetaData.getValue() ERROR
!!! " + e);
- }
- catch (NoSuchMethodException e) {
- Log.getLog().warning("!!! CMPFieldMetaData.getValue() ERROR
!!! " + e);
- }
- return null;
- }
-
- public boolean isNested() {
- return isNested;
- }
-
- // XmlLoadable implementation ------------------------------------
- public void importXml(Element element) throws DeploymentException {
-
- // column name
- String columnStr = getElementContent(getOptionalChild(element,
"column-name"));
- // For Netsted Properties, we will have a column name blank which means
- // the CMPField need to be removed. It will be reconstrcut and decompose
- // by Jaws when needed
- if (columnStr != null) columnName = columnStr;
-
- // jdbc type
- String jdbcStr = getElementContent(getOptionalChild(element,
"jdbc-type"));
-
- if (jdbcStr != null) {
- jdbcType = MappingMetaData.getJdbcTypeFromName(jdbcStr);
- validJdbcType = true;
-
- sqlType = getElementContent(getUniqueChild(element,
"sql-type"));
- }
-
- }
-
-
- // Package protected ---------------------------------------------
- void setPrimary() {
- isAPrimaryKeyField = true;
- }
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- /**
- * Workaround for certain Hotspot problems. Just traverse all the fields
- * in the Class, so Hotspot won't optimize to bad ...
- */
- private void debugClass(Class debugClass) {
- Field[] fields = debugClass.getFields();
- for (int i = 0; i < fields.length; ++i) {
- }
- }
-
- // Inner classes -------------------------------------------------
+ }
+ catch (IllegalAccessException e)
+ {
+ log.warn("!!! Deployment Failure !!!" + e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.warn("set method not invocable " + getLastComponent(name) + " on " +
currentObject.getClass().getName());
+ }
+ catch (NoSuchMethodException e)
+ {
+ log.warn("set method not found for " + getLastComponent(name) + " on " +
currentObject.getClass().getName());
+ }
+ }
+
+ /**
+ * Returns the value of this field.
+ */
+ public Object getValue(Object instance)
+ {
+ String fieldName;
+ Object currentObject = instance;
+ Field currentField;
+ //Object currentValue = null;
+
+ try
+ {
+ if (!isNested())
+ {
+ return getField().get(instance);
+ }
+ else
+ {
+ StringTokenizer st = new StringTokenizer(name, ".");
+ while(st.hasMoreTokens())
+ {
+ fieldName = st.nextToken();
+ if (currentObject == null) return null;
+ try
+ {
+ currentField = currentObject.getClass().getField(fieldName);
+ currentObject = currentField.get(currentObject);
+ }
+ catch(NoSuchFieldException e)
+ {
+ currentField = null;
+ currentObject =
ValueObjectHelper.getValue(currentObject,fieldName);
+ }
+ }
+ return currentObject;
+ }
+ }
+ catch (IllegalAccessException e)
+ {
+ // We have already checked the presence of this field in the constructor,
+ // so there is no need to throw an exception here.
+ log.warn("!!! CMPFieldMetaData.getValue() ERROR !!! " + e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.warn("!!! CMPFieldMetaData.getValue() ERROR !!! " + e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ log.warn("!!! CMPFieldMetaData.getValue() ERROR !!! " + e);
+ }
+ return null;
+ }
+
+ public boolean isNested()
+ {
+ return isNested;
+ }
+
+ // XmlLoadable implementation ------------------------------------
+ public void importXml(Element element) throws DeploymentException
+ {
+
+ // column name
+ String columnStr = getElementContent(getOptionalChild(element,
"column-name"));
+ // For Netsted Properties, we will have a column name blank which means
+ // the CMPField need to be removed. It will be reconstrcut and decompose
+ // by Jaws when needed
+ if (columnStr != null) columnName = columnStr;
+
+ // jdbc type
+ String jdbcStr = getElementContent(getOptionalChild(element, "jdbc-type"));
+
+ if (jdbcStr != null)
+ {
+ jdbcType = MappingMetaData.getJdbcTypeFromName(jdbcStr);
+ validJdbcType = true;
+
+ sqlType = getElementContent(getUniqueChild(element, "sql-type"));
+ }
+
+ }
+
+
+ // Package protected ---------------------------------------------
+ void setPrimary()
+ {
+ isAPrimaryKeyField = true;
+ }
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ /**
+ * Workaround for certain Hotspot problems. Just traverse all the fields
+ * in the Class, so Hotspot won't optimize to bad ...
+ */
+ private void debugClass(Class debugClass)
+ {
+ Field[] fields = debugClass.getFields();
+ for (int i = 0; i < fields.length; ++i)
+ {
+ }
+ }
+
+ // Inner classes -------------------------------------------------
}
1.5.6.5 +221 -185
jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsApplicationMetaData.java
Index: JawsApplicationMetaData.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsApplicationMetaData.java,v
retrieving revision 1.5.6.4
retrieving revision 1.5.6.5
diff -u -r1.5.6.4 -r1.5.6.5
--- JawsApplicationMetaData.java 2001/11/05 22:50:28 1.5.6.4
+++ JawsApplicationMetaData.java 2001/11/20 09:42:51 1.5.6.5
@@ -27,214 +27,250 @@
/**
- * <description>
- *
+ * <description>
+ *
* @see <related>
* @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.5.6.4 $
+ * @version $Revision: 1.5.6.5 $
*/
-public class JawsApplicationMetaData extends MetaData implements XmlLoadable {
- // Constants -----------------------------------------------------
- public static final String JPM =
"org.jboss.ejb.plugins.jaws.JAWSPersistenceManager";
-
- // Attributes ----------------------------------------------------
-
- // the classloader comes from the container. It is used to load the classes of
the beans
- // and their primary keys
- private ClassLoader classLoader;
+public class JawsApplicationMetaData extends MetaData implements XmlLoadable
+{
+ // Constants -----------------------------------------------------
+ public static final String JPM =
"org.jboss.ejb.plugins.jaws.JAWSPersistenceManager";
+ static Logger log = Logger.getLogger(JawsApplicationMetaData.class);
- // the "parent" applicationmetadata
- private ApplicationMetaData applicationMetaData;
-
- // this only contains the jaws-managed cmp entities
- private Hashtable entities = new Hashtable();
-
- // the datasource to use for this application
- private String dbURL;
- private DataSource dataSource;
+ // Attributes ----------------------------------------------------
+
+ // the classloader comes from the container. It is used to load the classes of
the beans
+ // and their primary keys
+ private ClassLoader classLoader;
+
+ // the "parent" applicationmetadata
+ private ApplicationMetaData applicationMetaData;
+
+ // this only contains the jaws-managed cmp entities
+ private Hashtable entities = new Hashtable();
+
+ // the datasource to use for this application
+ private String dbURL;
+ private DataSource dataSource;
private boolean debug = false;
-
- // all the available type mappings
- private Hashtable typeMappings = new Hashtable();
-
- // the type mapping to use with the specified database
- private TypeMappingMetaData typeMapping;
-
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
- public JawsApplicationMetaData(ApplicationMetaData amd, ClassLoader cl) throws
DeploymentException {
- // initialisation of this object goes as follows:
- // - constructor
- // - importXml() for standardjaws.xml and jaws.xml
- // - init()
-
- // the classloader is the same for all the beans in the application
- classLoader = cl;
- applicationMetaData = amd;
-
- // create metadata for all jaws-managed cmp entities
- // we do that here in case there is no jaws.xml
- Iterator beans = applicationMetaData.getEnterpriseBeans();
- while (beans.hasNext()) {
- BeanMetaData bean = (BeanMetaData)beans.next();
-
- // only take entities
- if (bean.isEntity()) {
- EntityMetaData entity = (EntityMetaData)bean;
-
- // only take jaws-managed CMP entities
- if (entity.isCMP() &&
entity.getContainerConfiguration().getPersistenceManager().equals(JPM)) {
- JawsEntityMetaData jawsEntity = new
JawsEntityMetaData(this, entity);
- entities.put(entity.getEjbName(), jawsEntity);
- }
- }
- }
- }
-
-
- // Public --------------------------------------------------------
- public Connection getConnection() throws SQLException {
- try {
+
+ // all the available type mappings
+ private Hashtable typeMappings = new Hashtable();
+
+ // the type mapping to use with the specified database
+ private TypeMappingMetaData typeMapping;
+
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+ public JawsApplicationMetaData(ApplicationMetaData amd, ClassLoader cl) throws
DeploymentException
+ {
+ // initialisation of this object goes as follows:
+ // - constructor
+ // - importXml() for standardjaws.xml and jaws.xml
+ // - init()
+
+ // the classloader is the same for all the beans in the application
+ classLoader = cl;
+ applicationMetaData = amd;
+
+ // create metadata for all jaws-managed cmp entities
+ // we do that here in case there is no jaws.xml
+ Iterator beans = applicationMetaData.getEnterpriseBeans();
+ while (beans.hasNext())
+ {
+ BeanMetaData bean = (BeanMetaData)beans.next();
+
+ // only take entities
+ if (bean.isEntity())
+ {
+ EntityMetaData entity = (EntityMetaData)bean;
+
+ // only take jaws-managed CMP entities
+ if (entity.isCMP() &&
entity.getContainerConfiguration().getPersistenceManager().equals(JPM))
+ {
+ JawsEntityMetaData jawsEntity = new JawsEntityMetaData(this, entity);
+ entities.put(entity.getEjbName(), jawsEntity);
+ }
+ }
+ }
+ }
+
+
+ // Public --------------------------------------------------------
+ public Connection getConnection() throws SQLException
+ {
+ try
+ {
return dataSource.getConnection();
}
- catch (Exception e) {
- try {
+ catch (Exception e)
+ {
+ try
+ {
init();//maybe datasource was unbound and killed
return dataSource.getConnection();
}
- catch (Exception ee) {
+ catch (Exception ee)
+ {
throw new SQLException("Connection unavailable: " + ee);
- }
+ }
}
}
- public String getDbURL() { return dbURL; }
+ public String getDbURL()
+ { return dbURL; }
- public TypeMappingMetaData getTypeMapping() { return typeMapping; }
-
- public boolean getDebug() { return debug; }
+ public TypeMappingMetaData getTypeMapping()
+ { return typeMapping; }
- protected ClassLoader getClassLoader() { return classLoader; }
-
- public JawsEntityMetaData getBeanByEjbName(String name) {
- return (JawsEntityMetaData)entities.get(name);
- }
-
-
- public void init() throws DeploymentException {
-
- // find the datasource
- if (! dbURL.startsWith("jdbc:")) {
- try {
- dataSource = (DataSource)new
InitialContext().lookup(dbURL);
- } catch (NamingException e) {
- throw new DeploymentException(e.getMessage());
- }
- }
-
- }
-
-
-
- // XmlLoadable implementation ------------------------------------
-
- public void importXml(Element element) throws DeploymentException {
- // importXml will be called at least once: with standardjaws.xml
- // it may be called a second time with user-provided jaws.xml
- // we must ensure to set all defaults values in the first call
- Iterator iterator;
-
- // first get the type mappings. (optional, but always set in
standardjaws.xml)
- Element typeMaps = getOptionalChild(element, "type-mappings");
-
- if (typeMaps != null) {
- iterator = getChildrenByTagName(typeMaps, "type-mapping");
-
- while (iterator.hasNext()) {
- Element typeMappingElement = (Element)iterator.next();
- TypeMappingMetaData typeMapping = new
TypeMappingMetaData();
- try {
- typeMapping.importXml(typeMappingElement);
- } catch (DeploymentException e) {
- throw new DeploymentException("Error in
jaws.xml for type-mapping " + typeMapping.getName() + ": " + e.getMessage());
- }
- typeMappings.put(typeMapping.getName(), typeMapping);
- }
- }
-
- // get the datasource (optional, but always set in standardjaws.xml)
- Element db = getOptionalChild(element, "datasource");
- if (db != null) dbURL = getElementContent(db);
-
+ public boolean getDebug()
+ { return debug; }
+
+ protected ClassLoader getClassLoader()
+ { return classLoader; }
+
+ public JawsEntityMetaData getBeanByEjbName(String name)
+ {
+ return (JawsEntityMetaData)entities.get(name);
+ }
+
+
+ public void init() throws DeploymentException
+ {
+
+ // find the datasource
+ if (! dbURL.startsWith("jdbc:"))
+ {
+ try
+ {
+ dataSource = (DataSource)new InitialContext().lookup(dbURL);
+ } catch (NamingException e)
+ {
+ throw new DeploymentException(e.getMessage());
+ }
+ }
+
+ }
+
+
+
+ // XmlLoadable implementation ------------------------------------
+
+ public void importXml(Element element) throws DeploymentException
+ {
+ // importXml will be called at least once: with standardjaws.xml
+ // it may be called a second time with user-provided jaws.xml
+ // we must ensure to set all defaults values in the first call
+ Iterator iterator;
+
+ // first get the type mappings. (optional, but always set in standardjaws.xml)
+ Element typeMaps = getOptionalChild(element, "type-mappings");
+
+ if (typeMaps != null)
+ {
+ iterator = getChildrenByTagName(typeMaps, "type-mapping");
+
+ while (iterator.hasNext())
+ {
+ Element typeMappingElement = (Element)iterator.next();
+ TypeMappingMetaData typeMapping = new TypeMappingMetaData();
+ try
+ {
+ typeMapping.importXml(typeMappingElement);
+ } catch (DeploymentException e)
+ {
+ throw new DeploymentException("Error in jaws.xml for type-mapping "
+ typeMapping.getName() + ": " + e.getMessage());
+ }
+ typeMappings.put(typeMapping.getName(), typeMapping);
+ }
+ }
+
+ // get the datasource (optional, but always set in standardjaws.xml)
+ Element db = getOptionalChild(element, "datasource");
+ if (db != null) dbURL = getElementContent(db);
+
// Make sure it is prefixed with java:
- if (!dbURL.startsWith("java:/"))
- dbURL = "java:/"+dbURL;
-
- // get the type mapping for this datasource (optional, but always set
in standardjaws.xml)
- String typeMappingString = getElementContent(getOptionalChild(element,
"type-mapping"));
-
- if (typeMappingString != null) {
- typeMapping =
(TypeMappingMetaData)typeMappings.get(typeMappingString);
-
- if (typeMapping == null) {
- throw new DeploymentException("Error in jaws.xml :
type-mapping " + typeMappingString + " not found");
- }
- }
+ if (!dbURL.startsWith("java:/"))
+ dbURL = "java:/"+dbURL;
+
+ // get the type mapping for this datasource (optional, but always set in
standardjaws.xml)
+ String typeMappingString = getElementContent(getOptionalChild(element,
"type-mapping"));
+ if (typeMappingString != null)
+ {
+ typeMapping = (TypeMappingMetaData)typeMappings.get(typeMappingString);
+
+ if (typeMapping == null)
+ {
+ throw new DeploymentException("Error in jaws.xml : type-mapping " +
typeMappingString + " not found");
+ }
+ }
+
//enable extra debugging?
Element debugElement = getOptionalChild(element, "debug");
- if (debugElement != null) {
+ if (debugElement != null)
+ {
String stringDebug = getElementContent( debugElement );
debug = Boolean.valueOf(stringDebug).booleanValue();
}
-
- // get default settings for the beans (optional, but always set in
standardjaws.xml)
- Element defaultEntity = getOptionalChild(element, "default-entity");
-
- if (defaultEntity != null) {
- iterator = entities.values().iterator();
-
- while (iterator.hasNext()) {
-
((JawsEntityMetaData)iterator.next()).importXml(defaultEntity);
- }
- }
-
- // get the beans data (only in jaws.xml)
- Element enterpriseBeans = getOptionalChild(element,
"enterprise-beans");
-
- if (enterpriseBeans != null) {
- String ejbName = null;
-
- try {
- iterator = getChildrenByTagName(enterpriseBeans,
"entity");
-
- while (iterator.hasNext()) {
- Element bean = (Element) iterator.next();
- ejbName =
getElementContent(getUniqueChild(bean, "ejb-name"));
- JawsEntityMetaData entity =
(JawsEntityMetaData)entities.get(ejbName);
-
- if (entity != null) {
- entity.importXml(bean);
- } else {
- Logger.warning("Warning: data found in
jaws.xml for entity " + ejbName + " but bean is not a jaws-managed cmp entity in
ejb-jar.xml");
- }
- }
-
- } catch (DeploymentException e) {
- throw new DeploymentException("Error in jaws.xml for
Entity " + ejbName + ": " + e.getMessage());
- }
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
+
+ // get default settings for the beans (optional, but always set in
standardjaws.xml)
+ Element defaultEntity = getOptionalChild(element, "default-entity");
+
+ if (defaultEntity != null)
+ {
+ iterator = entities.values().iterator();
+
+ while (iterator.hasNext())
+ {
+ ((JawsEntityMetaData)iterator.next()).importXml(defaultEntity);
+ }
+ }
+
+ // get the beans data (only in jaws.xml)
+ Element enterpriseBeans = getOptionalChild(element, "enterprise-beans");
+
+ if (enterpriseBeans != null)
+ {
+ String ejbName = null;
+
+ try
+ {
+ iterator = getChildrenByTagName(enterpriseBeans, "entity");
+
+ while (iterator.hasNext())
+ {
+ Element bean = (Element) iterator.next();
+ ejbName = getElementContent(getUniqueChild(bean, "ejb-name"));
+ JawsEntityMetaData entity =
(JawsEntityMetaData)entities.get(ejbName);
+
+ if (entity != null)
+ {
+ entity.importXml(bean);
+ } else
+ {
+ log.warn("Warning: data found in jaws.xml for entity " + ejbName
+ " but bean is not a jaws-managed cmp entity in ejb-jar.xml");
+ }
+ }
+
+ } catch (DeploymentException e)
+ {
+ throw new DeploymentException("Error in jaws.xml for Entity " + ejbName
+ ": " + e.getMessage());
+ }
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
}
1.5.6.2 +53 -49
jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsXmlFileLoader.java
Index: JawsXmlFileLoader.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsXmlFileLoader.java,v
retrieving revision 1.5.6.1
retrieving revision 1.5.6.2
diff -u -r1.5.6.1 -r1.5.6.2
--- JawsXmlFileLoader.java 2001/11/02 08:42:34 1.5.6.1
+++ JawsXmlFileLoader.java 2001/11/20 09:42:51 1.5.6.2
@@ -13,7 +13,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.jboss.logging.Log;
+import org.jboss.logging.Logger;
import org.jboss.deployment.DeploymentException;
import org.jboss.metadata.ApplicationMetaData;
import org.jboss.metadata.XmlFileLoader;
@@ -24,54 +24,58 @@
*
* @see <related>
* @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.5.6.1 $
+ * @version $Revision: 1.5.6.2 $
*/
-public class JawsXmlFileLoader {
-
- // Attributes ----------------------------------------------------
- private ApplicationMetaData application;
- private ClassLoader classLoader;
- private ClassLoader localClassLoader;
- private Log log;
-
-
- // Constructors --------------------------------------------------
- public JawsXmlFileLoader(ApplicationMetaData app, ClassLoader cl, ClassLoader
localCl, Log l) {
- application = app;
- classLoader = cl;
- localClassLoader = localCl;
- log = l;
- }
-
-
- // Public --------------------------------------------------------
- public JawsApplicationMetaData load() throws DeploymentException {
-
- // first create the metadata
- JawsApplicationMetaData jamd = new
JawsApplicationMetaData(application, classLoader);
-
- // Load standardjaws.xml from the default classLoader
- // we always load defaults first
- URL stdJawsUrl = classLoader.getResource("standardjaws.xml");
-
- if (stdJawsUrl == null) throw new DeploymentException("No
standardjaws.xml found");
-
- log.debug("Loading standardjaws.xml : " + stdJawsUrl.toString());
- Document stdJawsDocument = XmlFileLoader.getDocument(stdJawsUrl);
- jamd.importXml(stdJawsDocument.getDocumentElement());
-
- // Load jaws.xml if provided
- URL jawsUrl = localClassLoader.getResource("META-INF/jaws.xml");
-
- if (jawsUrl != null) {
- log.debug(jawsUrl.toString() + " found. Overriding defaults");
- Document jawsDocument = XmlFileLoader.getDocument(jawsUrl);
- jamd.importXml(jawsDocument.getDocumentElement());
- }
-
- // this can only be done once all the beans are built
- jamd.init();
-
- return jamd;
+public class JawsXmlFileLoader
+{
+
+ // Attributes ----------------------------------------------------
+ private ApplicationMetaData application;
+ private ClassLoader classLoader;
+ private ClassLoader localClassLoader;
+ private Logger log;
+
+
+ // Constructors --------------------------------------------------
+ public JawsXmlFileLoader(ApplicationMetaData app, ClassLoader cl, ClassLoader
localCl, Logger l)
+ {
+ application = app;
+ classLoader = cl;
+ localClassLoader = localCl;
+ log = l;
+ }
+
+
+ // Public --------------------------------------------------------
+ public JawsApplicationMetaData load() throws DeploymentException
+ {
+
+ // first create the metadata
+ JawsApplicationMetaData jamd = new JawsApplicationMetaData(application,
classLoader);
+
+ // Load standardjaws.xml from the default classLoader
+ // we always load defaults first
+ URL stdJawsUrl = classLoader.getResource("standardjaws.xml");
+
+ if (stdJawsUrl == null) throw new DeploymentException("No standardjaws.xml
found");
+
+ log.debug("Loading standardjaws.xml : " + stdJawsUrl.toString());
+ Document stdJawsDocument = XmlFileLoader.getDocument(stdJawsUrl);
+ jamd.importXml(stdJawsDocument.getDocumentElement());
+
+ // Load jaws.xml if provided
+ URL jawsUrl = localClassLoader.getResource("META-INF/jaws.xml");
+
+ if (jawsUrl != null)
+ {
+ log.debug(jawsUrl.toString() + " found. Overriding defaults");
+ Document jawsDocument = XmlFileLoader.getDocument(jawsUrl);
+ jamd.importXml(jawsDocument.getDocumentElement());
+ }
+
+ // this can only be done once all the beans are built
+ jamd.init();
+
+ return jamd;
}
}
1.2.6.2 +3 -3
jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/MappingMetaData.java
Index: MappingMetaData.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/MappingMetaData.java,v
retrieving revision 1.2.6.1
retrieving revision 1.2.6.2
diff -u -r1.2.6.1 -r1.2.6.2
--- MappingMetaData.java 2001/11/02 08:42:34 1.2.6.1
+++ MappingMetaData.java 2001/11/20 09:42:51 1.2.6.2
@@ -20,12 +20,12 @@
*
* @see <related>
* @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.2.6.1 $
+ * @version $Revision: 1.2.6.2 $
*/
public class MappingMetaData extends MetaData implements XmlLoadable
{
// Constants -----------------------------------------------------
-
+ static Logger log = Logger.getLogger(MappingMetaData.class);
// Attributes ----------------------------------------------------
private String javaType;
@@ -51,7 +51,7 @@
} catch (Exception e)
{
- Logger.warning("Unrecognized jdbc-type: " + name + ", using Types.OTHER");
+ log.warn("Unrecognized jdbc-type: " + name + ", using Types.OTHER", e);
return Types.OTHER;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development