[jboss-svn-commits] JBoss Common SVN: r3627 - in jbossxb/trunk/src: main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 2 06:31:53 EST 2009


Author: alex.loubyansky at jboss.com
Date: 2009-11-02 06:31:52 -0500 (Mon, 02 Nov 2009)
New Revision: 3627

Added:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/RepeatableParticleHandler.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapType.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeAdapter.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeRoot.java
   jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMyHashMapType.xml
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtCharactersHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/CollectionPropertyHandler.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java
Log:
JBXB-227, JBXB-228

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultWildcardHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -25,6 +25,7 @@
 import javax.xml.namespace.QName;
 
 import org.jboss.logging.Logger;
+import org.jboss.xb.binding.group.ValueList;
 import org.xml.sax.Attributes;
 
 /**
@@ -59,6 +60,13 @@
    public void setParent(Object parent, Object o, QName elementName, ParticleBinding particle,
          ParticleBinding parentParticle)
    {
+      if(parent instanceof ValueList)
+      {
+         ValueList valueList = (ValueList)parent;
+         valueList.getInitializer().addTermValue(elementName, particle, this, valueList, o, parentParticle);
+         return;
+      }
+
       ElementBinding element = (ElementBinding) particle.getTerm();
       ElementBinding parentElement = (ElementBinding) parentParticle.getTerm();
       setParent(parent, o, elementName, element, parentElement);

Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/RepeatableParticleHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/RepeatableParticleHandler.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/RepeatableParticleHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -0,0 +1,189 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.xb.binding.sunday.unmarshalling;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.xb.binding.GenericValueContainer;
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.jboss.xb.binding.group.ValueList;
+import org.jboss.xb.binding.group.ValueListHandler;
+import org.jboss.xb.binding.group.ValueListInitializer;
+import org.jboss.xb.binding.group.ValueList.NonRequiredValue;
+
+/**
+ * A RepeatableParticleHandler.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public interface RepeatableParticleHandler
+{
+   RepeatableParticleHandler VALUE_LIST = new RepeatableParticleHandler()
+   {
+      @Override
+      public Object startRepeatableParticle(Object parent, QName startName, ParticleBinding particle)
+      {
+         TermBinding term = particle.getTerm();
+         if(term.isSkip())
+         {
+            return null;
+         }
+         
+         if(parent != null &&
+               !(parent instanceof GenericValueContainer) &&
+               (parent instanceof Collection == false) &&
+               term.getAddMethodMetaData() == null &&
+               term.getMapEntryMetaData() == null &&
+               term.getPutMethodMetaData() == null)
+         {
+            ValueListHandler handler = ValueListHandler.FACTORY.lazy(parent);
+            Class<?> cls = parent.getClass();
+            return new ValueListInitializer().newValueList(handler, cls);
+         }
+         return null;
+      }      
+
+      @Override
+      public void endRepeatableParticle(Object parent, Object o, QName elementName, ParticleBinding particle, ParticleBinding parentParticle)
+      {
+         if (o == null)
+            throw new IllegalArgumentException("Collection value is null for repeatable particle " + particle.getTerm());
+
+         ValueList valueList = (ValueList) o;
+         if (valueList.size() == 0)
+            return;
+
+         if (particle.getTerm().isWildcard())
+         {
+            ParticleHandler handler = null;
+
+            // that's not good. some elements can be handled as "unresolved" and some as "resolved"
+            QName qName = valueList.getValue(0).qName;
+            Collection<Object> col = new ArrayList<Object>();
+            for (int i = 0; i < valueList.size(); ++i)
+            {
+               NonRequiredValue value = valueList.getValue(i);
+               col.add(value.value);
+
+               if (handler != value.handler)
+               {
+                  if (handler == null && i == 0)
+                  {
+                     handler = (ParticleHandler) value.handler;
+                  }
+                  else
+                  {
+                     throw new JBossXBRuntimeException("Handlers in the list are supposed to be the same.");
+                  }
+               }
+            }
+
+            handler.setParent(parent, col, qName, particle, parentParticle);
+         }
+         else
+         {
+            valueList.getHandler().newInstance(particle, valueList);
+         }
+      }
+
+      @Override
+      public void addTermValue(Object parent, Object particleValue, Object termValue, QName elementName,
+            ParticleBinding particle, ParticleBinding parentParticle, ParticleHandler handler)
+      {
+         if(parent == termValue)
+            return;
+
+         ValueList valueList = (ValueList)particleValue;
+         valueList.getInitializer().addTermValue(elementName, particle, handler, valueList, termValue, parentParticle);
+      }
+   };
+
+   RepeatableParticleHandler NOOP = new RepeatableParticleHandler()
+   {
+      @Override
+      public Object startRepeatableParticle(Object parent, QName startName, ParticleBinding particle)
+      {
+         return null;
+      }
+
+      @Override
+      public void endRepeatableParticle(Object parent, Object o, QName elementName, ParticleBinding particle, ParticleBinding parentParticle)
+      {
+      }
+
+      @Override
+      public void addTermValue(Object parent, Object particleValue, Object termValue, QName elementName,
+            ParticleBinding particle, ParticleBinding parentParticle, ParticleHandler handler)
+      {
+      }
+   };
+
+   RepeatableParticleHandler LIST = new RepeatableParticleHandler()
+   {
+      @Override
+      public Object startRepeatableParticle(Object parent, QName startName, ParticleBinding particle)
+      {
+         return new ArrayList<Object>();
+      }
+
+      @Override
+      public void endRepeatableParticle(Object parent, Object o, QName elementName, ParticleBinding particle, ParticleBinding parentParticle)
+      {
+         if(o == null)
+            return;
+         
+         ParticleHandler handler;
+         TermBinding term = particle.getTerm();
+         if(term.isElement())
+         {
+            handler = ((ElementBinding)term).getType().getHandler();
+         }
+         else if(term.isModelGroup())
+         {
+            handler = ((ModelGroupBinding)term).getHandler();
+         }
+         else
+         {
+            handler = ((WildcardBinding)term).getWildcardHandler();
+         }
+         
+         handler.setParent(parent, o, elementName, particle, parentParticle);
+      }
+
+      @Override
+      public void addTermValue(Object parent, Object particleValue, Object termValue, QName elementName,
+            ParticleBinding particle, ParticleBinding parentParticle, ParticleHandler handler)
+      {
+         ((Collection<Object>)particleValue).add(termValue);
+      }
+   };
+
+   Object startRepeatableParticle(Object parent, QName startName, ParticleBinding particle);
+   
+   void addTermValue(Object parent, Object particleValue, Object termValue, QName elementName, ParticleBinding particle, ParticleBinding parentParticle, ParticleHandler handler);
+   
+   void endRepeatableParticle(Object parent, Object o, QName elementName, ParticleBinding particle, ParticleBinding parentParticle);
+}

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -23,7 +23,6 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -33,14 +32,9 @@
 import org.jboss.util.StringPropertyReplacer;
 import org.jboss.xb.binding.AttributesImpl;
 import org.jboss.xb.binding.Constants;
-import org.jboss.xb.binding.GenericValueContainer;
 import org.jboss.xb.binding.JBossXBRuntimeException;
 import org.jboss.xb.binding.NamespaceRegistry;
 import org.jboss.xb.binding.Util;
-import org.jboss.xb.binding.group.ValueList;
-import org.jboss.xb.binding.group.ValueListHandler;
-import org.jboss.xb.binding.group.ValueListInitializer;
-import org.jboss.xb.binding.group.ValueList.NonRequiredValue;
 import org.jboss.xb.binding.introspection.FieldInfo;
 import org.jboss.xb.binding.metadata.CharactersMetaData;
 import org.jboss.xb.binding.metadata.PropertyMetaData;
@@ -51,7 +45,7 @@
 import org.xml.sax.Attributes;
 
 /**
- * ContentHandler that is used as a sandbox for JBXB-76
+ * Default ContentHandler
  *
  * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
  * @version <tt>$Revision$</tt>
@@ -72,6 +66,7 @@
    private NamespaceRegistry nsRegistry = new NamespaceRegistry();
 
    private ParticleHandler defParticleHandler = DefaultHandlers.ELEMENT_HANDLER;
+   private RepeatableParticleHandler defRepeatableHandler = RepeatableParticleHandler.VALUE_LIST;
 
    private UnmarshallingContextImpl ctx = new UnmarshallingContextImpl();
    // DTD information frm startDTD
@@ -190,7 +185,12 @@
                pop();
                if(item.particle.isRepeatable())
                {
-                  endRepeatableParticle(item.particle);
+                  StackItem parentItem = stack.peek();
+                  if(parentItem.repeatableParticleValue != null)
+                  {
+                     endRepeatableParticle(parentItem.o, parentItem.repeatableParticleValue, item.qName, item.particle, parentItem.particle);
+                     parentItem.repeatableParticleValue = null;
+                  }
                }
             }
             else
@@ -209,15 +209,22 @@
 
             ParticleBinding currentParticle = item.cursor.getCurrentParticle();
             TermBinding term = currentParticle.getTerm();
-            if(term.isWildcard() && currentParticle.isRepeatable())
+            if(item.repeatableParticleValue != null /* && currentParticle.isRepeatable()*/ && term.isWildcard())
             {
-               endRepeatableParticle(currentParticle);
+               StackItem parentItem = stack.peek1();
+               endRepeatableParticle(parentItem.o, item.repeatableParticleValue, item.qName, currentParticle, parentItem.particle);
+               item.repeatableParticleValue = null;
             }
 
             pop();
             if(item.particle.isRepeatable())
             {
-               endRepeatableParticle(item.particle);
+               StackItem parentItem = stack.peek();
+               if(parentItem.repeatableParticleValue != null)
+               {
+                  endRepeatableParticle(parentItem.o, parentItem.repeatableParticleValue, item.qName, item.particle, parentItem.particle);
+                  parentItem.repeatableParticleValue = null;
+               }
             }
          }
       }
