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

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


   {
      TypeBinding type = element.getType();
      for(int i = 0; i < attrs.getLength(); ++i)
      {
         QName attrName = new QName(attrs.getURI(i), attrs.getLocalName(i));
         AttributeBinding binding = type.getAttribute(attrName);
         if(binding != null)
         {
            AttributeHandler handler = binding.getHandler();
            if(handler != null)
            {
               Object value = handler.unmarshal(elementName, attrName, binding, nsCtx, attrs.getValue(i));
               handler.attribute(elementName, attrName, binding, o, value);
            }
View Full Code Here


                  attributeTypeInfo = attributeTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlAttribute.type());
               TypeBinding attributeType = resolveTypeBinding(attributeTypeInfo);
               // Create the attribute handler
               AttributeHandler attributeHandler = new PropertyHandler(property, attributeTypeInfo);
               // Create the attributre and bind it to the type
               AttributeBinding attribute = new AttributeBinding(schemaBinding, qName, attributeType, attributeHandler);
               attribute.setRequired(xmlAttribute.required());
               typeBinding.addAttribute(attribute);
               if (trace)
                  log.trace("Bound attribute " + qName + " type=" + beanInfo.getName() + " property=" + property.getName() + " propertyType=" + attributeTypeInfo);
            }
View Full Code Here

               TypeBinding attributeType = resolveTypeBinding(keyType);
               AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
               String attrNs = keyAttribute.namespace();
               if(JBossXmlConstants.DEFAULT.equals(attrNs))
                  attrNs = defaultNamespace;
               AttributeBinding keyBinding = new AttributeBinding(schemaBinding, new QName(attrNs, keyAttribute.name()), attributeType, attributeHandler);
               keyBinding.setRequired(true);
               entryType.addAttribute(keyBinding);
            }

            if(valueAttribute != null)
            {
               TypeBinding attributeType = resolveTypeBinding(valueType);
               AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
               String valueNs = valueAttribute.namespace();
               if(JBossXmlConstants.DEFAULT.equals(valueNs))
                  valueNs = defaultNamespace;
               AttributeBinding valueBinding = new AttributeBinding(schemaBinding, new QName(valueNs, valueAttribute.name()), attributeType, attributeHandler);
               valueBinding.setRequired(true);
               entryType.addAttribute(valueBinding);
            }
            else if(valueElement == null)
            {
               CharactersHandler charactersHandler = new ValueHandler(entryInfo.getProperty("value"), valueType);
View Full Code Here

                  attributeTypeInfo = attributeTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlAttribute.type());
               TypeBinding attributeType = resolveTypeBinding(attributeTypeInfo);
               // Create the attribute handler
               AttributeHandler attributeHandler = new PropertyHandler(property, attributeTypeInfo);
               // Create the attributre and bind it to the type
               AttributeBinding attribute = new AttributeBinding(schemaBinding, qName, attributeType, attributeHandler);
               attribute.setRequired(xmlAttribute.required());
               typeBinding.addAttribute(attribute);
               JBossXmlPreserveWhitespace preserveSpace = property.getUnderlyingAnnotation(JBossXmlPreserveWhitespace.class);
               if(preserveSpace != null)
                  attribute.setNormalizeSpace(preserveSpace.preserve() ? false : true);
               if (trace)
                  log.trace("Bound attribute " + qName + " type=" + beanInfo.getName() + " property=" + property.getName() + " propertyType=" + attributeTypeInfo + ", normalizeSpace=" + attribute.isNormalizeSpace());
            }

            // Is this any attribute
            XmlAnyAttribute xmlAnyAttribute = property.getUnderlyingAnnotation(XmlAnyAttribute.class);
            if (xmlAnyAttribute != null)
View Full Code Here

            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);
