db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r422231 [4/4] - in /db/ojb/trunk/src/java/org/apache/ojb/broker: ./ accesslayer/ accesslayer/sql/ cache/ core/ locking/ metadata/ metadata/fieldaccess/
Date Sat, 15 Jul 2006 14:20:27 GMT
Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanImpl.java?rev=422231&r1=422230&r2=422231&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanImpl.java
(original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanImpl.java
Sat Jul 15 07:20:25 2006
@@ -16,13 +16,12 @@
  */
 
 import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.lang.SystemUtils;
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.metadata.MetadataException;
-import org.apache.ojb.broker.util.logging.Logger;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
 
 /**
- * A {@link PersistentField} implementation accesses a property
+ * A {@link org.apache.ojb.broker.metadata.fieldaccess.PersistentField} implementation accesses
a property
  * from a {@link org.apache.commons.beanutils.DynaBean}.
  * Note that because of the way that PersistentField works,
  * at run time the type of the field could actually be different, since
@@ -125,26 +124,28 @@
      */
     protected void logSetProblem(Object anObject, Object aValue, String msg)
     {
-        Logger logger = LoggerFactory.getDefaultLogger();
-        logger.error("Error in operation [set] of object [" + this.getClass().getName() +
"], " + msg);
-        logger.error("Property Name [" + getName() + "]");
+        String eol = SystemUtils.LINE_SEPARATOR;
+        StringBuffer buf = new StringBuffer();
+        buf.append("Error in [set] operation: " + msg);
+        buf.append(eol + "  Property Name [" + getName() + "]");
         if (anObject instanceof DynaBean)
         {
             DynaBean dynaBean = (DynaBean) anObject;
-            logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() +
"]");
+            buf.append(eol + "  the target object is a DynaClass [" + dynaBean.getDynaClass().getName()
+ "]");
         }
         else if (anObject != null)
         {
-            logger.error("anObject was class [" + anObject.getClass().getName() + "]");
+            buf.append(eol + "  the target object type is [" + anObject.getClass().getName()
+ "]");
         }
         else
         {
-            logger.error("anObject was null");
+            buf.append(eol + "  the target object is 'null'");
         }
         if (aValue != null)
-            logger.error("aValue was class [" + aValue.getClass().getName() + "]");
+            buf.append(eol + "  the value type is [" + aValue.getClass().getName() + "]");
         else
-            logger.error("aValue was null");
+            buf.append(eol + "  the value is 'null'");
+        getLog().error(buf.toString());
     }
 
     /**
@@ -152,21 +153,23 @@
      */
     protected void logGetProblem(Object anObject, String msg)
     {
-        Logger logger = LoggerFactory.getDefaultLogger();
-        logger.error("Error in operation [get of object [" + this.getClass().getName() +
"], " + msg);
-        logger.error("Property Name [" + getName() + "]");
+        String eol = SystemUtils.LINE_SEPARATOR;
+        StringBuffer buf = new StringBuffer();
+        buf.append("Error in [get] operation: " + msg);
+        buf.append(eol + "  Property Name [" + getName() + "]");
         if (anObject instanceof DynaBean)
         {
             DynaBean dynaBean = (DynaBean) anObject;
-            logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() +
"]");
+            buf.append(eol + "  the object to read is a DynaClass [" + dynaBean.getDynaClass().getName()
+ "]");
         }
         else if (anObject != null)
         {
-            logger.error("anObject was class [" + anObject.getClass().getName() + "]");
+            buf.append(eol + "  the type of object to read is [" + anObject.getClass().getName()
+ "]");
         }
         else
         {
-            logger.error("anObject was null");
+            buf.append(eol + "  the object to read is 'null'");
         }