@@ -317,7 +324,11 @@
                         else
                         {
                            pop();
-                           endRepeatableParticle(item.particle);
+                           if(parentItem.repeatableParticleValue != null)
+                           {
+                              endRepeatableParticle(parentItem.o, parentItem.repeatableParticleValue, item.qName, item.particle, parentItem.particle);
+                              parentItem.repeatableParticleValue = null;
+                           }
                            continue;
                         }
                      }
@@ -335,7 +346,14 @@
                   {
                      pop();                     
                      if(item.particle.isRepeatable())
-                        endRepeatableParticle(item.particle);
+                     {
+                        StackItem parentItem = stack.peek();
+                        if(parentItem.repeatableParticleValue != null)
+                        {
+                           endRepeatableParticle(parentItem.o, parentItem.repeatableParticleValue, item.qName, item.particle, parentItem.particle);
+                           parentItem.repeatableParticleValue = null;
+                        }
+                     }
                      continue;
                   }
                }
@@ -403,12 +421,12 @@
                         ParticleBinding modelGroupParticle = cursor.getParticle();
                         if(modelGroupParticle.isRepeatable())
                         {
-                           startRepeatableParticle(o, startName, modelGroupParticle);
+                           stack.peek().repeatableParticleValue = startRepeatableParticle(o, startName, modelGroupParticle);
                         }
 
                         handler = getHandler(modelGroupParticle);
                         o = handler.startParticle(o, startName, modelGroupParticle, atts, nsRegistry);
