Package org.jboss.xb.binding.introspection

Examples of org.jboss.xb.binding.introspection.FieldInfo


      {
         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);
      }

      return value;
   }
View Full Code Here


               throw e;
            }
         }
      }

      FieldInfo fieldInfo = null;
      if(mapping != null)
      {
         fieldInfo = mapping.fieldInfo;
      }

      Object value = null;
      if(fieldInfo != null && (!forComplexType || forComplexType && !writeAsValue(fieldInfo.getType())))
      {
         value = fieldInfo.getValue(o);
      }

      if(value != null && mapping != null && mapping.converter != null)
      {
         value = mapping.converter.marshal(value);
View Full Code Here

   private static Object getJavaValue(String fieldName,
                                      Object o,
                                      boolean forComplexType,
                                      boolean ignoreNotFoundField)
   {
      FieldInfo fieldInfo = FieldInfo.getFieldInfo(o.getClass(), fieldName, !ignoreNotFoundField);
      Object value = null;
      if(fieldInfo != null && (!forComplexType || forComplexType && !writeAsValue(fieldInfo.getType())))
      {
         value = fieldInfo.getValue(o);
      }
      return value;
   }
View Full Code Here

            {
               ElementToFieldMapping fieldMapping = (ElementToFieldMapping)elementToFieldMapping.get(
                  new ElementToFieldMappingKey(localName, o.getClass())
               );

               FieldInfo fieldInfo;
               if(fieldMapping != null)
               {
                  fieldInfo = fieldMapping.fieldInfo;
               }
               else
               {
                  String fieldName = Util.xmlNameToFieldName(localName, true);
                  fieldInfo = FieldInfo.getFieldInfo(o.getClass(), fieldName, true);
               }

               child = get(o, localName, fieldInfo);
            }

            if(child == null)
            {
               child = newInstance(mapping.cls);
            }

            if(attrs != null)
            {
               for(int i = 0; i < attrs.getLength(); ++i)
               {
                  if(attrs.getLocalName(i).length() > 0)
                  {
                     if(!attrs.getQName(i).startsWith("xsi:")) //todo horrible
                     {
                        setAttribute(child, attrs.getLocalName(i), attrs.getValue(i), ctx);
                     }
                  }
               }
            }
         }
         catch(RuntimeException e)
         {
            throw e;
         }
         catch(Exception e)
         {
            throw new NestedRuntimeException("newChild failed for o=" +
               o +
               ", uri=" +
               namespaceURI +
               ", local="
               + localName + ", attrs=" + attrs, e
            );
         }
      }
      else
      {
         if(o instanceof Collection)
         {
            child = create(namespaceURI, localName, type);
         }
         else
         {
            Class oCls;
            if(o instanceof Immutable)
            {
               oCls = ((Immutable)o).cls;
            }
            else
            {
               oCls = o.getClass();
            }

            String fieldName = Util.xmlNameToFieldName(localName, true);
            FieldInfo fieldInfo = FieldInfo.getFieldInfo(oCls, fieldName, true);
            if(Collection.class.isAssignableFrom(fieldInfo.getType()))
            {
               child = get(o, localName, fieldInfo);

               // now does this element really represent a Java collection or is it an element that can appear more than once?
               // try to load the class and create an instance
               Object item = null;
               if(type == null || type != null && type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
               {
                  item = create(namespaceURI, localName, type);
               }

               if(item != null)
               {
                  if(child == null)
                  {
                     setChild(new ArrayList(), o, localName);
                  }
                  child = item;
               }
               else
               {
                  if(child == null)
                  {
                     child = new ArrayList();
                  }
               }
            }
            else if(!Util.isAttributeType(fieldInfo.getType()))
            {
               // id there is no field mapping
               ElementToFieldMapping fieldMapping = (ElementToFieldMapping)elementToFieldMapping.get(
                  new ElementToFieldMappingKey(localName, o.getClass())
               );
               TypeBinding converter = fieldMapping == null ? null : fieldMapping.converter;

               // if converter != null it will be used in setValue
               if(converter == null)
               {
                  child = newInstance(fieldInfo.getType());
               }
            }
         }
      }
View Full Code Here

            Class parentCls = parent instanceof Immutable ?
               ((Immutable)parent).cls :
               parent.getClass();

            String fieldName = Util.xmlNameToFieldName(localName, true);
            FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentCls, fieldName, false);
            if(trace)
            {
               log.trace("Add " + value + " to property " + fieldName + " of " + parentCls);
            }

            if(fieldInfo != null)
            {
               if(!(child instanceof Collection) && Collection.class.isAssignableFrom(fieldInfo.getType()))
               {
                  Object o = get(parent, localName, fieldInfo);
                  Collection col = (Collection)o;
                  if(trace)
                  {
View Full Code Here

            {
               oCls = o.getClass();
            }

            final String fieldName = Util.xmlNameToFieldName(localName, true);
            FieldInfo fieldInfo = FieldInfo.getFieldInfo(oCls, fieldName, true);

            fieldValue = SimpleTypeBindings.unmarshal(value, fieldInfo.getType());
            set(o, fieldValue, localName, fieldInfo);
         }
      }
   }
View Full Code Here

      {
         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);
      }

      return value;
   }