+        getLog().error(buf.toString());
     }
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldIntrospectorImpl.java?rev=422231&r1=422230&r2=422231&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldIntrospectorImpl.java
(original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldIntrospectorImpl.java
Sat Jul 15 07:20:25 2006
@@ -15,9 +15,6 @@
  * limitations under the License.
  */
 
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -26,7 +23,6 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.ojb.broker.metadata.MetadataException;
 import org.apache.ojb.broker.util.ClassHelper;
-import org.apache.ojb.broker.util.logging.Logger;
 
 /**
  * A {@link PersistentField} implementation using
@@ -120,13 +116,16 @@
             }
             catch (Throwable e)
             {
-                logProblem(pd, target, null, "Can't read value from given object");
-                throw new MetadataException("Error invoking method:" + m.getName() + " in
object " + target.getClass().getName(), e);
+                String msg = buildGetterErrorMsg(pd.getPropertyType(), target, "Can't read
value from given object");
+                getLog().error(msg);
+                throw new MetadataException("Error invoking method '" + m.getName() + "'
in object '"
+                        + target.getClass().getName() + "'", e);
             }
         }
         else
         {
-            throw new MetadataException("Can't get ReadMethod for property:" + pd.getName()
+ " in object " + target.getClass().getName());
+            throw new MetadataException("Can't get ReadMethod for property '" + pd.getName()
+                    + "' in object " + target.getClass().getName());
         }
     }
 
@@ -152,13 +151,16 @@
             }
             catch (Throwable e)
             {
-                logProblem(pd, target, value, "Can't set value on given object.");
-                throw new MetadataException("Error invoking method:" + m.getName() + " in
object:" + target.getClass().getName(), e);
+                String msg = buildSetterErrorMsg(pd.getPropertyType(), target, value, "Can't
set value on given object.");
+                getLog().error(msg);
+                throw new MetadataException("Error invoking method '" + m.getName()
+                        + "' in object '" + target.getClass().getName() + "'", e);
             }
         }
         else
         {
-            throw new MetadataException("Can't get WriteMethod for property:" + pd.getName()
+ " in object:" + target.getClass().getName());
+            throw new MetadataException("Can't get WriteMethod for property '"
+                    + pd.getName() + "' in object '" + target.getClass().getName() + "'");
         }
     }
 
@@ -193,47 +195,6 @@
     }
 
     /**
-     * Get the PropertyDescriptor for aClass and aPropertyName
-     */
-    protected static PropertyDescriptor findPropertyDescriptor(Class aClass, String aPropertyName)
-    {
-        BeanInfo info;
-        PropertyDescriptor[] pd;
-        PropertyDescriptor descriptor = null;
-
-        try
-        {
-            info = Introspector.getBeanInfo(aClass);
-            pd = info.getPropertyDescriptors();
-            for (int i = 0; i < pd.length; i++)
-            {
-                if (pd[i].getName().equals(aPropertyName))
-                {
-                    descriptor = pd[i];
-                    break;
-                }
-            }
-            if (descriptor == null)
-            {
-                /*
-				 * Daren Drummond: 	Throw here so we are consistent
-				 * 					with PersistentFieldDefaultImpl.
-				 */
-                throw new MetadataException("Can't find property " + aPropertyName + " in
" + aClass.getName());
-            }
-            return descriptor;
-        }
-        catch (IntrospectionException ex)
-        {
-            /*
-			 * Daren Drummond: 	Throw here so we are consistent
-			 * 					with PersistentFieldDefaultImpl.
-			 */
-            throw new MetadataException("Can't find property " + aPropertyName + " in " +
aClass.getName(), ex);
-        }
-    }
-
-    /**
      * Returns the PropertyDescriptor.
      *
      * @return java.beans.PropertyDescriptor
@@ -251,34 +212,5 @@
     public boolean makeAccessible()
     {
         return false;
-    }
-
-    /**
-     * Let's give the user some hints as to what could be wrong.
-     */
-    protected void logProblem(PropertyDescriptor pd, Object anObject, Object aValue, String
msg)
-    {
-        Logger logger = getLog();
-        logger.error("Error in [PersistentFieldPropertyImpl], " + msg);
-        logger.error("Declaring class [" + getDeclaringClass().getName() + "]");
-        logger.error("Property Name [" + getName() + "]");
-        logger.error("Property Type [" + pd.getPropertyType().getName() + "]");
-
-        if (anObject != null)
-        {
-            logger.error("anObject was class [" + anObject.getClass().getName() + "]");
-        }
-        else
-        {
-            logger.error("anObject was null");
-        }
-        if (aValue != null)
-        {
-            logger.error("aValue was class [" + aValue.getClass().getName() + "]");
-        }
-        else
-        {
-            logger.error("aValue was null");
-        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message