[jboss-cvs] JBossAS SVN: r59176 - in projects/microcontainer/trunk: container/src/main/org/jboss/beans/info/plugins container/src/main/org/jboss/joinpoint/plugins kernel/src/main/org/jboss/beans/metadata/plugins kernel/src/main/org/jboss/beans/metadata/spi kernel/src/main/org/jboss/kernel/plugins/config kernel/src/main/org/jboss/kernel/plugins/config/xml kernel/src/main/org/jboss/kernel/plugins/deployment/xml kernel/src/main/org/jboss/kernel/spi/config kernel/src/resources/org/jboss/test/javabean/test kernel/src/resources/schema kernel/src/tests/org/jboss/test/javabean/support kernel/src/tests/org/jboss/test/javabean/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 20 06:56:39 EST 2006


Author: alesj
Date: 2006-12-20 06:56:02 -0500 (Wed, 20 Dec 2006)
New Revision: 59176

Added:
   projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityInt.xml
   projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityString.xml
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/support/AmbiguityBean.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/AmbiguityTestCase.java
Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
   projects/microcontainer/trunk/container/src/main/org/jboss/joinpoint/plugins/Config.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/PropertyMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/Configurator.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/xml/JavaBeanSchemaInitializer.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropHandler.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertiesHandler.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/config/KernelConfigurator.java
   projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestConfigure.xml
   projects/microcontainer/trunk/kernel/src/resources/schema/javabean_1_0.xsd
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/JavaBeanTestSuite.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/PropertyTestCase.java
Log:
JBMICROCONT-125; added property type check, using classloader

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -298,10 +298,8 @@
             Map.Entry<String, List<MethodInfo>> entry = i.next();
             String name = entry.getKey();
             List<MethodInfo> setterList = entry.getValue();
-            // TODO JBMICROCONT-125 Maybe should just create duplicate propertyInfo and let the configurator guess?
-            if (setterList.size() == 1)
+            for(MethodInfo setter : setterList)
             {
-               MethodInfo setter = setterList.get(0);
                TypeInfo pinfo = setter.getParameterTypes()[0];
                String lowerName = getLowerPropertyName(name);
                AnnotationValue[] annotations = setter.getAnnotations();

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/joinpoint/plugins/Config.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/joinpoint/plugins/Config.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/joinpoint/plugins/Config.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -373,10 +373,9 @@
     */
    public static boolean equals(String[] typeNames, TypeInfo[] typeInfos)
    {
-      if (typeNames == null || typeInfos == null)
+      if (simpleCheck(typeNames, typeInfos) == false)
          return false;
-      if (typeNames.length != typeInfos.length)
-         return false;
+
       for (int i = 0; i < typeNames.length; ++i)
       {
          if (typeNames[i] != null && typeNames[i].equals(typeInfos[i].getName()) == false)
@@ -384,4 +383,21 @@
       }
       return true;
    }
+
+   /**
+    * A simple null and length check.
+    *
+    * @param typeNames
+    * @param typeInfos
+    * @return false if either argument is null or lengths differ, else true
+    */
+   protected static boolean simpleCheck(String[] typeNames, TypeInfo[] typeInfos)
+   {
+      if (typeNames == null || typeInfos == null)
+      {
+         return false;
+      }
+      return typeNames.length == typeInfos.length;
+   }
+
 }

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -121,6 +121,15 @@
       flushJBossObjectCache();
    }
 
