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

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


            entryType = new TypeBinding();
            entryType.setSchemaBinding(schemaBinding);
            entryType.setHandler(entryHandler);

            entryTypeInfo = JBossXBBuilder.configuration.getTypeInfo(DefaultMapEntry.class);                    
            ElementBinding entryElementBinding = createElementBinding(entryTypeInfo, entryType, entryName, false);
            ParticleBinding entryParticle = new ParticleBinding(entryElementBinding, 0, -1, true);
            targetGroup.addParticle(entryParticle);
              
            propertyQName = entryName;
              
            if(keyAttribute != null)
            {
               TypeBinding attributeType = resolveTypeBinding(keyType);
               AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
               QName attrQName = generateXmlName(keyType, attributeForm, keyAttribute.namespace(), keyAttribute.name());
               AttributeBinding keyBinding = new AttributeBinding(schemaBinding, attrQName, attributeType, attributeHandler);
               keyBinding.setRequired(true);
               entryType.addAttribute(keyBinding);
            }

            if(valueAttribute != null)
            {
               TypeBinding attributeType = resolveTypeBinding(valueType);
               AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
               QName attrQName = generateXmlName(valueType, attributeForm, valueAttribute.namespace(), valueAttribute.name());
               AttributeBinding valueBinding = new AttributeBinding(schemaBinding, attrQName, attributeType, attributeHandler);
               valueBinding.setRequired(true);
               entryType.addAttribute(valueBinding);
            }
            else if(valueElement == null)
            {
               CharactersHandler charactersHandler = new ValueHandler(entryInfo.getProperty("value"), valueType);
               entryType.setSimpleType(charactersHandler);
            }
         }
        
         SequenceBinding keyValueSequence = null;
         if(keyElement != null)
         {
            keyValueSequence = new SequenceBinding(schemaBinding);                    
            if(entryType == null)
            {
               keyValueSequence.setSkip(Boolean.FALSE);
               keyValueSequence.setQName(propertyQName);
               schemaBinding.addGroup(keyValueSequence.getQName(), keyValueSequence);
               ParticleBinding keyValueParticle = new ParticleBinding(keyValueSequence, 0, -1, true);
               targetGroup.addParticle(keyValueParticle);
               keyValueSequence.setHandler(entryHandler);
            }
            else
            {
               ParticleBinding keyValueParticle = new ParticleBinding(keyValueSequence, 1, 1, false);
               entryType.setParticle(keyValueParticle);
            }
           
            // key element
            TypeBinding keyTypeBinding = resolveTypeBinding(keyType);                 
            String keyNs = keyElement.namespace();
            if(JBossXmlConstants.DEFAULT.equals(keyNs))
               keyNs = defaultNamespace;                 
            ElementBinding keyElementBinding = createElementBinding(keyType, keyTypeBinding, new QName(keyNs, keyElement.name()), false);
            ParticleBinding particle = new ParticleBinding(keyElementBinding, 1, 1, false);
            keyValueSequence.addParticle(particle);
            PropertyHandler keyHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
            entryAdapterFactory.addProperty(keyElementBinding.getQName(), keyHandler);
         }
        
         if(valueElement != null)
         {
            TypeBinding valueTypeBinding = resolveTypeBinding(valueType);                 
            String valueNs = valueElement.namespace();
            if(JBossXmlConstants.DEFAULT.equals(valueNs))
               valueNs = defaultNamespace;                 
            ElementBinding valueElementBinding = createElementBinding(valueType, valueTypeBinding, new QName(valueNs, valueElement.name()), false);
            ParticleBinding particle = new ParticleBinding(valueElementBinding, 1, 1, false);
            keyValueSequence.addParticle(particle);
            PropertyHandler valueHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
            entryAdapterFactory.addProperty(valueElementBinding.getQName(), valueHandler);
         }

         // TODO: need to verify correct binding before proceeding
         boundQName = propertyQName;
      }
      else if(entryElement != null && !JBossXmlMapEntry.DEFAULT.class.equals(entryElement.type()))
      {
         if(!JBossXmlConstants.DEFAULT.equals(entryElement.name()))
         {
            String ns = entryElement.namespace();
            if(JBossXmlConstants.DEFAULT.equals(ns))
               ns = propertyQName.getNamespaceURI();
            propertyQName = new QName(ns, entryElement.name());
         }

         TypeInfo entryTypeInfo = JBossXBBuilder.configuration.getTypeInfo(entryElement.type());
         ElementBinding entryElementBinding = createElementBinding(entryTypeInfo, propertyQName.getLocalPart(), false);
         ParticleBinding entryParticle = new ParticleBinding(entryElementBinding, 0, -1, true);
         targetGroup.addParticle(entryParticle);
         boundQName = propertyQName;
      }
      return boundQName;