-                        push(cursor, o, handler, parentType);
+                        push(startName, cursor, o, handler, parentType);
                      }
                      particle = cursor.getCurrentParticle();
                   }
@@ -472,14 +490,17 @@
                   ParticleBinding curParticle = cursor.getCurrentParticle();
                   if(curParticle != prevParticle)
                   {
-                     if(prevParticle != null && prevParticle.isRepeatable() && prevParticle.getTerm().isModelGroup())
+                     if(item.repeatableParticleValue != null &&
+                           prevParticle != null && prevParticle.isRepeatable() && prevParticle.getTerm().isModelGroup())
                      {
-                        endRepeatableParticle(prevParticle);
+                        StackItem parentItem = stack.peek1();
+                        endRepeatableParticle(parentItem.o, item.repeatableParticleValue, item.qName, prevParticle, parentItem.particle);
+                        item.repeatableParticleValue = null;
                      }
 
                      if(newCursors.size() > 1 && curParticle.isRepeatable())
                      {
-                        startRepeatableParticle(stack.peek1().o, startName, curParticle);
+                        stack.peek().repeatableParticleValue = startRepeatableParticle(stack.peek1().o, startName, curParticle);
                      }
                   }
                   else
@@ -497,7 +518,7 @@
                      ParticleBinding modelGroupParticle = cursor.getParticle();
                      handler = getHandler(modelGroupParticle);
                      o = handler.startParticle(o, startName, modelGroupParticle, atts, nsRegistry);
-                     push(cursor, o, handler, parentType);
+                     push(startName, cursor, o, handler, parentType);
                   }
                   cursor = newCursors.get(0);
                   particle = cursor.getCurrentParticle();
@@ -528,7 +549,7 @@
 
             if(!repeatedParticle && particle.isRepeatable())
             {
-               startRepeatableParticle(parent, startName, particle);
+               stack.peek().repeatableParticleValue = startRepeatableParticle(parent, startName, particle);
             }
             particle = new ParticleBinding(element/*, particle.getMinOccurs(), particle.getMaxOccurs(), particle.getMaxOccursUnbounded()*/);
          }