+   public String getType()
+   {
+      if (value instanceof AbstractTypeMetaData)
+      {
+         return ((AbstractTypeMetaData)value).getType();
+      }
+      return null;
+   }
+
    public ValueMetaData getValue()
    {
       return value;

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/PropertyMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/PropertyMetaData.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/PropertyMetaData.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -35,8 +35,15 @@
     * @return the name.
     */
    String getName();
-   
+
    /**
+    * Get property type if possible.
+    *
+    * @return class type if set, otherwise null
+    */
+   String getType();
+
+   /**
     * Get the value.
     * 
     * @return the value.

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/Configurator.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/Configurator.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/Configurator.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -300,7 +300,7 @@
     */
    public static void configure(boolean trace, Object object, BeanInfo info, ClassLoader cl, PropertyMetaData metaData) throws Throwable
    {
-      PropertyInfo ainfo = resolveProperty(trace, info, metaData.getName());
+      PropertyInfo ainfo = resolveProperty(trace, info, cl, metaData.getName(), metaData.getType());
       configure(trace, object, ainfo, cl, metaData);
    }
 
@@ -440,7 +440,7 @@
     */
    public static TargettedJoinpoint getPropertySetterJoinPoint(boolean trace, BeanInfo info, ClassLoader cl, PropertyMetaData metaData) throws Throwable
    {
-      PropertyInfo ainfo = resolveProperty(trace, info, metaData.getName());
+      PropertyInfo ainfo = resolveProperty(trace, info, cl, metaData.getName(), metaData.getType());
       return getPropertySetterJoinPoint(trace, ainfo, cl, metaData.getValue());
    }
 
@@ -523,13 +523,14 @@
       if (metaData == null)
          throw new IllegalArgumentException("Null bean metadata");
 
+      ClassLoader cl = getClassLoader(metaData);
       Set propertys = metaData.getProperties();
       if (propertys != null && propertys.isEmpty() == false)
       {
          for (Iterator i = metaData.getProperties().iterator(); i.hasNext();)
          {
             PropertyMetaData property = (PropertyMetaData) i.next();
-            unconfigure(object, info, property);
+            unconfigure(object, cl, info, property);
          }
       }
    }
@@ -542,10 +543,10 @@
     * @param metaData the property metadata
     * @throws Throwable for any error
     */
-   public static void unconfigure(Object object, BeanInfo info, PropertyMetaData metaData) throws Throwable
+   public static void unconfigure(Object object, ClassLoader cl, BeanInfo info, PropertyMetaData metaData) throws Throwable
    {
       boolean trace = log.isTraceEnabled();
-      PropertyInfo ainfo = resolveProperty(trace, info, metaData.getName());
+      PropertyInfo ainfo = resolveProperty(trace, info, cl, metaData.getName(), metaData.getType());
       unconfigure(trace, object, ainfo, metaData);
    }
 
@@ -586,7 +587,8 @@
          throw new IllegalArgumentException("Null bean info");
       if (metaData == null)
          throw new IllegalArgumentException("Null bean metadata");
-      
+
+      ClassLoader cl = getClassLoader(metaData);
       Set<TargettedJoinpoint> result = new HashSet<TargettedJoinpoint>();
       Set<PropertyMetaData> propertys = metaData.getProperties();
       if (propertys != null && propertys.isEmpty() == false)
@@ -608,11 +610,26 @@
     * @param metaData the property metadata
     * @return the join point
     * @throws Throwable for any error
+    * @deprecated must use ClassLoader when determinig PropertyInfo
     */
    public static TargettedJoinpoint getPropertyNullerJoinPoint(BeanInfo info, PropertyMetaData metaData) throws Throwable
    {
+      return getPropertyNullerJoinPoint(null, info, metaData);
+   }
+
+   /**
+    * Get property nuller joinpoint for a property
+    *
+    * @param cl the bean classloader
+    * @param info the bean info
+    * @param metaData the property metadata
+    * @return the join point
+    * @throws Throwable for any error
+    */
+   public static TargettedJoinpoint getPropertyNullerJoinPoint(ClassLoader cl, BeanInfo info, PropertyMetaData metaData) throws Throwable
+   {
       boolean trace = log.isTraceEnabled();
-      PropertyInfo ainfo = resolveProperty(trace, info, metaData.getName());
+      PropertyInfo ainfo = resolveProperty(trace, info, cl, metaData.getName(), metaData.getType());
       return getPropertyNullerJoinPoint(ainfo, metaData);
    }
 