View Full Code Here

  
   public Object getValue(MarshallingContext ctx)
   {
      Object owner = ctx.peek();
      SchemaBinding schema = ctx.getSchemaBinding();
      AttributeBinding binding = ctx.getAttributeBinding();
      QName qName = binding.getQName();

      String fieldName = null;
      PropertyMetaData propertyMetaData = binding.getPropertyMetaData();
      if(propertyMetaData != null)
      {
         fieldName = propertyMetaData.getName();
      }

      if(fieldName == null)
      {
         fieldName =
            Util.xmlNameToFieldName(qName.getLocalPart(), schema.isIgnoreLowLine());
      }

      FieldInfo fieldInfo = FieldInfo.getFieldInfo(
         owner.getClass(), fieldName, binding.getRequired() && !schema.isIgnoreUnresolvedFieldOrClass()
      );
      Object value = null;
      if(fieldInfo != null)
      {
         value = fieldInfo.getValue(owner);
View Full Code Here

      return value;
   }

   public String marshalValue(MarshallingContext ctx, Object value)
   {
      AttributeBinding binding = ctx.getAttributeBinding();

      if(value == null)
      {
         if(binding.getRequired())
         {
            ElementBinding element = (ElementBinding) ctx.getParticleBinding().getTerm();
            throw new JBossXBRuntimeException("Missing value for the required attribute " + binding.getQName() + " of element " + element.getQName());
         }  
         return null;
      }

      String marshalled;

      TypeBinding attrType = binding.getType();

      if(attrType.getItemType() != null)
      {
         TypeBinding itemType = attrType.getItemType();
         if(Constants.NS_XML_SCHEMA.equals(itemType.getQName().getNamespaceURI()))
         {
            List<QName> list;
            if(value instanceof List)
            {
               list = (List<QName>)value;
            }
            else if(value.getClass().isArray())
            {
               list = Arrays.asList((QName[])value);
            }
            else
            {
               throw new JBossXBRuntimeException("Expected value for list type is an array or " +
                  List.class.getName() +
                  " but got: " +
                  value
               );
            }

            if(Constants.QNAME_QNAME.getLocalPart().equals(itemType.getQName().getLocalPart()))
            {
               String attrLocal = binding.getQName().getLocalPart();
               for(int listInd = 0; listInd < list.size(); ++listInd)
               {
                  QName item = (QName)list.get(listInd);
                  String itemNs = item.getNamespaceURI();
                  if(itemNs != null && itemNs.length() > 0)
View Full Code Here

      ElementBinding elementBinding = schemaBinding.getElement(elementName);
      assertNotNull(elementBinding);
      TypeBinding typeBinding = elementBinding.getType();
      assertNotNull(typeBinding);
      QName attributeName = new QName(XMLConstants.NULL_NS_URI, "attribute");
      AttributeBinding attribute = typeBinding.getAttribute(attributeName);
      assertNotNull(attribute);
      TypeBinding attributeType = attribute.getType();
      assertTrue("Expected " + expectedTypeBinding + " got " + attributeType, expectedTypeBinding == attributeType);
   }
View Full Code Here

     
      SchemaBinding schema = new SchemaBinding();
     
      try
      {
         new AttributeBinding(schema, new QName("name"), complexType, DefaultHandlers.ATTRIBUTE_HANDLER);
         fail("Attribute can't be of a complex type w/o a value adapter.");
      }
      catch(JBossXBRuntimeException e)
      {
      }
     
      complexType.setValueAdapter(
         new ValueAdapter()
         {
            public Object cast(Object o, Class<?> c)
            {
               // TODO Auto-generated method stub
               return null;
            }
         }
      );
      try
      {
         new AttributeBinding(schema, new QName("name"), complexType, DefaultHandlers.ATTRIBUTE_HANDLER);
      }
      catch(JBossXBRuntimeException e)
      {
         fail("Attribute can be of a complex type with value adapter.");
      }
View Full Code Here

  
   public Object getValue(MarshallingContext ctx)
   {
      Object owner = ctx.peek();
      SchemaBinding schema = ctx.getSchemaBinding();
      AttributeBinding binding = ctx.getAttributeBinding();
      QName qName = binding.getQName();

      String fieldName = null;
      PropertyMetaData propertyMetaData = binding.getPropertyMetaData();
      if(propertyMetaData != null)
      {
         fieldName = propertyMetaData.getName();
      }

      if(fieldName == null)
      {
         fieldName =
            Util.xmlNameToFieldName(qName.getLocalPart(), schema.isIgnoreLowLine());
      }

      FieldInfo fieldInfo = FieldInfo.getFieldInfo(
         owner.getClass(), fieldName, binding.getRequired() && !schema.isIgnoreUnresolvedFieldOrClass()
      );
      Object value = null;
      if(fieldInfo != null)
      {
         value = fieldInfo.getValue(owner);
View Full Code Here

TOP

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

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.