[jboss-svn-commits] JBoss Common SVN: r2191 - jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 7 09:03:09 EST 2006


Author: alex.loubyansky at jboss.com
Date: 2006-12-07 09:03:06 -0500 (Thu, 07 Dec 2006)
New Revision: 2191

Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
Log:
don't handle wrapped list as a wrapped array

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java	2006-12-07 14:00:20 UTC (rev 2190)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java	2006-12-07 14:03:06 UTC (rev 2191)
@@ -387,8 +387,10 @@
       if(!term.isModelGroup())
       {
          TypeBinding type = ((ElementBinding)term).getType();
-         if(!type.isStartElementCreatesObject() ||
-            classMetaData == null && mapEntryMetaData == null && Constants.QNAME_ANYTYPE.equals(type.getQName()))
+         if(type.isSimple() ||
+               classMetaData == null && mapEntryMetaData == null &&
+               (!type.isStartElementCreatesObject() ||
+                     Constants.QNAME_ANYTYPE.equals(type.getQName())))
          {
             if(trace)
             {
@@ -398,8 +400,6 @@
          }
       }
 
-      Object o = null;
-
       // if addMethod is specified, it's probably some collection field
       // but should not be set as a property. Instead, items are added to it using the addMethod
       ElementBinding arrayItem = null;
@@ -452,7 +452,7 @@
                {
                   log.trace("startElement " + elementName + " new array " + itemType.getName());
                }
-               o = GenericValueContainer.FACTORY.array(itemType);
+               return GenericValueContainer.FACTORY.array(itemType);
             }
          }
          else
@@ -475,7 +475,7 @@
 
             if(trace)
             {
-               log.trace("startElement " + elementName + " property=" + propName);
+               log.trace("startElement " + elementName + " property=" + propName + " wrapper=" + wrapperType);
             }
 
             Class parentClass = wrapperType;
@@ -509,226 +509,204 @@
                }
             }
 
+            // TODO: review the logic for cases when wrapperType == null
             if(fieldType.isArray())
             {
-               o = GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
+               return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
             }
             else if(Collection.class.isAssignableFrom(fieldType))
             {
-               //System.out.println("GeenericValueContainer.child: " + elementName);
-               o = new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
-               //o = new ArrayList();
+               if(wrapperType == null)
+               {
+                  return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
+                  //o = new ArrayList();
+               }         
             }
             else
             {
-               o = GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
+               return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
             }
          }
       }