View Full Code Here

                          String prop,
                          String colType,
                          boolean ignoreNotFoundField,
                          ValueAdapter valueAdapter)
   {
      FieldInfo fieldInfo = FieldInfo.getFieldInfo(o.getClass(), prop, !ignoreNotFoundField);
      if(fieldInfo == null)
      {
         return;
      }

      Class fieldType = fieldInfo.getType();
      boolean arrType;
      if(fieldType.isArray())
      {
         arrType = true;
      }
      else if(Collection.class.isAssignableFrom(fieldType))
      {
         arrType = false;
      }
      else
      {
         throw new JBossXBRuntimeException(
            "Expected type for " + prop + " in " + o.getClass() + " is an array or java.util.Collection but was " + fieldType
         );
      }


      if(valueAdapter != null)
      {
         value = valueAdapter.cast(value, fieldType);
      }

      if(!arrType || colType != null)
      {
         Collection col = (Collection)fieldInfo.getValue(o);
         if(col == null)
         {
            if(colType == null)
            {
               col = new ArrayList();
            }
            else
            {
               Class colCls;
               try
               {
                  colCls = Thread.currentThread().getContextClassLoader().loadClass(colType);
               }
               catch(ClassNotFoundException e)
               {
                  throw new JBossXBRuntimeException("Failed to load collection type: " + colType);
               }

               try
               {
                  col = (Collection)colCls.newInstance();
               }
               catch(Exception e)
               {
                  throw new JBossXBRuntimeException("Failed to create an instance of " + colCls);
               }
            }

            fieldInfo.setValue(o, col);
         }

         col.add(value);
      }
      else
      {
         Object arr = fieldInfo.getValue(o);
         int length = 0;
         if(arr == null)
         {
            arr = Array.newInstance(fieldType.getComponentType(), 1);
         }
         else
         {
            Object tmp = arr;
            length = Array.getLength(arr);
            arr = Array.newInstance(fieldType.getComponentType(), length + 1);
            System.arraycopy(tmp, 0, arr, 0, length);
            //System.out.println("copied array (1)");
         }
         Array.set(arr, length, value);
         fieldInfo.setValue(o, arr);
      }
   }
View Full Code Here

                          String prop,
                          String colType,
                          boolean ignoreNotFoundField,
                          ValueAdapter valueAdapter)
   {
      FieldInfo fieldInfo = FieldInfo.getFieldInfo(o.getClass(), prop, !ignoreNotFoundField);
      if(fieldInfo == null)
      {
         return;
      }

      Class fieldType = fieldInfo.getType();

      if(valueAdapter != null)
      {
         value = valueAdapter.cast(value, fieldType);
      }

      if(Collection.class.isAssignableFrom(fieldType) &&
         !Collection.class.isAssignableFrom(value.getClass()))
      {
         Collection col = (Collection)fieldInfo.getValue(o);
         if(col == null)
         {
            if(colType == null)
            {
               col = new ArrayList();
            }
            else
            {
               Class colCls;
               try
               {
                  colCls = Thread.currentThread().getContextClassLoader().loadClass(colType);
               }
               catch(ClassNotFoundException e)
               {
                  throw new JBossXBRuntimeException("Failed to load collection type: " + colType);
               }

               try
               {
                  col = (Collection)colCls.newInstance();
               }
               catch(Exception e)
               {
                  throw new JBossXBRuntimeException("Failed to create an instance of " + colCls);
               }
            }

            fieldInfo.setValue(o, col);
         }

         //System.out.println("col.add(value): " + prop + "=" + value);
         col.add(value);
      }
/*
      else if(fieldType.isArray() &&
         value != null &&
         (fieldType.getComponentType().isAssignableFrom(value.getClass()) ||
         fieldType.getComponentType().isPrimitive() &&
         Classes.getPrimitiveWrapper(fieldType.getComponentType()) == value.getClass()
         ))
      {
         Object arr = fieldInfo.getValue(o);
         int length = 0;
         if(arr == null)
         {
            arr = Array.newInstance(fieldType.getComponentType(), 1);
         }
         else
         {
            Object tmp = arr;
            length = Array.getLength(arr);
            arr = Array.newInstance(fieldType.getComponentType(), length + 1);
            System.arraycopy(tmp, 0, arr, 0, length);
            throw new JBossXBRuntimeException("copied array (2)");
         }
         Array.set(arr, length, value);
         fieldInfo.setValue(o, arr);
      }
*/     
      else
      {
         // todo: unmarshalling should produce the right type instead
         Class valueClass = value == null ? null : value.getClass();
         if (valueClass != null && fieldType.isArray() && Collection.class.isAssignableFrom(valueClass))
         {
            Collection col = (Collection) value;
            Class compType = fieldType.getComponentType();
            value = Array.newInstance(compType, col.size());
            if (compType.isPrimitive())
            {
               int i = 0;
               for (Iterator iter = col.iterator(); iter.hasNext();)
               {
                  Array.set(value, i++, iter.next());
               }
            }
            else
            {
               value = col.toArray((Object[]) value);
            }
         }

         fieldInfo.setValue(o, value);
      }
   }
View Full Code Here

         ((Collection)o).add(value);
      }
      else
      {
         String fieldName = Util.xmlNameToFieldName(elementName.getLocalPart(), ignoreLowLine);
         FieldInfo fieldInfo = FieldInfo.getFieldInfo(o.getClass(), fieldName, true);
         fieldInfo.setValue(o, value);
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.introspection.FieldInfo

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.