View Full Code Here


      ClassMetaData bootstrapClassMetaData = new ClassMetaData();
      bootstrapClassMetaData.setImpl(BootstrapMetaData.class.getName());
      bootstrapType.setClassMetaData(bootstrapClassMetaData);
     
      // Bootstrap can take some urls
      ElementBinding urlElement = new ElementBinding(this, new QName(NAMESPACE, "url"), stringType);
      ParticleBinding urlParticle = new ParticleBinding(urlElement, 0, 1, true);
      bootstrapModel.addParticle(urlParticle);
      bootstrapType.pushInterceptor(urlElement.getQName(), new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            BootstrapMetaData bootstrap = (BootstrapMetaData) parent;
            String url = (String) child;
            List<String> bootstrapURLs = bootstrap.getBootstrapURLs();
            if (bootstrapURLs == null)
            {
               bootstrapURLs = new ArrayList<String>();
               bootstrap.setBootstrapURLs(bootstrapURLs);
            }
            bootstrapURLs.add(url);
         }
      });
     
      // The bootstrap root element
      addElement(new ElementBinding(this, new QName(NAMESPACE, "bootstrap"), bootstrapType));
   }
View Full Code Here

   {
      TermBinding term = particle.getTerm();
      Object o = startElement(parent, elementName, particle);
      if(!term.isModelGroup())
      {
         ElementBinding element = (ElementBinding)term;
         if(o != null)
         {
            attrs = element.getType().expandWithDefaultAttributes(attrs);
            attributes(o, elementName, element, attrs, nsCtx);
         }
      }
      return o;
   }