@@ -582,7 +603,7 @@
 
          if(!repeated && particle.isRepeatable())
          {
-            startRepeatableParticle(parent, startName, particle);
+            stack.peek().repeatableParticleValue = startRepeatableParticle(parent, startName, particle);
          }
 
          TypeBinding type = element.getType();
@@ -608,17 +629,17 @@
 
             for (int i = 0; i < localInterceptors.size(); ++i)
             {
-               ElementInterceptor interceptor = (ElementInterceptor) localInterceptors.get(i);
+               ElementInterceptor interceptor = localInterceptors.get(i);
                parent = interceptor.startElement(parent, startName, type);
-               push(particle, parent, handler, parentType);
+               push(startName, particle, parent, handler, parentType);
                interceptor.attributes(parent, startName, type, atts, nsRegistry);
             }
 
             for (int i = 0; i < interceptors.size(); ++i)
             {
-               ElementInterceptor interceptor = (ElementInterceptor) interceptors.get(i);
+               ElementInterceptor interceptor = interceptors.get(i);
                parent = interceptor.startElement(parent, startName, type);
-               push(particle, parent, handler, parentType);
+               push(startName, particle, parent, handler, parentType);
                interceptor.attributes(parent, startName, type, atts, nsRegistry);
             }
 
@@ -678,7 +699,7 @@
       }
       else
       {
-         push(particle, o, handler, parentType);
+         push(startName, particle, o, handler, parentType);
       }
    }
 
@@ -780,86 +801,19 @@
       }
    }
 
-   private void startRepeatableParticle(Object parent, QName startName, ParticleBinding particle)
+   private Object startRepeatableParticle(Object parent, QName startName, ParticleBinding particle)
    {
       if(trace)
          log.trace(" start repeatable (" + stack.size() + "): " + particle.getTerm());
-      
-      TermBinding term = particle.getTerm();
-      if(term.isSkip())
-      {
-         return;
-      }
-      
-      StackItem item = stack.peek();
-      if(item.o != null &&
-            !(item.o instanceof GenericValueContainer) &&
-            (item.o instanceof Collection == false) &&
-            term.getAddMethodMetaData() == null &&
-            term.getMapEntryMetaData() == null &&
-            term.getPutMethodMetaData() == null)
-      {
-         ValueListHandler handler = ValueListHandler.FACTORY.lazy(item.o);
-         Class<?> cls = item.o.getClass();
-         item.repeatableParticleValue = new ValueListInitializer().newValueList(handler, cls);
-      }
+      return defRepeatableHandler.startRepeatableParticle(parent, startName, particle);
    }
 
-   private void endRepeatableParticle(ParticleBinding particle)
+   private void endRepeatableParticle(Object parent, Object o, QName elementName, ParticleBinding particle, ParticleBinding parentParticle)
    {
-      if(trace)
+      if (trace)
          log.trace(" end repeatable (" + stack.size() + "): " + particle.getTerm());
 
-      StackItem item = stack.peek();
-      ValueList valueList = item.repeatableParticleValue;
-      if(valueList != null)
-      {
-         item.repeatableParticleValue = null;
-         if(valueList.size() == 0)
-         {
-            return;
-         }
-            
-         if(particle.getTerm().isWildcard())
-         {
-            ParticleHandler handler = null;
-/*
-            handler = ((WildcardBinding) particle.getTerm()).getWildcardHandler();
-            if (handler == null)
-            {
-               handler = defParticleHandler;
-            }
- */
-            
-            // that's not good. some elements can be handled as "unresolved" and some as "resolved"
-            QName qName = valueList.getValue(0).qName;
-            Collection<Object> col = new ArrayList<Object>();
-            for(int i = 0; i < valueList.size(); ++i)
-            {
-               NonRequiredValue value = valueList.getValue(i);
-               col.add(value.value);
-
-               if(handler != value.handler)
-               {
-                  if(handler == null && i == 0)
-                  {
-                     handler = (ParticleHandler) value.handler;
-                  }
-                  else
-                  {
-                     throw new JBossXBRuntimeException("Handlers in the list are supposed to be the same.");
-                  }
-               }
-            }
-
-            StackItem parentItem = stack.peek1();
-            handler.setParent(parentItem.o, col, qName, particle, parentItem.particle);
-         }
-         else
-         {
-            valueList.getHandler().newInstance(particle, valueList);
-         }
-      }
+      defRepeatableHandler.endRepeatableParticle(parent, o, elementName, particle, parentParticle);
    }
 
    private void endParticle(QName qName, StackItem item, StackItem parentItem)
