[jboss-cvs] JBossAS SVN: r60323 - projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 6 07:15:01 EST 2007


Author: alesj
Date: 2007-02-06 07:15:01 -0500 (Tue, 06 Feb 2007)
New Revision: 60323

Added:
   projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/NestedPropertyInfo.java
Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java
Log:
Added NestedPropertyInfo, handeling set for multiple same named propertys.

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java	2007-02-06 10:57:12 UTC (rev 60322)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java	2007-02-06 12:15:01 UTC (rev 60323)
@@ -117,7 +117,22 @@
          propertiesByName = new HashMap<String, PropertyInfo>(properties.size());
          for (PropertyInfo property : properties)
          {
-            propertiesByName.put(property.getName(), property);
+            PropertyInfo previous = propertiesByName.put(property.getName(), property);
+            if (previous != null)
+            {
+               NestedPropertyInfo nestedPropertyInfo;
+               if (previous instanceof NestedPropertyInfo)
+               {
+                  nestedPropertyInfo = (NestedPropertyInfo)previous;
+               }
+               else
+               {
+                  nestedPropertyInfo = new NestedPropertyInfo(previous.getName());
+                  nestedPropertyInfo.addPropertyInfo(previous);
+                  propertiesByName.put(previous.getName(), nestedPropertyInfo);
+               }
+               nestedPropertyInfo.addPropertyInfo(property);
+            }
             if (property instanceof AbstractPropertyInfo)
             {
                AbstractPropertyInfo ainfo = (AbstractPropertyInfo) property;

Added: projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/NestedPropertyInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/NestedPropertyInfo.java	                        (rev 0)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/NestedPropertyInfo.java	2007-02-06 12:15:01 UTC (rev 60323)
@@ -0,0 +1,78 @@
+/*
+* 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.beans.info.plugins;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * When bean has more than one property with the same name
+ * we try to use this impl to look over all possible setters.
+ * In case of getter we cannot determine which one to use
+ * since there is insufficient information - only parent bean.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NestedPropertyInfo extends AbstractPropertyInfo
+{
+   private List<PropertyInfo> propertys = new ArrayList<PropertyInfo>();
+
+   public NestedPropertyInfo(String name)
+   {
+      super(name);
+   }
+
+   void addPropertyInfo(PropertyInfo propertyInfo)
+   {
+      propertys.add(propertyInfo);
+   }
+
+   public Object get(Object bean) throws Throwable
+   {
+      throw new IllegalArgumentException("Unable to determine getter!");
+   }
+
+   public void set(Object bean, Object value) throws Throwable
+   {
+      if (value != null)
+      {
+         for (PropertyInfo pi : propertys)
+         {
+            TypeInfo info = pi.getType();
+            if (info != null)
+            {
+               TypeInfo valueTypeInfo = info.getTypeInfoFactory().getTypeInfo(value.getClass());
+               if (info.isAssignableFrom(valueTypeInfo))
+               {
+                  pi.set(bean, value);
+                  return;
+               }
+            }
+         }
+      }
+      throw new IllegalArgumentException("Unable to determine setter!");
+   }
+
+}




More information about the jboss-cvs-commits mailing list