Package com.adaptiweb.utils.xmlbind.annotation

Examples of com.adaptiweb.utils.xmlbind.annotation.BindElement


    throw new IllegalArgumentException("Unknown type " + type.getName());
  }
 
  private void appendElements(Object obj, List<Method> subelemetns, MarshallerOutput output) throws IllegalArgumentException, IllegalAccessException, IOException, SecurityException, ParserException, NoSuchMethodException, ArrayIndexOutOfBoundsException, InvocationTargetException {
    for(Method method : subelemetns) {
      BindElement annotation = method.getAnnotation(BindElement.class);
      if(annotation == null) annotation = DefaultBindElement.defaultInstance;

      Class<?> type = method.getReturnType();
      Object result = null;
      try {
        result = method.invoke(obj);
      } catch (InvocationTargetException ignore) {}

      String tag = annotation.tagName().length() != 0 ? annotation.tagName() :
        BindUtils.toXmlName(method.getName().substring(method.getName().startsWith("is") ? 2 : 3));
           
      if(Iterable.class.isAssignableFrom(type) || type.isArray()) {
        if(result == null) continue;
       
        if(annotation.itemTag().length() != 0) {
          output.startElement(tag);
          tag = annotation.itemTag();
        }
       
        if(type.isArray())
          for(int i = 0, length = Array.getLength(result); i < length; i++)
            determineElement(tag, Array.get(result, i), annotation, output);
        else
          for(Object o : (Iterable<?>) result)
            determineElement(tag, o, annotation, output);
       
        if(annotation.itemTag().length() != 0)
          output.stopElement();
      }
      else determineElement(tag, result, annotation, output);
    }
  }
View Full Code Here

TOP

Related Classes of com.adaptiweb.utils.xmlbind.annotation.BindElement

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.