@@ -872,20 +826,7 @@
       ParticleBinding modelGroupParticle = item.particle;
       ParticleHandler handler = item.handler;//getHandler(modelGroupParticle);
 
-      Object o;
-      if(item.o instanceof ValueList && !modelGroupParticle.getTerm().isSkip())
-      {
-         if(trace)
-         {
-            log.trace("endParticle " + modelGroupParticle.getTerm() + " valueList");
-         }
-         ValueList valueList = (ValueList)item.o;
-         o = valueList.getHandler().newInstance(modelGroupParticle, valueList);
-      }
-      else
-      {
-         o = handler.endParticle(item.o, qName, modelGroupParticle);
-      }
+      Object o = handler.endParticle(item.o, qName, modelGroupParticle);
 
       item.ended = true;
 
@@ -895,12 +836,12 @@
       {
          ParticleBinding parentParticle = getParentParticle();//item.particle;
          if(parentParticle == null)
-         {
             parentParticle = parentItem.particle;
-         }
-         setParent(handler,
-               parentItem.repeatableParticleValue == null ? parentItem.o : parentItem.repeatableParticleValue,
-               o, qName, modelGroupParticle, parentParticle);
+         
+         if(parentItem.repeatableParticleValue == null)
+            setParent(handler, parentItem.o, o, qName, modelGroupParticle, parentParticle);
+         else
+            defRepeatableHandler.addTermValue(parentItem.o, parentItem.repeatableParticleValue, o, qName, modelGroupParticle, parentParticle, handler);
       }
    }
 
@@ -1118,33 +1059,7 @@
                      ctx.clear();
                   }
                   
-                  if(o instanceof ValueList)
-                  {
-                     ValueList valueList = (ValueList)o;
-                     if(type.isSimple())
-                     {
-                        valueList.getInitializer().addTermValue(endName,
-                           particle,
-                           charHandler,
-                           valueList,
-                           unmarshalled,
-                           null
-                        );
-                     }
-                     else
-                     {
-                        valueList.getInitializer().addTextValue(endName,
-                           particle,
-                           charHandler,
-                           valueList,
-                           unmarshalled
-                        );
-                     }
-                  }
-                  else
-                  {
-                     charHandler.setValue(endName, element, o, unmarshalled);
-                  }
+                  charHandler.setValue(endName, element, o, unmarshalled);
                }
             }
 
@@ -1153,13 +1068,13 @@
                int interceptorIndex = stack.size() - 1 - allInterceptors;
                for (int i = interceptors.size() - 1; i >= 0; --i)
                {
-                  ElementInterceptor interceptor = (ElementInterceptor) interceptors.get(i);
+                  ElementInterceptor interceptor = interceptors.get(i);
                   interceptor.characters(stack.peek(interceptorIndex++).o, endName, type, nsRegistry, dataContent);
                }
 
                for (int i = localInterceptors.size() - 1; i >= 0; --i)
                {
-                  ElementInterceptor interceptor = (ElementInterceptor) localInterceptors.get(i);
+                  ElementInterceptor interceptor = localInterceptors.get(i);
                   interceptor.characters(stack.peek(interceptorIndex++).o, endName, type, nsRegistry, dataContent);
                }
             }
@@ -1178,26 +1093,14 @@
       Object parent = parentItem == null ? null : parentItem.o;
       ParticleHandler handler = stack.peek().handler;
       
-      if(o instanceof ValueList && !particle.getTerm().isSkip())
-      {
-         if(trace)
-         {
-            log.trace("endParticle " + endName + " valueList");
-         }
-         ValueList valueList = (ValueList)o;
-         o = valueList.getHandler().newInstance(particle, valueList);
-      }
-      else
-      {
-         o = handler.endParticle(o, endName, particle);
-      }
+      o = handler.endParticle(o, endName, particle);
 
       if(!interceptors.isEmpty())
       {
          int interceptorIndex = stack.size() - 1 - interceptors.size();
          for (int i = interceptors.size() - 1; i >= 0; --i)
          {
-            ElementInterceptor interceptor = (ElementInterceptor) interceptors.get(i);
+            ElementInterceptor interceptor = interceptors.get(i);
             interceptor.endElement(stack.peek(interceptorIndex++).o, endName, type);
          }
       }
