Package org.jboss.xb.binding.sunday.unmarshalling

Examples of org.jboss.xb.binding.sunday.unmarshalling.TermBinding


/*   99 */     return o;
/*      */   }
/*      */
/*      */   public void setParent(Object parent, Object o, QName qName, ParticleBinding particle, ParticleBinding parentParticle)
/*      */   {
/*  108 */     TermBinding term = particle.getTerm();
/*  109 */     if (term.isSkip())
/*      */     {
/*  111 */       return;
/*      */     }
/*      */
/*  114 */     boolean trace = log.isTraceEnabled();
/*  115 */     if (trace)
/*      */     {
/*  117 */       log.trace("setParent " + qName + " parent=" + parent + " object=" + o + " term=" + term);
/*      */     }
/*      */
/*  120 */     TermBinding parentTerm = parentParticle.getTerm();
/*      */
/*  122 */     if (term.isMapEntryKey())
/*      */     {
/*  124 */       if (trace)
/*      */       {
/*  126 */         log.trace("setParent " + qName + " mapKey");
/*      */       }
/*      */
/*  129 */       if ((parent instanceof MapEntry))
/*      */       {
/*  131 */         MapEntry mapEntry = (MapEntry)parent;
/*  132 */         mapEntry.setKey(o);
/*      */       }
/*  134 */       else if (parentTerm != null)
/*      */       {
/*  136 */         MapEntryMetaData mapEntryMetaData = getMapEntryMetaData(parentTerm, qName);
/*      */
/*  138 */         String getKeyMethodName = mapEntryMetaData.getGetKeyMethod();
/*  139 */         if (getKeyMethodName == null)
/*      */         {
/*  141 */           getKeyMethodName = "getKey";
/*      */         }
/*      */
/*  144 */         String setKeyMethodName = mapEntryMetaData.getSetKeyMethod();
/*  145 */         if (setKeyMethodName == null)
/*      */         {
/*  147 */           setKeyMethodName = "setKey";
/*      */         }
/*      */
/*  150 */         Class parentCls = parent.getClass();
/*  151 */         Method setKeyMethod = getSetMethod(parentCls, getKeyMethodName, setKeyMethodName);
/*  152 */         invokeSetter(setKeyMethod, parent, o, setKeyMethodName);
/*      */       }
/*      */       else
/*      */       {
/*  156 */         throw new JBossXBRuntimeException("Element " + qName + " bound as map entry key but parent element is not recognized as map entry and its metadata is not available.");
/*      */       }
/*      */
/*      */     }
/*  163 */     else if (term.isMapEntryValue())
/*      */     {
/*  165 */       if (trace)
/*      */       {
/*  167 */         log.trace("setParent " + qName + " mapValue");
/*      */       }
/*      */
/*  170 */       if ((parent instanceof MapEntry))
/*      */       {
/*  172 */         MapEntry mapEntry = (MapEntry)parent;
/*  173 */         mapEntry.setValue(o);
/*      */       }
/*  175 */       else if (parentTerm != null)
/*      */       {
/*  177 */         MapEntryMetaData mapEntryMetaData = getMapEntryMetaData(parentTerm, qName);
/*  178 */         setMapEntryValue(mapEntryMetaData, parent, o);
/*      */       }
/*      */       else
/*      */       {
/*  182 */         throw new JBossXBRuntimeException("Element " + qName + " bound as map entry key but parent element is not recognized as map entry and its metadata is not available.");
/*      */       }
/*      */
/*      */     }
/*      */     else
/*      */     {
/*  191 */       Object owner = parent;
/*  192 */       if ((parent instanceof MapEntry))
/*      */       {
/*  194 */         if (trace)
/*      */         {
/*  196 */           log.trace("setParent " + qName + " mapEntry");
/*      */         }
/*      */
/*  199 */         MapEntry mapEntry = (MapEntry)parent;
/*  200 */         owner = mapEntry.getValue();
/*  201 */         if (owner == null)
/*      */         {
/*  203 */           if (parentTerm == null)
/*      */           {
/*  205 */             throw new JBossXBRuntimeException("Binding metadata needed for lazy map entry value instantiation is not available for parent element of element " + qName);
/*      */           }
/*      */
/*  211 */           MapEntryMetaData mapEntryMetaData = getMapEntryMetaData(parentTerm, qName);
/*  212 */           String valueType = mapEntryMetaData.getValueType();
/*  213 */           if (valueType == null)
/*      */           {
/*  215 */             throw new JBossXBRuntimeException("Element " + qName + " is supposed to be bound as map entry value with lazy value instantiation " + "but value type is not specified in its map entry metadata.");
/*      */           }
/*      */
/*      */           Class valueCls;
/*      */           try
/*      */           {
/*  225 */             valueCls = Thread.currentThread().getContextClassLoader().loadClass(valueType);
/*      */           }
/*      */           catch (ClassNotFoundException e)
/*      */           {
/*  229 */             throw new JBossXBRuntimeException("Failed to load value type specified in the map entry metadata: " + valueType);
/*      */           }
/*      */
/*      */           try
/*      */           {
/*  236 */             owner = valueCls.newInstance();
/*      */           }
/*      */           catch (Exception e)
/*      */           {
/*  240 */             throw new JBossXBRuntimeException("Failed to create an instance of value type " + valueType + ": " + e.getMessage());
/*      */           }
/*      */
/*  245 */           setMapEntryValue(mapEntryMetaData, parent, owner);
/*      */         }
/*      */
/*      */       }
/*      */
/*  250 */       WildcardBinding wildcard = null;
/*  251 */       if ((parentTerm != null) && (!parentTerm.isModelGroup()))
/*      */       {
/*  253 */         ElementBinding parentElement = (ElementBinding)parentTerm;
/*  254 */         TypeBinding parentType = parentElement.getType();
/*  255 */         wildcard = parentType.getWildcard();
/*      */
View Full Code Here


/*      */     }
/*      */   }
/*      */
/*      */   public Object endParticle(Object o, QName elementName, ParticleBinding particle)
/*      */   {
/*  330 */     TermBinding term = particle.getTerm();
/*  331 */     if (term.isSkip())
/*      */     {
/*  333 */       return o;
/*      */     }
/*      */
/*  336 */     boolean trace = log.isTraceEnabled();
View Full Code Here

/*  365 */     return o;
/*      */   }
/*      */
/*      */   private Object startElement(Object parent, QName elementName, ParticleBinding particle)
/*      */   {
/*  372 */     TermBinding term = particle.getTerm();
/*  373 */     if (term.isSkip())
/*      */     {
/*  375 */       return parent;
/*      */     }
/*      */
/*  378 */     boolean trace = log.isTraceEnabled();
/*  379 */     if (trace)
/*      */     {
/*  381 */       log.trace("startElement " + elementName + " parent=" + parent + " term=" + term);
/*      */     }
/*      */
/*  384 */     ClassMetaData classMetaData = term.getClassMetaData();
/*  385 */     MapEntryMetaData mapEntryMetaData = term.getMapEntryMetaData();
/*      */
/*  387 */     if (!term.isModelGroup())
/*      */     {
/*  389 */       TypeBinding type = ((ElementBinding)term).getType();
/*  390 */       if ((type.isSimple()) || ((classMetaData == null) && (mapEntryMetaData == null) && ((!type.isStartElementCreatesObject()) || (Constants.QNAME_ANYTYPE.equals(type.getQName())))))
/*      */       {
/*  395 */         if (trace)
/*      */         {
/*  397 */           log.trace("startElement " + elementName + " does not create an object");
/*      */         }
/*  399 */         return null;
/*      */       }
/*      */
/*      */     }
/*      */
/*  405 */     ElementBinding arrayItem = null;
/*  406 */     if (!term.isModelGroup())
/*      */     {
/*  408 */       TypeBinding type = ((ElementBinding)term).getType();
/*  409 */       if (type.getAttributes().isEmpty())
/*      */       {
/*  411 */         ParticleBinding typeParticle = type.getParticle();
/*  412 */         ModelGroupBinding modelGroup = (ModelGroupBinding)(typeParticle == null ? null : typeParticle.getTerm());
/*  413 */         arrayItem = modelGroup == null ? null : modelGroup.getArrayItem();
/*      */
/*  416 */         if ((arrayItem != null) && ((arrayItem.isSkip()) || (arrayItem.getMapEntryMetaData() != null) || (arrayItem.getPutMethodMetaData() != null) || (arrayItem.getAddMethodMetaData() != null)))
/*      */         {
/*  423 */           arrayItem = null;
/*      */         }
/*      */       }
/*      */     }
/*      */
/*  428 */     if (arrayItem != null)
/*      */     {
/*  430 */       Class wrapperType = null;
/*  431 */       if (classMetaData != null)
/*      */       {
/*  433 */         wrapperType = loadClassForTerm(classMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
/*      */
/*  438 */         if ((GenericValueContainer.class.isAssignableFrom(wrapperType)) || (Collection.class.isAssignableFrom(wrapperType)) || (Map.class.isAssignableFrom(wrapperType)))
/*      */         {
/*  442 */           return newInstance(wrapperType, elementName, term.getSchema().isUseNoArgCtorIfFound());
/*      */         }
/*      */       }
/*      */
/*  446 */       if ((wrapperType == null) && (parent == null))
/*      */       {
/*  448 */         Class itemType = classForElement(arrayItem, null);
/*  449 */         if (itemType != null)
/*      */         {
/*  451 */           if (trace)
/*      */           {
/*  453 */             log.trace("startElement " + elementName + " new array " + itemType.getName());
/*      */           }
/*  455 */           return GenericValueContainer.FACTORY.array(itemType);
/*      */         }
/*      */       }
/*      */       else
/*      */       {
/*  460 */         PropertyMetaData propertyMetaData = wrapperType == null ? term.getPropertyMetaData() : arrayItem.getPropertyMetaData();
/*      */         String propName;
/*      */         String propName;
/*  464 */         if (propertyMetaData == null)
/*      */         {
/*  466 */           propName = Util.xmlNameToFieldName(wrapperType == null ? elementName.getLocalPart() : arrayItem.getQName().getLocalPart(), term.getSchema().isIgnoreLowLine());
/*      */         }
/*      */         else
/*      */         {
/*  473 */           propName = propertyMetaData.getName();
/*      */         }
/*      */
/*  476 */         if (trace)
/*      */         {
/*  478 */           log.trace("startElement " + elementName + " property=" + propName + " wrapper=" + wrapperType);
/*      */         }
/*      */
/*  481 */         Class parentClass = wrapperType;
/*  482 */         if (wrapperType == null)
/*      */         {
/*  484 */           if ((parent instanceof GenericValueContainer))
/*      */           {
/*  486 */             parentClass = ((GenericValueContainer)parent).getTargetClass();
/*      */           }
/*  488 */           else if ((parent instanceof ValueList))
/*      */           {
/*  490 */             parentClass = ((ValueList)parent).getTargetClass();
/*      */           }
/*      */           else
/*      */           {
/*  494 */             parentClass = parent.getClass();
/*      */           }
/*      */         }
/*      */
/*  498 */         Class fieldType = null;
/*  499 */         if (parentClass.isArray())
/*      */         {
/*  501 */           fieldType = parentClass.getComponentType();
/*      */         }
/*      */         else
/*      */         {
/*  509 */           FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentClass, propName, false);
/*  510 */           if (fieldInfo != null)
/*      */           {
/*  512 */             fieldType = fieldInfo.getType();
/*  513 */             if ((particle.isRepeatable()) && (fieldType.isArray()))
/*      */             {
/*  515 */               fieldType = fieldType.getComponentType();
/*      */             }
/*      */           }
/*  518 */           else if ((((ElementBinding)term).getType().getInterceptors(arrayItem.getQName()).isEmpty()) && (arrayItem.getInterceptors().isEmpty()))
/*      */           {
/*  521 */             QName typeName = ((ElementBinding)term).getType().getQName();
/*  522 */             throw new JBossXBRuntimeException("Couldn't apply 'array wrapper' pattern for element " + elementName + " of type " + (typeName == null ? "anonymous" : typeName.toString()) + ": failed to resolve property " + propName + " and no interceptors applied to override handler.setParent(...)");
/*      */           }
/*      */
/*      */         }
/*      */
/*  531 */         if (fieldType != null)
/*      */         {
/*  534 */           if (fieldType.isArray())
/*      */           {
/*  536 */             return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
/*      */           }
/*  538 */           if (Collection.class.isAssignableFrom(fieldType))
/*      */           {
/*  540 */             if (wrapperType == null)
/*      */             {
/*  542 */               return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
/*      */             }
/*      */
/*      */           }
/*      */           else
/*      */           {
/*  548 */             return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */
/*  554 */     Object o = null;
/*  555 */     if (mapEntryMetaData != null)
/*      */     {
/*  557 */       if (mapEntryMetaData.getImpl() != null)
/*      */       {
/*  559 */         Class cls = loadClassForTerm(mapEntryMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
/*      */
/*  561 */         if (trace)
/*      */         {
/*  563 */           log.trace("startElement " + elementName + " new map entry " + cls.getName());
/*      */         }
/*      */
/*  566 */         o = newInstance(cls, elementName, term.getSchema().isUseNoArgCtorIfFound());
/*      */       }
/*      */       else
/*      */       {
/*  570 */         o = new MapEntry();
/*  571 */         if (trace)
/*      */         {
/*  573 */           log.trace("startElement " + elementName + " new map entry");
/*      */         }
/*      */       }
/*      */
/*  577 */       if ((mapEntryMetaData.isNonNullValue()) && (mapEntryMetaData.getValueType() != null))
/*      */       {
/*      */         Class mapValueType;
/*      */         try {
/*  582 */           mapValueType = Thread.currentThread().getContextClassLoader().loadClass(mapEntryMetaData.getValueType());
/*      */         }
/*      */         catch (ClassNotFoundException e)
/*      */         {
/*  586 */           throw new JBossXBRuntimeException("startElement failed for " + elementName + ": failed to load class " + mapEntryMetaData.getValueType() + " for map entry value.");
/*      */         }
/*      */
/*      */         Object value;
/*      */         try
/*      */         {
/*  593 */           if (trace)
/*      */           {
/*  595 */             log.trace("startElement " + elementName + " map value type " + mapEntryMetaData.getValueType());
/*      */           }
/*  597 */           value = mapValueType.newInstance();
/*      */         }
/*      */         catch (Exception e)
/*      */         {
/*  601 */           throw new JBossXBRuntimeException("startElement failed for " + elementName + ": failed to create an instance of " + mapValueType + " for map entry value.");
/*      */         }
/*      */
/*  605 */         if ((o instanceof MapEntry))
/*      */         {
/*  607 */           ((MapEntry)o).setValue(value);
/*      */         }
/*      */         else
/*      */         {
/*  611 */           String getValueMethodName = mapEntryMetaData.getGetValueMethod();
/*  612 */           if (getValueMethodName == null)
/*      */           {
/*  614 */             getValueMethodName = "getValue";
/*      */           }
/*      */
/*  617 */           String setValueMethodName = mapEntryMetaData.getSetValueMethod();
/*  618 */           if (setValueMethodName == null)
/*      */           {
/*  620 */             setValueMethodName = "setValue";
/*      */           }
/*      */           Method getValueMethod;
/*      */           try
/*      */           {
/*  626 */             getValueMethod = o.getClass().getMethod(getValueMethodName, null);
/*      */           }
/*      */           catch (NoSuchMethodException e)
/*      */           {
/*  630 */             throw new JBossXBRuntimeException("getValueMethod=" + getValueMethodName + " is not found in map entry " + o.getClass());
/*      */           }
/*      */
/*      */           Method setValueMethod;
/*      */           try
/*      */           {
/*  637 */             setValueMethod = o.getClass().getMethod(setValueMethodName, new Class[] { getValueMethod.getReturnType() });
/*      */           }
/*      */           catch (NoSuchMethodException e)
/*      */           {
/*  641 */             throw new JBossXBRuntimeException("setValueMethod=" + setValueMethodName + "(" + getValueMethod.getReturnType().getName() + " value) is not found in map entry " + o.getClass());
/*      */           }
/*      */
/*      */           try
/*      */           {
/*  648 */             setValueMethod.invoke(o, new Object[] { value });
/*      */           }
/*      */           catch (Exception e)
/*      */           {
/*  653 */             throw new JBossXBRuntimeException("setValueMethod=" + setValueMethodName + " failed: owner=" + o + ", value=" + value + ", msg=" + e.getMessage(), e);
/*      */           }
/*      */
/*      */         }
/*      */
/*      */       }
/*      */
/*      */     }
/*      */     else
/*      */     {
/*  663 */       Class parentClass = null;
/*  664 */       if (parent != null)
/*      */       {
/*  666 */         if ((parent instanceof GenericValueContainer))
/*      */         {
/*  668 */           parentClass = ((GenericValueContainer)parent).getTargetClass();
/*      */         }
/*  670 */         else if ((parent instanceof ValueList))
/*      */         {
/*  672 */           parentClass = ((ValueList)parent).getTargetClass();
/*      */         }
/*      */         else
/*      */         {
/*  676 */           parentClass = parent.getClass();
/*      */         }
/*      */       }
/*      */       Class cls;
/*      */       Class cls;
/*  681 */       if (term.isModelGroup())
/*      */       {
/*  683 */         if (classMetaData == null)
/*      */         {
/*  685 */           throw new JBossXBRuntimeException("Model groups should be annotated with 'class' annotation to be bound.");
/*      */         }
/*      */
/*  688 */         cls = loadClassForTerm(classMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
/*      */       }
/*      */       else
/*      */       {
/*  692 */         ElementBinding element = (ElementBinding)term;
/*  693 */         cls = classForNonArrayItem(element, parentClass);
/*  694 */         if (cls != null)
/*      */         {
/*  697 */           TypeBinding simpleType = element.getType().getSimpleType();
/*  698 */           if (simpleType != null)
/*      */           {
/*  700 */             Class simpleCls = classForSimpleType(simpleType, element.isNillable());
/*  701 */             if ((cls.equals(simpleCls)) || ((cls.isPrimitive()) && (Classes.getPrimitiveWrapper(cls) == simpleCls)) || ((simpleCls.isPrimitive()) && (Classes.getPrimitiveWrapper(simpleCls) == cls)))
/*      */             {
/*  704 */               cls = null;
/*      */             }
/*      */           }
/*      */         }
/*      */       }
/*      */
/*  710 */       if (cls != null)
/*      */       {
/*      */         boolean noArgCtor;
/*      */         boolean noArgCtor;
/*  713 */         if (classMetaData == null)
/*      */         {
/*  715 */           noArgCtor = term.getSchema().isUseNoArgCtorIfFound();
/*      */         }
/*      */         else
/*      */         {
/*  719 */           Boolean termUsesNoArgCtor = classMetaData.isUseNoArgCtor();
/*  720 */           noArgCtor = termUsesNoArgCtor == null ? term.getSchema().isUseNoArgCtorIfFound() : termUsesNoArgCtor.booleanValue();
/*      */         }
/*      */
/*  724 */         if (trace)
/*      */         {
/*  726 */           log.trace("startElement " + elementName + " new " + cls.getName() + ", noArgCtor=" + noArgCtor);
View Full Code Here

      try
      {
         SchemaBinding schema = JBossXBBuilder.build(Root.class);
         ElementBinding e = schema.getElement(new QName("root"));
         assertNotNull(e);
         TermBinding t = e.getType().getParticle().getTerm();
         assertTrue(t instanceof SequenceBinding);
         Collection<ParticleBinding> particles = ((SequenceBinding) t).getParticles();
         assertEquals(3, particles.size());
         Iterator<ParticleBinding> i = particles.iterator();
View Full Code Here

      });

      ModelGroupBinding valueGroup = schemaBinding.getGroup(valueGroupQName);
      for(Iterator<?> i = valueGroup.getParticles().iterator(); i.hasNext();)
      {
         TermBinding term = ((ParticleBinding)i.next()).getTerm();
         if(!term.isWildcard())
         {
            ElementBinding e = (ElementBinding) term;
            if(e.getQName().equals(nullQName))
            {
               e.pushInterceptor(NULLVALUES);
View Full Code Here

         idElement = (ElementBinding) iterator.next().getTerm();
      }
      else
      {
         assertTrue(group instanceof UnorderedSequenceBinding);
         TermBinding t = iterator.next().getTerm();
         if(t.isElement())
         {
            idElement = (ElementBinding) t;
            group = (ModelGroupBinding) iterator.next().getTerm();
         }
         else
View Full Code Here

         idElement = (ElementBinding) iterator.next().getTerm();
      }
      else
      {
         assertTrue(group instanceof UnorderedSequenceBinding);
         TermBinding t = iterator.next().getTerm();
         if(t.isElement())
         {
            idElement = (ElementBinding) t;
            group = (ModelGroupBinding) iterator.next().getTerm();
         }
         else
View Full Code Here

         idElement = (ElementBinding) iterator.next().getTerm();
      }
      else
      {
         assertTrue(group instanceof UnorderedSequenceBinding);
         TermBinding t = iterator.next().getTerm();
         if(t.isElement())
         {
            idElement = (ElementBinding) t;
            group = (ModelGroupBinding) iterator.next().getTerm();
         }
         else
View Full Code Here

         idElement = (ElementBinding) iterator.next().getTerm();
      }
      else
      {
         assertTrue(group instanceof UnorderedSequenceBinding);
         TermBinding t = iterator.next().getTerm();
         if(t.isElement())
         {
            idElement = (ElementBinding) t;
            group = (ModelGroupBinding) iterator.next().getTerm();
         }
         else
View Full Code Here

   public void setParent(Object parent, Object o, QName qName,  ParticleBinding particle, ParticleBinding parentParticle)
   {
      if (trace)
         log.trace("setParent " + qName + " parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o));

      TermBinding term = particle.getTerm();
      ValueAdapter valueAdapter = null;
      if(term.isModelGroup())
      {
         QName modelGroupName = ((ModelGroupBinding)term).getQName();
         if(modelGroupName != null)
         {
            qName = modelGroupName;
         }
      }
      else if(term.isElement())
      {
         valueAdapter = ((ElementBinding)term).getValueAdapter();
      }

      if (parent != null && parent instanceof ArrayWrapper)
      {
         ArrayWrapper wrapper = (ArrayWrapper) parent;
         wrapper.add(o);
         wrapper.setChildParticle(particle);
         wrapper.setParentParticle(parentParticle);
         return;
      }

      BeanAdapter beanAdapter;
      if (parent instanceof ArrayWrapper)
         beanAdapter = (BeanAdapter) ((ArrayWrapper) parent).getParent();
      else
         beanAdapter = (BeanAdapter) parent;
      AbstractPropertyHandler propertyHandler = beanAdapter.getPropertyHandler(qName);
      if (propertyHandler == null)
      {
         AbstractPropertyHandler wildcardHandler = beanAdapter.getWildcardHandler();
         if (wildcardHandler != null)
         {
            if (o != null && o instanceof ArrayWrapper)
            {
               ArrayWrapper wrapper = (ArrayWrapper) o;
               wildcardHandler.doHandle(beanAdapter, wrapper, wrapper.getElementName());
               return;
            }
         }
         TermBinding element = term;
         if (element.getSchema().isStrictSchema())
         {
            throw new RuntimeException("QName " + qName + " unknown property parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o) + " available=" + beanAdapter.getAvailable());
         }
         if (trace)
            log.trace("QName " + qName + " unknown property parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o));
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.sunday.unmarshalling.TermBinding

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.