@@ -650,11 +667,29 @@
     */
    public static PropertyInfo resolveProperty(boolean trace, BeanInfo info, String name) throws Throwable
    {
+      return resolveProperty(trace, info, null, name, null);
+   }
+
+   /**
+    * Get the property info
+    *
+    * @param trace whether trace is enabled
+    * @param info the bean info
+    * @param name the property name
+    * @param type the property type
+    * @return the property info
+    * @throws Throwable for any error
+    */
+   public static PropertyInfo resolveProperty(boolean trace, BeanInfo info, ClassLoader cl, String name, String type) throws Throwable
+   {
       if (info == null)
          throw new IllegalArgumentException("Null bean info");
       if (name == null)
          throw new IllegalArgumentException("Null name");
-      
+
+      if (trace)
+         log.trace("Resolving property on bean info=" + info + " name=" + name);
+
       Set properties = info.getProperties();
       if (properties != null && properties.size() > 0)
       {
@@ -662,7 +697,14 @@
          {
             PropertyInfo ainfo = (PropertyInfo) i.next();
             if (name.equals(ainfo.getName()))
-               return ainfo;
+            {
+               String[] typeNames = {type};
+               TypeInfo[] typeInfos = {ainfo.getType()};
+               if (equals(typeNames, typeInfos) || assignable(cl, typeNames, typeInfos) || progression(cl, typeNames, typeInfos))
+               {
+                  return ainfo;
+               }
+            }
          }
       }
       
@@ -834,8 +876,59 @@
          cl = tcl;
       return cl;
    }
-   
+
    /**
+    * Test whether type names can be assigned to type infos
+    *
+    * @param cl bean classloader
+    * @param typeNames the type names
+    * @param typeInfos the type infos
+    * @return true when they can be assigned
+    */
+   public static boolean assignable(ClassLoader cl, String[] typeNames, TypeInfo[] typeInfos) throws Throwable
+   {
+      if (cl == null)
+         return false;
+
+      if (simpleCheck(typeNames, typeInfos) == false)
+         return false;
+
+      for (int i = 0; i < typeNames.length; ++i)
+      {
+         if (typeNames[i] != null)
+         {
+            // todo - is there some better way to do this - via Container?
+            Class clazz = Class.forName(typeNames[i], true, cl);
+            if (typeInfos[i].getType().isAssignableFrom(clazz) == false)
+            {
+               return false;
+            }
+         }
+      }
+      return true;
+   }
+
+   /**
+    * Test whether type names can progress to type infos
+    *
+    * @param cl bean classloader
+    * @param typeNames the type names
+    * @param typeInfos the type infos
+    * @return true when we can use progression
+    */
+   public static boolean progression(ClassLoader cl, String[] typeNames, TypeInfo[] typeInfos)
+   {
+      if (cl == null)
+         return false;
+
+      if (simpleCheck(typeNames, typeInfos) == false)
+         return false;
+
+      // JBMICROCONT-119: todo - write this + actual progression code at value injection
+      return false;
+   }
+
+   /**
     * ValueJoinpoint.
     */
    private static class ValueJoinpoint implements Joinpoint

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/xml/JavaBeanSchemaInitializer.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/xml/JavaBeanSchemaInitializer.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/config/xml/JavaBeanSchemaInitializer.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -21,14 +21,11 @@
 */
 package org.jboss.kernel.plugins.config.xml;
 
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
-import java.util.Iterator;
-import java.util.Set;
 
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.kernel.plugins.config.Configurator;
@@ -39,12 +36,7 @@
 import org.jboss.reflect.spi.TypeInfo;
 import org.jboss.reflect.spi.TypeInfoFactory;
 import org.jboss.util.propertyeditor.PropertyEditors;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementInterceptor;