@@ -1210,7 +1113,6 @@
       {
          ParticleBinding parentParticle = getParentParticle();
          boolean hasWildcard = false;
-         ParticleHandler wildcardHandler = null;
          if (parentParticle != null && parentParticle.getTerm().isElement())
          {
             WildcardBinding wildcard = ((ElementBinding) parentParticle.getTerm()).getType().getWildcard();
@@ -1219,29 +1121,19 @@
                hasWildcard = true;
                if(parentItem.cursor.isWildcardContent())
                {
-                  wildcardHandler = wildcard.getWildcardHandler();
+                  ParticleHandler wh = wildcard.getWildcardHandler();
+                  if(wh != null)
+                     handler = wh;
                }
             }
          }
 
          if(parent != null)
          {
-            /*if(o == null)
-            {
-               throw new JBossXBRuntimeException(endName + " is null!");
-            } */
-            if(wildcardHandler != null)
-            {
-               setParent(wildcardHandler,
-                     parentItem.repeatableParticleValue == null ? parent : parentItem.repeatableParticleValue,
-                     o, endName, particle, parentParticle);
-            }
+            if(parentItem.repeatableParticleValue == null)
+               setParent(handler, parent, o, endName, particle, parentParticle);
             else
-            {
-               setParent(handler,
-                     parentItem.repeatableParticleValue == null ? parent : parentItem.repeatableParticleValue,
-                     o, endName, particle, parentParticle);
-            }
+               defRepeatableHandler.addTermValue(parent, parentItem.repeatableParticleValue, o, endName, particle, parentParticle, handler);
          }
          else if(parentParticle != null && hasWildcard && stack.size() > 1)
          {
@@ -1264,7 +1156,7 @@
 
          for(int i = interceptors.size() - 1; i >= 0; --i)
          {
-            ElementInterceptor interceptor = (ElementInterceptor)interceptors.get(i);
+            ElementInterceptor interceptor = interceptors.get(i);
             parent = pop().o;
             interceptor.add(parent, o, endName);
             o = parent;
@@ -1272,7 +1164,7 @@
 
          for(int i = localInterceptors.size() - 1; i >= 0; --i)
          {
-            ElementInterceptor interceptor = (ElementInterceptor)localInterceptors.get(i);
+            ElementInterceptor interceptor = localInterceptors.get(i);
             parent = pop().o;
             interceptor.add(parent, o, endName);
             o = parent;
@@ -1324,24 +1216,12 @@
          ctx.clear();
       }
       
-      if(parent instanceof ValueList /*&& !particle.getTerm().isSkip()*/)
-      {
-         if(parent == o)
-         {            
-            return;
-         }
-         ValueList valueList = (ValueList)parent;
-         valueList.getInitializer().addTermValue(endName, particle, handler, valueList, o, parentParticle);
-      }
-      else
-      {
-         handler.setParent(parent, o, endName, particle, parentParticle);
-      }
+      handler.setParent(parent, o, endName, particle, parentParticle);
    }
 
-   private void push(ParticleBinding particle, Object o, ParticleHandler handler, TypeBinding parentType)
+   private void push(QName qName, ParticleBinding particle, Object o, ParticleHandler handler, TypeBinding parentType)
    {
-      StackItem item = new StackItem(particle);
+      StackItem item = new StackItem(qName, particle);
       item.o = o;
       item.handler = handler;
       item.parentType = parentType;      
@@ -1355,9 +1235,9 @@
       }
    }
 