View Full Code Here

         // the wildcard this element is a content of
         WildcardBinding wildcard = null;
         if(parentTerm != null && !parentTerm.isModelGroup())
         {
            ElementBinding parentElement = (ElementBinding)parentTerm;
            TypeBinding parentType = parentElement.getType();
            wildcard = parentType.getWildcard();
            // there should be a better way of checking this
            if(wildcard != null && parentType.getElement(qName) != null)
            {
               wildcard = null;
View Full Code Here

         }
      }

      // 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;
      if(!term.isModelGroup())
      {
         TypeBinding type = ((ElementBinding)term).getType();
         if(type.getAttributes().isEmpty())
         {
            ParticleBinding typeParticle = type.getParticle();
            ModelGroupBinding modelGroup = (ModelGroupBinding)(typeParticle == null ? null : typeParticle.getTerm());
            arrayItem = modelGroup == null ? null : modelGroup.getArrayItem();

            // todo refactor later (move it to modelGroup.getArrayItem()?)
            if(arrayItem != null &&
               (arrayItem.isSkip() ||
               arrayItem.getMapEntryMetaData() != null ||
               arrayItem.getPutMethodMetaData() != null ||
               arrayItem.getAddMethodMetaData() != null
               ))
            {
               arrayItem = null;
            }
         }
      }

      if(arrayItem != null)
      {
         Class wrapperType = null;
         if(classMetaData != null)
         {
            wrapperType = loadClassForTerm(classMetaData.getImpl(),
               term.getSchema().isIgnoreUnresolvedFieldOrClass(),
               elementName
            );

            if(GenericValueContainer.class.isAssignableFrom(wrapperType) ||
               Collection.class.isAssignableFrom(wrapperType) ||
               Map.class.isAssignableFrom(wrapperType))
            {
               return newInstance(wrapperType, elementName, term.getSchema().isUseNoArgCtorIfFound());
            }
         }

         if(wrapperType == null && parent == null)
         {
            Class itemType = classForElement(arrayItem, null);
            if(itemType != null)
            {
               if(trace)
               {
                  log.trace("startElement " + elementName + " new array " + itemType.getName());
               }
               return GenericValueContainer.FACTORY.array(itemType);
            }
         }
         else
         {
            PropertyMetaData propertyMetaData = wrapperType == null ?
               term.getPropertyMetaData() : arrayItem.getPropertyMetaData();

            String propName;
            if(propertyMetaData == null)
            {
               propName = Util.xmlNameToFieldName(
                  wrapperType == null ? elementName.getLocalPart() : arrayItem.getQName().getLocalPart(),
                  term.getSchema().isIgnoreLowLine()
               );
            }
            else
            {
               propName = propertyMetaData.getName();
            }

            if(trace)
            {
               log.trace("startElement " + elementName + " property=" + propName + " wrapper=" + wrapperType);
            }

            Class parentClass = wrapperType;
            if(wrapperType == null)
            {
               if(parent instanceof GenericValueContainer)
               {
                  parentClass = ((GenericValueContainer)parent).getTargetClass();
               }
               else if(parent instanceof ValueList)
               {
                  parentClass = ((ValueList)parent).getTargetClass();
               }
               else
               {
                  parentClass = parent.getClass();
               }
            }

            Class fieldType = null;
            if(parentClass.isArray())
            {
               fieldType = parentClass.getComponentType();
            }
            else
            {
               //fieldType = FieldInfo.getFieldInfo(parentClass, propName, true).getType();
               // this was changed to false because allow overriding of handler.setParent()
               // with an interceptor.add(). See CollectionOverridePropertyUnitTestCase
               // In other words, don't treat it as an array wrapper.
               FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentClass, propName, false);
               if(fieldInfo != null)
               {
                  fieldType = fieldInfo.getType();
                  if (particle.isRepeatable() && fieldType.isArray())
                  {
                     fieldType = fieldType.getComponentType();
                  }
               }
               else if(((ElementBinding)term).getType().getInterceptors(arrayItem.getQName()).isEmpty() &&
                     arrayItem.getInterceptors().isEmpty())
               {
                  QName typeName = ((ElementBinding)term).getType().getQName();
                  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(...)");
               }
            }

            if(fieldType != null)
            {
               // TODO: review the logic for cases when wrapperType == null
               if (fieldType.isArray())
               {
                  return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
               }
               else if (Collection.class.isAssignableFrom(fieldType))
               {
                  if (wrapperType == null)
                  {
                     return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
                     //o = new ArrayList();
                  }
               }
               else
               {
                  return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
               }
            }
         }
      }

      Object o = null;
      if (mapEntryMetaData != null)
      {
         if (mapEntryMetaData.getImpl() != null)
         {
            Class cls = loadClassForTerm(mapEntryMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);

            if (trace)
            {
               log.trace("startElement " + elementName + " new map entry " + cls.getName());
            }

            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 + " 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.");
            }

            if (o instanceof MapEntry)
            {
               ((MapEntry) o).setValue(value);
            }
            else
            {
               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);
               }
            }
         }
      }
      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)
         {
            if (parent instanceof GenericValueContainer)
            {
               parentClass = ((GenericValueContainer) parent).getTargetClass();
            }
            else if (parent instanceof ValueList)
            {
               parentClass = ((ValueList) parent).getTargetClass();
            }
            else
            {
               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)
               {
                  Class simpleCls = classForSimpleType(simpleType, element.isNillable());
                  if (cls.equals(simpleCls) || cls.isPrimitive() && Classes.getPrimitiveWrapper(cls) == simpleCls
                        || simpleCls.isPrimitive() && Classes.getPrimitiveWrapper(simpleCls) == cls)
                  {
                     cls = null;
                  }
View Full Code Here

      {
         cls = SimpleTypeBindings.classForType(type.getQName().getLocalPart(), element.isNillable());
      }
      else
      {
         ElementBinding arrayItem = null;
         if(!type.isSimple() && type.getAttributes().isEmpty())
         {
            ParticleBinding typeParticle = type.getParticle();
            ModelGroupBinding modelGroup = (ModelGroupBinding)(typeParticle == null ? null : typeParticle.getTerm());
            arrayItem = modelGroup == null ? null : modelGroup.getArrayItem();
View Full Code Here

               qName +
               " bound as map entry key or value but map entry metadata is not available for its parent term.";
         }
         else
         {
            ElementBinding element = (ElementBinding)term;
            msg = "Element " +
               qName +
               " bound as map entry key or value but map entry metadata is not available for its parent element nor its " +
               (element.getType().getQName() == null ?
               "annonymous" :
               element.getType().getQName().toString()
               ) +
               " type.";
         }
         throw new JBossXBRuntimeException(msg);
      }
View Full Code Here

   {
      TermBinding term = particle.getTerm();
      Object o = startElement(parent, elementName, particle);
      if(!term.isModelGroup())
      {
         ElementBinding element = (ElementBinding)term;
         if(o != null)
         {
            attrs = element.getType().expandWithDefaultAttributes(attrs);
            attributes(o, elementName, element, attrs, nsCtx);
         }
      }
      return o;
   }
View Full Code Here

         // the wildcard this element is a content of
         WildcardBinding wildcard = null;
         if(parentTerm != null && !parentTerm.isModelGroup())
         {
            ElementBinding parentElement = (ElementBinding)parentTerm;
            TypeBinding parentType = parentElement.getType();
            wildcard = parentType.getWildcard();
            // there should be a better way of checking this
            if(wildcard != null && parentType.getElement(qName) != null)
            {
               wildcard = null;
View Full Code Here

         }
      }

      // 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;
      if(!term.isModelGroup())
      {
         TypeBinding type = ((ElementBinding)term).getType();
         if(type.getAttributes().isEmpty())
         {
            ParticleBinding typeParticle = type.getParticle();
            ModelGroupBinding modelGroup = (ModelGroupBinding)(typeParticle == null ? null : typeParticle.getTerm());
            arrayItem = modelGroup == null ? null : modelGroup.getArrayItem();

            // todo refactor later (move it to modelGroup.getArrayItem()?)
            if(arrayItem != null &&
               (arrayItem.isSkip() ||
               arrayItem.getMapEntryMetaData() != null ||
               arrayItem.getPutMethodMetaData() != null ||
               arrayItem.getAddMethodMetaData() != null
               ))
            {
               arrayItem = null;
            }
         }
      }

      if(arrayItem != null)
      {
         Class wrapperType = null;
         if(classMetaData != null)
         {
            wrapperType = loadClassForTerm(classMetaData.getImpl(),
               term.getSchema().isIgnoreUnresolvedFieldOrClass(),
               elementName
            );

            if(GenericValueContainer.class.isAssignableFrom(wrapperType) ||
               Collection.class.isAssignableFrom(wrapperType) ||
               Map.class.isAssignableFrom(wrapperType))
            {
               return newInstance(wrapperType, elementName, term.getSchema().isUseNoArgCtorIfFound());
            }
         }

         if(wrapperType == null && parent == null)
         {
            Class itemType = classForElement(arrayItem, null);
            if(itemType != null)
            {
               if(trace)
               {
                  log.trace("startElement " + elementName + " new array " + itemType.getName());
               }
               return GenericValueContainer.FACTORY.array(itemType);
            }
         }
         else
         {
            PropertyMetaData propertyMetaData = wrapperType == null ?
               term.getPropertyMetaData() : arrayItem.getPropertyMetaData();

            String propName;
            if(propertyMetaData == null)
            {
               propName = Util.xmlNameToFieldName(
                  wrapperType == null ? elementName.getLocalPart() : arrayItem.getQName().getLocalPart(),
                  term.getSchema().isIgnoreLowLine()
               );
            }
            else
            {
               propName = propertyMetaData.getName();
            }

            if(trace)
            {
               log.trace("startElement " + elementName + " property=" + propName);
            }

            Class parentClass = wrapperType;
            if(wrapperType == null)
            {
               if(parent instanceof GenericValueContainer)
               {
                  parentClass = ((GenericValueContainer)parent).getTargetClass();
               }
               else if(parent instanceof ValueList)
               {
                  parentClass = ((ValueList)parent).getTargetClass();
               }
               else
               {
                  parentClass = parent.getClass();
               }
            }

            Class fieldType = null;
            if(parentClass.isArray())
            {
               fieldType = parentClass.getComponentType();
            }
            else
            {
               //fieldType = FieldInfo.getFieldInfo(parentClass, propName, true).getType();
               // this was changed to false because allow overriding of handler.setParent()
               // with an interceptor.add(). See CollectionOverridePropertyUnitTestCase
               // In other words, don't treat it as an array wrapper.
               FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentClass, propName, false);
               if(fieldInfo != null)
               {
                  fieldType = fieldInfo.getType();
                  if (particle.isRepeatable() && fieldType.isArray())
                  {
                     fieldType = fieldType.getComponentType();
                  }
               }
               else if(arrayItem.getInterceptors().isEmpty())
               {
                  QName typeName = ((ElementBinding)term).getType().getQName();
                  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(...)");
               }
            }

            if(fieldType.isArray())
            {
               return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
            }
            else if(Collection.class.isAssignableFrom(fieldType))
            {
               if (wrapperType == null)
               {
                  return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
                  //o = ArrayList();
               }
            }
            else
            {
               return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
            }
         }
      }

      Object o = null;
         if(mapEntryMetaData != null)
         {
            if(mapEntryMetaData.getImpl() != null)
            {
               Class cls = loadClassForTerm(mapEntryMetaData.getImpl(),
                  term.getSchema().isIgnoreUnresolvedFieldOrClass(),
                  elementName
               );

               if(trace)
               {
                  log.trace("startElement " + elementName + " new map entry " + cls.getName());
               }

               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 + " 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."
                  );
               }

               if(o instanceof MapEntry)
               {
                  ((MapEntry)o).setValue(value);
               }
               else
               {
                  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
                     );
                  }
               }
            }
         }
         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)
            {
               if(parent instanceof GenericValueContainer)
               {
                  parentClass = ((GenericValueContainer)parent).getTargetClass();
               }
               else if(parent instanceof ValueList)
               {
                  parentClass = ((ValueList)parent).getTargetClass();
               }
               else
               {
                  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)
                  {
                     Class simpleCls = classForSimpleType(simpleType, element.isNillable());
                     if(cls.equals(simpleCls) ||
                        cls.isPrimitive() && Classes.getPrimitiveWrapper(cls) == simpleCls ||
                        simpleCls.isPrimitive() && Classes.getPrimitiveWrapper(simpleCls) == cls)
                     {
                        cls = null;
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.sunday.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.