-import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingInitializer;
-import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.*;
 import org.xml.sax.Attributes;
 
 /**
@@ -164,7 +156,7 @@
             Object value = prop.getValue();
             try
             {
-               PropertyInfo info = getProperty(parentValue, property);
+               PropertyInfo info = getProperty(parentValue, property, prop.getType());
                value = convertValue(info, prop.getType(), value);
                method = info.getSetter();
                method.invoke(parentValue, new Object[] { value });
@@ -211,24 +203,11 @@
       return schema;
    }
    
-   private PropertyInfo getProperty(Object parent, String property) throws Throwable
+   private PropertyInfo getProperty(Object parent, String property, String type) throws Throwable
    {
       BeanInfo beanInfo = config.getBeanInfo(parent.getClass());
-      Set properties = beanInfo.getProperties();
-      if (properties != null && properties.size() > 0)
-      {
-         for (Iterator i = properties.iterator(); i.hasNext();)
-         {
-            PropertyInfo prop = (PropertyInfo) i.next();
-            if (prop.getName().equals(property))
-            {
-               if (prop.getSetter() == null)
-                  throw new IllegalArgumentException("Property '" + property + "' is read only " + prop);
-               return prop;
-            }
-         }
-      }
-      throw new IllegalArgumentException("No property '" + property + "' for " + beanInfo);
+      ClassLoader cl = Thread.currentThread().getContextClassLoader();
+      return Configurator.resolveProperty(false, beanInfo, cl, property, type);
    }
 
    /**

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropHandler.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropHandler.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -31,8 +31,7 @@
 /**
  * PropertyHandler.
  *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 43026 $
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  */
 public class PropHandler extends DefaultElementHandler
 {

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertiesHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertiesHandler.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertiesHandler.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -30,8 +30,7 @@
 /**
  * PropertyHandler.
  *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 43026 $
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  */
 public class PropertiesHandler extends DefaultElementHandler
 {

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/config/KernelConfigurator.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/config/KernelConfigurator.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/config/KernelConfigurator.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -205,6 +205,7 @@
     * @param metaData the property metadata
     * @return the join point
     * @throws Throwable for any error
+    * @deprecated must use ClassLoader when determining PropertyInfo
     */
    TargettedJoinpoint getPropertyNullerJoinPoint(BeanInfo info, PropertyMetaData metaData) throws Throwable;
 

Added: projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityInt.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityInt.xml	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityInt.xml	2006-12-20 11:56:02 UTC (rev 59176)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<javabean xmlns="urn:jboss:javabean:1.0" class="org.jboss.test.javabean.support.AmbiguityBean">
+   <property name="something" class="java.lang.Integer">123</property>
+</javabean>

Added: projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityString.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityString.xml	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestAmbiguityString.xml	2006-12-20 11:56:02 UTC (rev 59176)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<javabean xmlns="urn:jboss:javabean:1.0" class="org.jboss.test.javabean.support.AmbiguityBean">
+   <property name="something" class="java.lang.String">SomeString</property>
+</javabean>

Modified: projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestConfigure.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestConfigure.xml	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/javabean/test/TestConfigure.xml	2006-12-20 11:56:02 UTC (rev 59176)
@@ -9,7 +9,8 @@
    <property name="ALong">12345</property>
    <property name="AFloat">3.14</property>
    <property name="ADouble">3.14e12</property>
-   <property name="ADate">Mon Jan 01 00:00:00 CET 2001</property>
+   <!--<property name="ADate">Mon Jan 01 00:00:00 CET 2001</property>-->
+   <property name="ADate">Jan 01 00:00:00 CET 2001</property>
    <property name="ABigDecimal">12e4</property>
    <property name="ABigInteger">123456</property>
    <property name="abyte">12</property>

Modified: projects/microcontainer/trunk/kernel/src/resources/schema/javabean_1_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/schema/javabean_1_0.xsd	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/resources/schema/javabean_1_0.xsd	2006-12-20 11:56:02 UTC (rev 59176)
@@ -14,7 +14,7 @@
          <![CDATA[
          A schema for constructing javabeans.
 
-         <javabean xmlns="urn:jboss:bean-deployer:2.0"
+         <javabean xmlns="urn:jboss:javabean:1.0"
                    class="com.acme.MyJavaBean">
             <property name="someProperty">SomeValue</property>
          ...

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/support/AmbiguityBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/support/AmbiguityBean.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/support/AmbiguityBean.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.javabean.support;
+
+/**
+ * SimpleBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 46093 $
+ */
+public class AmbiguityBean
+{
+   private Integer someint;
+   private String somestring;
+
+   public void setSomething(Integer integer)
+   {
+      someint = integer;
+   }
+
+   public void setSomething(String string)
+   {
+      somestring = string;
+   }
+
+   public Object something()
+   {
+      if (someint != null && somestring != null)
+         throw new IllegalArgumentException("Only one 'something' can be set!");
+      if (someint != null)
+         return someint;
+      if (somestring != null)
+         return somestring;
+      throw new IllegalArgumentException("Must set 'something'!");
+   }
+
+   public String toString()
+   {
+      return someint + "," + somestring;
+   }
+
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/AmbiguityTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/AmbiguityTestCase.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/AmbiguityTestCase.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.javabean.test;
+
+import junit.framework.Test;
+import org.jboss.test.javabean.support.AmbiguityBean;
+
+/**
+ * PropertyTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 58996 $
+ */
+public class AmbiguityTestCase extends AbstractJavaBeanTest
+{
+   /**
+    * Create a new AmbiguityTestCase.
+    *
+    * @param name the test name
+    */
+   public AmbiguityTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test
+    *
+    * @return the test
+    */
+   public static Test suite()
+   {
+      return suite(AmbiguityTestCase.class);
+   }
+
+   public void testConfigureInt() throws Exception
+   {
+      AmbiguityBean ab = unmarshal("TestAmbiguityInt.xml", AmbiguityBean.class);
+      Object something = ab.something();
+      assertEquals(something.getClass(), Integer.class);
+   }
+
+   public void testConfigureString() throws Exception
+   {
+      AmbiguityBean ab = unmarshal("TestAmbiguityString.xml", AmbiguityBean.class);
+      Object something = ab.something();
+      assertEquals(something.getClass(), String.class);
+   }
+
+}

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/JavaBeanTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/JavaBeanTestSuite.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/JavaBeanTestSuite.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -44,7 +44,8 @@
 
       suite.addTest(InstantiateTestCase.suite());
       suite.addTest(PropertyTestCase.suite());
-      
+      suite.addTest(AmbiguityTestCase.suite());
+
       return suite;
    }
 }

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/PropertyTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/PropertyTestCase.java	2006-12-20 05:03:08 UTC (rev 59175)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/javabean/test/PropertyTestCase.java	2006-12-20 11:56:02 UTC (rev 59176)
@@ -44,8 +44,10 @@
  */
 public class PropertyTestCase extends AbstractJavaBeanTest
 {
-   private static DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
-   
+//   private static DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
+   // even example from API doesn't work for me (alesj) - with EEE
+   private static DateFormat dateFormat = new SimpleDateFormat("MMM d HH:mm:ss z yyyy");
+
    String stringValue =  "StringValue";
    Byte byteValue = new Byte("12");
    Boolean booleanValue = Boolean.TRUE;
@@ -56,12 +58,16 @@
    Long longValue = new Long("12345");
    Float floatValue = new Float("3.14");
    Double doubleValue = new Double("3.14e12");
-   Date dateValue = createDate("Mon Jan 01 00:00:00 CET 2001");
+//   Date dateValue = createDate("Mon Jan 01 00:00:00 CET 2001");
+   Date dateValue = createDate("Jan 01 00:00:00 CET 2001");
    BigDecimal bigDecimalValue = new BigDecimal("12e4");
    BigInteger bigIntegerValue = new BigInteger("123456");
 
    public void testConfigure() throws Exception
    {
+      // tmp format
+      System.setProperty("org.jboss.util.propertyeditor.DateEditor.format", "MMM d HH:mm:ss z yyyy");
+      // check bean
       SimpleBean bean = unmarshal("TestConfigure.xml", SimpleBean.class);
       assertEquals("()", bean.getConstructorUsed());
       




More information about the jboss-cvs-commits mailing list