-      else
+
+      Object o = null;
+      if (mapEntryMetaData != null)
       {
-         if(mapEntryMetaData != null)
+         if (mapEntryMetaData.getImpl() != null)
          {
-            if(mapEntryMetaData.getImpl() != null)
+            Class cls = loadClassForTerm(mapEntryMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
+
+            if (trace)
             {
-               Class cls = loadClassForTerm(mapEntryMetaData.getImpl(),
-                  term.getSchema().isIgnoreUnresolvedFieldOrClass(),
-                  elementName
-               );
+               log.trace("startElement " + elementName + " new map entry " + cls.getName());
+            }
 
-               if(trace)
+            o = newInstance(cls, elementName, term.getSchema().isUseNoArgCtorIfFound());
+         }
+         else
+         {
+            o = new MapEntry();
+            if (trace)
+            {
+               log.trace("startElement " + elementName + " new map entry");
+            }
+         }
+
+         if (mapEntryMetaData.isNonNullValue() && mapEntryMetaData.getValueType() != null)
+         {
+            Class mapValueType;
+            try
+            {
+               mapValueType = Thread.currentThread().getContextClassLoader().loadClass(mapEntryMetaData.getValueType());
+            }
+            catch (ClassNotFoundException e)
+            {
+               throw new JBossXBRuntimeException("startElement failed for " + elementName + ": failed to load class "
+                     + mapEntryMetaData.getValueType() + " for map entry value.");
+            }
+
+            Object value;
+            try
+            {
+               if (trace)
                {
-                  log.trace("startElement " + elementName + " new map entry " + cls.getName());
+                  log.trace("startElement " + elementName + " map value type " + mapEntryMetaData.getValueType());
                }
+               value = mapValueType.newInstance();
+            }
+            catch (Exception e)
+            {
+               throw new JBossXBRuntimeException("startElement failed for " + elementName
+                     + ": failed to create an instance of " + mapValueType + " for map entry value.");
+            }
 
-               o = newInstance(cls, elementName, term.getSchema().isUseNoArgCtorIfFound());
+            if (o instanceof MapEntry)
+            {
+               ((MapEntry) o).setValue(value);
             }
             else
             {
-               o = new MapEntry();
-               if(trace)
+               String getValueMethodName = mapEntryMetaData.getGetValueMethod();
+               if (getValueMethodName == null)
                {
-                  log.trace("startElement " + elementName + " new map entry");
+                  getValueMethodName = "getValue";
                }
-            }
 
-            if(mapEntryMetaData.isNonNullValue() && mapEntryMetaData.getValueType() != null)
-            {
-               Class mapValueType;
+               String setValueMethodName = mapEntryMetaData.getSetValueMethod();
+               if (setValueMethodName == null)
+               {
+                  setValueMethodName = "setValue";
+               }
+
+               Method getValueMethod;
                try
                {
-                  mapValueType =
-                     Thread.currentThread().getContextClassLoader().loadClass(mapEntryMetaData.getValueType());
+                  getValueMethod = o.getClass().getMethod(getValueMethodName, null);
                }
-               catch(ClassNotFoundException e)
+               catch (NoSuchMethodException e)
                {
-                  throw new JBossXBRuntimeException("startElement failed for " +
-                     elementName +
-                     ": failed to load class " +
-                     mapEntryMetaData.getValueType() +
-                     " for map entry value."
-                  );
+                  throw new JBossXBRuntimeException("getValueMethod=" + getValueMethodName
+                        + " is not found in map entry " + o.getClass());
                }
 
-               Object value;
+               Method setValueMethod;
                try
                {
-                  if(trace)
-                  {
-                     log.trace("startElement " + elementName + " map value type " + mapEntryMetaData.getValueType());
-                  }
-                  value = mapValueType.newInstance();
+                  setValueMethod = o.getClass().getMethod(setValueMethodName, new Class[]{getValueMethod.getReturnType()});
                }
-               catch(Exception e)
+               catch (NoSuchMethodException e)
                {
-                  throw new JBossXBRuntimeException("startElement failed for " +
-                     elementName +
-                     ": failed to create an instance of " +
-                     mapValueType +
-                     " for map entry value."
-                  );
+                  throw new JBossXBRuntimeException("setValueMethod=" + setValueMethodName + "("
+                        + getValueMethod.getReturnType().getName() + " value) is not found in map entry "
+                        + o.getClass());
                }
 
-               if(o instanceof MapEntry)
+               try
                {
-                  ((MapEntry)o).setValue(value);
+                  setValueMethod.invoke(o, new Object[]
+                  {value});
                }
-               else
+               catch (Exception e)
                {
-                  String getValueMethodName = mapEntryMetaData.getGetValueMethod();
-                  if(getValueMethodName == null)
-                  {
-                     getValueMethodName = "getValue";
-                  }
-
-                  String setValueMethodName = mapEntryMetaData.getSetValueMethod();
-                  if(setValueMethodName == null)
-                  {
-                     setValueMethodName = "setValue";
-                  }
-
-                  Method getValueMethod;
-                  try
-                  {
-                     getValueMethod = o.getClass().getMethod(getValueMethodName, null);
-                  }
-                  catch(NoSuchMethodException e)
-                  {
-                     throw new JBossXBRuntimeException("getValueMethod=" +
-                        getValueMethodName +
-                        " is not found in map entry " + o.getClass()
-                     );
-                  }
-
-                  Method setValueMethod;
-                  try
-                  {
-                     setValueMethod =
-                        o.getClass().getMethod(setValueMethodName, new Class[]{getValueMethod.getReturnType()});
-                  }
-                  catch(NoSuchMethodException e)
-                  {
-                     throw new JBossXBRuntimeException("setValueMethod=" +
-                        setValueMethodName +
-                        "(" +
-                        getValueMethod.getReturnType().getName() +
-                        " value) is not found in map entry " + o.getClass()
-                     );
-                  }
-
-                  try
-                  {
-                     setValueMethod.invoke(o, new Object[]{value});
-                  }
-                  catch(Exception e)
-                  {
-                     throw new JBossXBRuntimeException("setValueMethod=" +
-                        setValueMethodName +
-                        " failed: owner=" +
-                        o +
-                        ", value=" + value + ", msg=" + e.getMessage(), e
-                     );
-                  }
+                  throw new JBossXBRuntimeException("setValueMethod=" + setValueMethodName + " failed: owner=" + o
+                        + ", value=" + value + ", msg=" + e.getMessage(), e);
                }
             }
          }
-         else
+      }
+      else
+      {
+         // todo: for now we require metadata for model groups to be bound
+         // todo 2: parent.getClass() is not going to work for containers
+         Class parentClass = null;
+         if (parent != null)
          {
-            // todo: for now we require metadata for model groups to be bound
-            // todo 2: parent.getClass() is not going to work for containers
-            Class parentClass = null;
-            if(parent != null)
+            if (parent instanceof GenericValueContainer)
             {
-               if(parent instanceof GenericValueContainer)
-               {
-                  parentClass = ((GenericValueContainer)parent).getTargetClass();
-               }
-               else if(parent instanceof ValueList)
-               {
-                  parentClass = ((ValueList)parent).getTargetClass();
-               }
-               else
-               {
-                  parentClass = parent.getClass();
-               }
+               parentClass = ((GenericValueContainer) parent).getTargetClass();
             }
-
-            Class cls;
-            if(term.isModelGroup())
+            else if (parent instanceof ValueList)
             {
-               if(classMetaData == null)
-               {
-                  throw new JBossXBRuntimeException(
-                     "Model groups should be annotated with 'class' annotation to be bound."
-                  );
-               }
-               cls = loadClassForTerm(classMetaData.getImpl(),
-                  term.getSchema().isIgnoreUnresolvedFieldOrClass(),
-                  elementName
-               );
+               parentClass = ((ValueList) parent).getTargetClass();
             }
             else
             {
-               ElementBinding element = (ElementBinding)term;
-               cls = classForNonArrayItem(element, parentClass);
-               if(cls != null)
+               parentClass = parent.getClass();
+            }
+         }
+
+         Class cls;
+         if (term.isModelGroup())
+         {
+            if (classMetaData == null)
+            {
+               throw new JBossXBRuntimeException(
+                     "Model groups should be annotated with 'class' annotation to be bound.");
+            }
+            cls = loadClassForTerm(classMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
+         }
+         else
+         {
+            ElementBinding element = (ElementBinding) term;
+            cls = classForNonArrayItem(element, parentClass);
+            if (cls != null)
+            {
+               // todo: before that, the type should be checked for required attributes and elements
+               TypeBinding simpleType = element.getType().getSimpleType();
+               if (simpleType != null)
                {
-                  // todo: before that, the type should be checked for required attributes and elements
-                  TypeBinding simpleType = element.getType().getSimpleType();
-                  if(simpleType != null)
+                  Class simpleCls = classForSimpleType(simpleType, element.isNillable());
+                  if (cls.equals(simpleCls) || cls.isPrimitive() && Classes.getPrimitiveWrapper(cls) == simpleCls
+                        || simpleCls.isPrimitive() && Classes.getPrimitiveWrapper(simpleCls) == cls)
                   {
-                     Class simpleCls = classForSimpleType(simpleType, element.isNillable());
-                     if(cls.equals(simpleCls) ||
-                        cls.isPrimitive() && Classes.getPrimitiveWrapper(cls) == simpleCls ||
-                        simpleCls.isPrimitive() && Classes.getPrimitiveWrapper(simpleCls) == cls)
-                     {
-                        cls = null;
-                     }
+                     cls = null;
                   }
                }
             }
+         }
 
-            if(cls != null)
+         if (cls != null)
+         {
+            boolean noArgCtor;
+            if (classMetaData == null)
             {
-               boolean noArgCtor;
-               if(classMetaData == null)
-               {
-                  noArgCtor = term.getSchema().isUseNoArgCtorIfFound();
-               }
-               else
-               {
-                  Boolean termUsesNoArgCtor = classMetaData.isUseNoArgCtor();
-                  noArgCtor = termUsesNoArgCtor == null ?
-                     term.getSchema().isUseNoArgCtorIfFound() : termUsesNoArgCtor.booleanValue();               }
+               noArgCtor = term.getSchema().isUseNoArgCtorIfFound();
+            }
+            else
+            {
+               Boolean termUsesNoArgCtor = classMetaData.isUseNoArgCtor();
+               noArgCtor = termUsesNoArgCtor == null ?
+                     term.getSchema().isUseNoArgCtorIfFound() : termUsesNoArgCtor.booleanValue();
+            }
 
-               if(trace)
-               {
-                  log.trace("startElement " + elementName + " new " + cls.getName() + ", noArgCtor=" + noArgCtor);
-               }
-               o = newInstance(cls, elementName, noArgCtor);
+            if (trace)
+            {
+               log.trace("startElement " + elementName + " new " + cls.getName() + ", noArgCtor=" + noArgCtor);
             }
+            o = newInstance(cls, elementName, noArgCtor);
          }
       }
+
       return o;
    }
 




More information about the jboss-svn-commits mailing list