harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r447820 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ main/java/org/apache/harmony/beans/internal/nls/ test/java/org/apache/harmony/beans/tests/java/beans/
Date Tue, 19 Sep 2006 11:35:22 GMT
Author: tellison
Date: Tue Sep 19 04:35:21 2006
New Revision: 447820

URL: http://svn.apache.org/viewvc?view=rev&rev=447820
Log:
Apply patch HARMONY-1466 ([classlib][beans] PropertyDescriptor#createPropertyEditor() is missing)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=447820&r1=447819&r2=447820
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
Tue Sep 19 04:35:21 2006
@@ -14,23 +14,15 @@
  *  limitations under the License.
  */
 
-/**
- * @author Maxim V. Berkultsev
- * @version $Revision: 1.9.4.3 $
- */
 package java.beans;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Constructor;
 import java.util.Vector;
 
 import org.apache.harmony.beans.internal.nls.Messages;
 
-/**
- * @author Maxim V. Berkultsev
- * @version $Revision: 1.9.4.3 $
- */
-
 public class PropertyDescriptor extends FeatureDescriptor {
 
     Class<?> beanClass = null;
@@ -44,9 +36,6 @@
     boolean constrained = false;
     boolean bound = false;
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public PropertyDescriptor(String propertyName, Class<?> beanClass,
             String getterName, String setterName) throws IntrospectionException {
 
@@ -80,9 +69,6 @@
         }
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public PropertyDescriptor(String propertyName, Method getter, Method setter)
             throws IntrospectionException {
         super();
@@ -99,9 +85,6 @@
         setReadMethod(getter);
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public PropertyDescriptor(String propertyName, Class<?> beanClass)
             throws IntrospectionException {
         super();
@@ -136,9 +119,6 @@
         }
     }
         
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setWriteMethod(Method setter) throws IntrospectionException {
         if (setter != null) {
             int modifiers = setter.getModifiers();
@@ -164,9 +144,6 @@
         this.setter = setter;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setReadMethod(Method getter) throws IntrospectionException {
         if (getter != null) {
             int modifiers = getter.getModifiers();
@@ -195,23 +172,14 @@
         this.getter = getter;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public Method getWriteMethod() {
         return setter;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public Method getReadMethod() {
         return getter;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public boolean equals(Object object) {
         boolean result = (object != null);
         if (result) {
@@ -243,16 +211,10 @@
         return result;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setPropertyEditorClass(Class<?> propertyEditorClass) {
         this.propertyEditorClass = propertyEditorClass;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public Class<?> getPropertyType() {
         Class<?> result = null;
         if (getter != null) {
@@ -264,37 +226,22 @@
         return result;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public Class<?> getPropertyEditorClass() {
         return propertyEditorClass;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setConstrained(boolean constrained) {
         this.constrained = constrained;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setBound(boolean bound) {
         this.bound = bound;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public boolean isConstrained() {
         return constrained;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public boolean isBound() {
         return bound;
     }
@@ -366,5 +313,39 @@
                 break;
             }
         }
+    }
+    
+    public PropertyEditor createPropertyEditor(Object bean) {
+        PropertyEditor editor;
+
+        if (propertyEditorClass == null) {
+            return null;
+        }
+
+        if (!PropertyEditor.class.isAssignableFrom(propertyEditorClass)) {
+            // beans.48=Property editor is not assignable from the PropertyEditor interface
+            throw new ClassCastException(Messages.getString("beans.48")); //$NON-NLS-1$
+        }
+
+        try {
+            Constructor constr;
+
+            try {
+                // try to look for the constructor with single Object argument
+                constr = propertyEditorClass.getConstructor(Object.class);
+                editor = (PropertyEditor) constr.newInstance(bean);
+            } catch (NoSuchMethodException e) {
+                // try no-argument constructor
+                constr = propertyEditorClass.getConstructor();
+                editor = (PropertyEditor) constr.newInstance();
+            }
+        } catch (Exception e) {
+            // beans.47=Unable to instantiate property editor
+            RuntimeException re = new RuntimeException(
+                    Messages.getString("beans.47"), e); //$NON-NLS-1$
+
+            throw re;
+        }
+        return editor;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties?view=diff&rev=447820&r1=447819&r2=447820
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
Tue Sep 19 04:35:21 2006
@@ -85,3 +85,5 @@
 beans.44=for property {0} no getter(setter) is found
 beans.45=method name is not generated: error in getMethodName()
 beans.46=Not a valid child
+beans.47=Unable to instantiate property editor
+beans.48=Property editor is not assignable from the PropertyEditor interface

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java?view=diff&rev=447820&r1=447819&r2=447820
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
Tue Sep 19 04:35:21 2006
@@ -17,6 +17,8 @@
 
 import java.beans.IntrospectionException;
 import java.beans.PropertyDescriptor;
+import java.beans.PropertyEditorSupport;
+import java.beans.PropertyEditor;
 import java.io.Serializable;
 import java.lang.reflect.Method;
 
@@ -960,6 +962,55 @@
             assertEquals("bad property name", e.getMessage());
         }
     }
+    
+    public void testCreatePropertyEditor() throws IntrospectionException {
+        PropertyDescriptor pd =
+                new PropertyDescriptor("propertyOne", MockJavaBean.class);
+        PropertyEditor pe;
+
+        pe = pd.createPropertyEditor(this);
+        assertNull(pe);
+
+        pd.setPropertyEditorClass(CoolPropertyEditor.class);
+        pe = pd.createPropertyEditor(this);
+        assertNotNull(pe);
+        pe.setAsText("Harmony");
+        assertEquals("Harmony is cool", pe.getAsText());
+
+        pd.setPropertyEditorClass(VeryCoolPropertyEditor.class);
+        pe = pd.createPropertyEditor(this);
+        assertNotNull(pe);
+        pe.setAsText("Harmony");
+        assertEquals("Harmony is really cool", pe.getAsText());
+
+        pd.setPropertyEditorClass(null);
+        pe = pd.createPropertyEditor(this);
+        assertNull(pe);
+
+    }
+
+    public void testCreatePropertyEditor_Invalid() throws
+            IntrospectionException {
+        PropertyDescriptor pd =
+                new PropertyDescriptor("propertyOne", MockJavaBean.class);
+
+        try {
+            pd.setPropertyEditorClass(InvalidPropertyEditor.class);
+            pd.createPropertyEditor(this);
+            fail("RuntimeException expected");
+        } catch (RuntimeException e) {
+            // valid
+        }
+
+        try {
+            pd.setPropertyEditorClass(InvalidPropertyEditor2.class);
+            pd.createPropertyEditor(this);
+            fail("ClassCastException expected");
+        } catch (ClassCastException e) {
+            // valid
+        }
+    }
+
 
     static class FakeFox01 {
 
@@ -1003,4 +1054,47 @@
         private static final long serialVersionUID = 7423254295680570566L;
         //
     }
+    
+
+    public static class CoolPropertyEditor extends PropertyEditorSupport {
+        String str;
+        String suffix;
+
+        public CoolPropertyEditor() {
+            suffix = " is cool";
+        }
+
+        public void setAsText(String newVal) {
+            str = newVal + suffix;
+        }
+
+        public String getAsText() {
+            return str;
+        }
+    };
+
+    public static class VeryCoolPropertyEditor extends CoolPropertyEditor {
+        public VeryCoolPropertyEditor() {
+            super();
+        }
+
+        public VeryCoolPropertyEditor(Object obj) {
+            suffix = " is really cool";
+        }
+    }
+
+
+    public static class InvalidPropertyEditor extends PropertyEditorSupport {
+        // there is no valid constructors
+        public InvalidPropertyEditor(Object arg1, Object arg2) {
+        }
+    }
+
+
+    public static class InvalidPropertyEditor2 {
+        // is not assignable from PropertyEditor
+        public InvalidPropertyEditor2() {
+        }
+    }
+
 }



Mime
View raw message