Package org.jboss.xb.binding.metadata.unmarshalling

Examples of org.jboss.xb.binding.metadata.unmarshalling.ElementBinding


         {
            stack = new ElementBindingStack(doc, elementName);
            for(int i = 0; i < delegates.size(); ++i)
            {
               AbstractBasicElementBinding el = (AbstractBasicElementBinding)delegates.get(i);
               ElementBinding local = el.getElementLocal(elementName);
               if(local != null)
               {
                  stack.push(local);
               }
            }
View Full Code Here


         log.trace("newChild " + namespaceURI + ":" + localName + " for " + parent);
      }

      Object child;

      ElementBinding metadata = (ElementBinding)ctx.getMetadata();
      if(metadata == null)
      {
         throw new JBossXBRuntimeException(
            "Binding metadata is not available for element {" + namespaceURI + ":" + localName + "}"
         );
      }

      if(Collection.class.isAssignableFrom(metadata.getJavaType()))
      {
         Collection col;
         if(parent instanceof Immutable)
         {
            Immutable imm = (Immutable)parent;
            col = (Collection)imm.getChild(localName);
            if(col == null)
            {
               col = (Collection)newInstance(metadata);
               imm.addChild(localName, col);
            }
         }
         else
         {
            col = (Collection)getFieldValue(metadata, parent);
            if(col == null)
            {
               col = (Collection)newInstance(metadata);
               setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, col);
            }
         }

         child = col;
      }
      else if(!Util.isAttributeType(metadata.getJavaType()))
      {
         child = newInstance(metadata);
         if(!(child instanceof Immutable))
         {
            if(parent instanceof Collection)
            {
               ((Collection)parent).add(child);
            }
            else if(parent instanceof Immutable)
            {
               ((Immutable)parent).addChild(localName, child);
            }
            else if(metadata.getFieldType() != null && Collection.class.isAssignableFrom(metadata.getFieldType()))
            {
               Collection col = (Collection)getFieldValue(metadata, parent);
               if(col == null)
               {
                  if(Set.class.isAssignableFrom(metadata.getFieldType()))
                  {
                     col = new HashSet();
                  }
                  else
                  {
                     col = new ArrayList();
                  }
                  setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, col);
               }
               col.add(child);
            }
            else
            {
               setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, child);
            }
         }

         if(attrs != null && attrs.getLength() > 0)
         {
            for(int i = 0; i < attrs.getLength(); ++i)
            {
               QName attrName = new QName(attrs.getURI(i), attrs.getLocalName(i));
               AttributeBinding attrBinding = metadata.getAttribute(attrName);
               if(attrBinding != null)
               {
                  Object unmarshalledValue = SimpleTypeBindings.unmarshal(attrs.getValue(i),
                     attrBinding.getJavaType()
                  );
View Full Code Here

   public void addChild(Object parent, Object child, UnmarshallingContext ctx, String namespaceURI, String localName)
   {
      if(child instanceof Immutable)
      {
         ElementBinding metadata = (ElementBinding)ctx.getMetadata();

         child = ((Immutable)child).newInstance();
         if(parent instanceof Collection)
         {
            ((Collection)parent).add(child);
         }
         else if(metadata.getFieldType() == null || Collection.class.isAssignableFrom(metadata.getFieldType()))
         {
            Collection col;
            if(parent instanceof Immutable)
            {
               Immutable imm = (Immutable)parent;
               col = (Collection)imm.getChild(localName);
               if(col == null)
               {
                  col = new ArrayList();
                  imm.addChild(localName, col);
               }
            }
            else
            {
               col = (Collection)getFieldValue(metadata, parent);
               if(col == null)
               {
                  col = new ArrayList();
                  setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, col);
               }
            }

            col.add(child);
         }
         else if(parent instanceof Immutable)
         {
            ((Immutable)parent).addChild(localName, child);
         }
         else
         {
            setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, child);
         }
      }
   }
View Full Code Here

      }
   }

   public void setValue(Object o, UnmarshallingContext ctx, String namespaceURI, String localName, String value)
   {
      ElementBinding metadata = (ElementBinding)ctx.getMetadata();

      // todo: this check is a hack! undeterminism when field is of type collection and there is only RuntimeDocumentBinding
      if(Collection.class.isAssignableFrom(metadata.getJavaType()))
      {
         ((Collection)o).add(value);
      }
      else
      {
         if(Util.isAttributeType(metadata.getJavaType()))
         {
            Object unmarshalledValue = SimpleTypeBindings.unmarshal(value, metadata.getJavaType());
            if(o instanceof Collection)
            {
               ((Collection)o).add(unmarshalledValue);
            }
            else if(o instanceof Immutable)
            {
               ((Immutable)o).addChild(localName, unmarshalledValue);
            }
            else
            {
               if(Collection.class.isAssignableFrom(metadata.getFieldType()))
               {
                  Collection col = (Collection)getFieldValue(metadata, o);
                  if(col == null)
                  {
                     col = new ArrayList();
                     setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), o, col);
                  }
                  col.add(unmarshalledValue);
               }
               else
               {
                  setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), o, unmarshalledValue);
               }
            }
         }
         else
         {
            XmlValueBinding valueBinding = metadata.getValue();
            if(valueBinding == null)
            {
               throw new JBossXBRuntimeException(
                  "Required value binding is not customized for " + metadata.getName() + ": value=" + value
               );
            }

            unmarshalValue(valueBinding, value, o);
         }
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.metadata.unmarshalling.ElementBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.