-   private void push(ModelGroupBinding.Cursor cursor, Object o, ParticleHandler handler, TypeBinding parentType)
+   private void push(QName qName, ModelGroupBinding.Cursor cursor, Object o, ParticleHandler handler, TypeBinding parentType)
    {
-      StackItem item = new StackItem(cursor);
+      StackItem item = new StackItem(qName, cursor);
       item.o = o;
       item.handler = handler;
       item.parentType = parentType;
@@ -1383,6 +1263,7 @@
 
    private static class StackItem
    {
+      final QName qName;
       final ModelGroupBinding.Cursor cursor;
       ParticleBinding particle;
       ParticleBinding nonXsiParticle;
@@ -1390,27 +1271,37 @@
       TypeBinding parentType;
       boolean ignoreCharacters;
       Object o;
-      ValueList repeatableParticleValue;
+      Object repeatableParticleValue;
       StringBuffer textContent;
       Boolean indentation;
       boolean ignorableCharacters = true;
       boolean ended;
 
-      public StackItem(ModelGroupBinding.Cursor cursor)
+      public StackItem(QName qName, ModelGroupBinding.Cursor cursor)
       {
          if (cursor == null)
             throw new IllegalArgumentException("Null cursor");
          // this is modelgroup particle
          this.cursor = cursor;
+         
+         if(qName == null)
+            throw new IllegalArgumentException("Null qName");
+         this.qName = qName;
+         
          this.particle = cursor.getParticle();
       }
 
-      public StackItem(ParticleBinding particle)
+      public StackItem(QName qName, ParticleBinding particle)
       {
          if (particle == null)
             throw new IllegalArgumentException("Null particle");
          // this is element particle
          this.cursor = null;
+         
+         if(qName == null)
+            throw new IllegalArgumentException("Null qName");
+         this.qName = qName;
+
          this.particle = particle;
       }
 

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtCharactersHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtCharactersHandler.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtCharactersHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -27,11 +27,13 @@
 import org.jboss.xb.binding.Constants;
 import org.jboss.xb.binding.JBossXBRuntimeException;
 import org.jboss.xb.binding.Util;
+import org.jboss.xb.binding.group.ValueList;
 import org.jboss.xb.binding.metadata.CharactersMetaData;
 import org.jboss.xb.binding.metadata.PropertyMetaData;
 import org.jboss.xb.binding.metadata.ValueMetaData;
 import org.jboss.xb.binding.sunday.unmarshalling.CharactersHandler;
 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
 import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
 import org.jboss.util.Classes;
 
@@ -124,16 +126,40 @@
 
    public void setValue(QName qName, ElementBinding element, Object owner, Object value)
    {
-      //todo: assert if type is not null it must simple...
+      //TODO: assert if type is not null it must simple...
 
-      if(owner == null) // todo: owner should never be null
+      if(owner == null) // TODO: owner should never be null
       {
          return;
       }
       
-      if (owner instanceof MapEntry)
+      if(owner instanceof ValueList)
       {
+         ValueList valueList = (ValueList)owner;
          TypeBinding type = element.getType();
+         if(type.isSimple())
+         {
+            valueList.getInitializer().addTermValue(qName,
+               new ParticleBinding(element), // TODO
+               this,
+               valueList,
+               value,
+               null
+            );
+         }
+         else
+         {
+            valueList.getInitializer().addTextValue(qName,
+               new ParticleBinding(element),
+               this,
+               valueList,
+               value
+            );
+         }
+      }
+      else if (owner instanceof MapEntry)
+      {
+         TypeBinding type = element.getType();
          CharactersMetaData characters = type.getCharactersMetaData();
          if (characters != null)
          {

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	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -260,9 +260,14 @@
             }
          }
 
-         if(tryPut(owner, o, qName, term, trace))
+         if(owner instanceof ValueList)
          {
+            ValueList valueList = (ValueList)owner;
+            valueList.getInitializer().addTermValue(qName, particle, this, valueList, o, parentParticle);
          }
+         else if(tryPut(owner, o, qName, term, trace))
+         {
+         }
          else if(tryAdd(owner, o, qName, term, wildcard, trace))
          {
          }
@@ -317,10 +322,20 @@
             }
             else
             {*/
+
+            if(particle.isRepeatable() && !(o instanceof Collection))
+            {
+               RtUtil.add(owner, o, propName, colType,
+                     term.getSchema().isIgnoreUnresolvedFieldOrClass(),
+                     term.getValueAdapter()
+                  );               
+            }
+            else
+            {
                RtUtil.set(owner, o, propName, colType,
                      term.getSchema().isIgnoreUnresolvedFieldOrClass(),
                      term.getValueAdapter());
-            //}
+            }
          }
       }
    }
@@ -334,19 +349,19 @@
       }
 
       boolean trace = log.isTraceEnabled();
-      if(trace)
+      if(o instanceof ValueList)
       {
-         log.trace("endParticle " + elementName + " object=" + o + " term=" + term);
+         if(trace)
+            log.trace("endParticle " + particle.getTerm() + " valueList");
+         ValueList valueList = (ValueList)o;
+         o = valueList.getHandler().newInstance(particle, valueList);
       }
-
-      if(o instanceof GenericValueContainer)
+      else if(o instanceof GenericValueContainer)
       {
          try
          {
             if(trace)
-            {
                log.trace("endParticle " + elementName + " instantiate()");
-            }
             o = ((GenericValueContainer)o).instantiate();
          }
          catch(JBossXBRuntimeException e)
@@ -361,6 +376,10 @@
             );
          }
       }
+      else if(trace)
+      {
+         log.trace("endParticle " + elementName + " object=" + o + " term=" + term);
+      }
 
       return o;
    }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -184,13 +184,14 @@
          return;
       }
 
-      if(particle.isRepeatable() && !(propertyHandler instanceof PropertyHandler))
+      if(particle.isRepeatable() && !(propertyHandler instanceof PropertyHandler) &&
+            o != null && java.util.Collection.class.isAssignableFrom(o.getClass()))
       {
          // TODO this is not optimal!
          // repeatable particles are collected into java.util.Collection
-         for(Object item : (java.util.Collection)o)
+         for (Object item : (java.util.Collection<?>) o)
          {
-            if(valueAdapter != null)
+            if (valueAdapter != null)
             {
                item = valueAdapter.cast(item, null/*propertyHandler.getPropertyType().getType()*/);
             }

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/CollectionPropertyHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/CollectionPropertyHandler.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/CollectionPropertyHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -174,7 +174,6 @@
    
    private static class ArrayListFactory implements CollectionFactory
    {
-      @SuppressWarnings("unchecked")
       public Collection<Object> createCollection()
       {
          return new ArrayList<Object>();
@@ -183,7 +182,6 @@
    
    private static class HashSetFactory implements CollectionFactory
    {
-      @SuppressWarnings("unchecked")
       public Collection<Object> createCollection()
       {
          return new HashSet<Object>();

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/GroupBeanHandler.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -91,7 +91,7 @@
          }
       }
 
-      if(groupValue == null)
+      if(groupValue == null || particle.isRepeatable())
          return super.startParticle(parent, qName, particle, attrs, nsCtx);
       else
          return new SingletonBeanAdapter(this.getBeanAdapterFactory(), groupValue);

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapType.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapType.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapType.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.xb.builder.object.element.javatypeadapter.support;
+
+import java.util.List;
+
+/**
+ * A MyHashMapType.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyHashMapType
+{
+   private List<MyHashMapEntryType> entry;
+   
+   public List<MyHashMapEntryType> getEntry()
+   {
+      return entry;
+   }
+   
+   public void setEntry(List<MyHashMapEntryType> entry)
+   {
+      this.entry = entry;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeAdapter.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeAdapter.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeAdapter.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.xb.builder.object.element.javatypeadapter.support;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * A MyHashMapAdapter.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyHashMapTypeAdapter extends XmlAdapter<MyHashMapType, Map<Integer, String>>
+{
+   @Override
+   public MyHashMapType marshal(Map<Integer, String> arg0) throws Exception
+   {
+      return null;
+   }
+
+   @Override
+   public Map<Integer, String> unmarshal(MyHashMapType list) throws Exception
+   {
+      if(list == null || list.getEntry() == null)
+         return null;
+      Map<Integer, String> map = new HashMap<Integer, String>();
+      for(MyHashMapEntryType entry: list.getEntry())
+         map.put(entry.getKey(), entry.getValue());
+      return map;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeRoot.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeRoot.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapTypeRoot.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.xb.builder.object.element.javatypeadapter.support;
+
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+
+/**
+ * A Root.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+public class MyHashMapTypeRoot
+{
+   private Map<?, ?> map;
+   
+   @XmlJavaTypeAdapter(MyHashMapTypeAdapter.class)
+   public Map<?, ?> getMap()
+   {
+      return map;
+   }
+   
+   public void setMap(Map<?, ?> map)
+   {
+      this.map = map;
+   }
+}

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java	2009-10-28 15:35:21 UTC (rev 3626)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java	2009-11-02 11:31:52 UTC (rev 3627)
@@ -24,6 +24,7 @@
 import java.util.Map;
 
 import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.element.javatypeadapter.support.MyHashMapTypeRoot;
 import org.jboss.test.xb.builder.object.element.javatypeadapter.support.Root;
 
 
@@ -51,4 +52,15 @@
       assertEquals("value22", map.get(22));
       assertEquals("value333", map.get(333));
    }
+
+   public void testMyHashMapType() throws Exception
+   {
+      MyHashMapTypeRoot root = unmarshalObject(MyHashMapTypeRoot.class);
+      Map<?, ?> map = root.getMap();
+      assertNotNull(map);
+      assertEquals(3, map.size());
+      assertEquals("value1", map.get(1));
+      assertEquals("value22", map.get(22));
+      assertEquals("value333", map.get(333));
+   }
 }

Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMyHashMapType.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMyHashMapType.xml	                        (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMyHashMapType.xml	2009-11-02 11:31:52 UTC (rev 3627)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+  <map>
+    <entry key="1">value1</entry>
+    <entry key="22">value22</entry>
+    <entry key="333">value333</entry>
+  </map>
+</root>



More information about the jboss-svn-commits mailing list