Java 类org.simpleframework.xml.ElementArray 实例源码

项目:simplexml    文件:AnnotationFactory.java   
/**
 * This is used to create an annotation for the provided type.
 * Annotations created are used to match the type provided. So
 * an array of objects will have an <code>ElementArray</code>
 * annotation for example. Matching the annotation to the
 * type ensures the best serialization for that type. 
 * 
 * @param type the type to create the annotation for
 * 
 * @return this returns the synthetic annotation to be used
 */
private Annotation getInstance(Class type) throws Exception {
   ClassLoader loader = getClassLoader();
   Class entry = type.getComponentType();

   if(type.isArray()) {
      if(isPrimitive(entry)) {
         return getInstance(loader, Element.class);
      }
      return getInstance(loader, ElementArray.class);
   }
   if(isPrimitive(type) && isAttribute()) {
      return getInstance(loader, Attribute.class);
   }
   return getInstance(loader, Element.class);
}
项目:simple-xml    文件:AnnotationFactory.java   
/**
 * This is used to create an annotation for the provided type.
 * Annotations created are used to match the type provided. So
 * an array of objects will have an <code>ElementArray</code>
 * annotation for example. Matching the annotation to the
 * type ensures the best serialization for that type. 
 * 
 * @param type the type to create the annotation for
 * 
 * @return this returns the synthetic annotation to be used
 */
private Annotation getInstance(Class type) throws Exception {
   ClassLoader loader = getClassLoader();
   Class entry = type.getComponentType();

   if(type.isArray()) {
      if(isPrimitive(entry)) {
         return getInstance(loader, Element.class);
      }
      return getInstance(loader, ElementArray.class);
   }
   if(isPrimitive(type) && isAttribute()) {
      return getInstance(loader, Attribute.class);
   }
   return getInstance(loader, Element.class);
}
项目:simple-xml-serializers    文件:TypeConverterTest.java   
@SuppressFBWarnings("EI_EXPOSE_REP2")
public MethodArrayBean(
        @ElementArray(name = "types", entry = "type", empty = false) Type[] types,
        @ElementArray(name = "classes", entry = "class", empty = false) Class<?>[] classes) {
    this.types = types;
    this.classes = classes;
}
项目:simple-xml-serializers    文件:SimpleXmlInvocation.java   
@Nonnull
@ElementArray(name = "args", entry = "arg", required = false, empty = false)
public Object[] getArgumentsWrapped() {
    Object[] args = super.getArguments();
    args = Arrays.copyOf(args, args.length);
    for (int i = 0; i < args.length; i++)
        args[i] = PersisterUtils.wrap(args[i]);
    return args;
}
项目:simplexml    文件:ElementArrayParameter.java   
/**   
 * Constructor for the <code>ElementArrayParameter</code> object.
 * This is used to create a parameter that can be used to 
 * determine a consistent name using the provided XML annotation.
 * 
 * @param factory this is the constructor the parameter is in
 * @param value this is the annotation used for the parameter
 * @param format this is the format used to style the elements
 * @param index this is the index the parameter appears at
 */
public ElementArrayParameter(Constructor factory, ElementArray value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new ElementArrayLabel(contact, value, format);
   this.expression = label.getExpression();
   this.path = label.getPath();
   this.type = label.getType();
   this.name = label.getName();
   this.key = label.getKey();
   this.index = index;
}
项目:simplexml    文件:FieldScanner.java   
/**
 * This reflectively checks the annotation to determine the type 
 * of annotation it represents. If it represents an XML schema
 * annotation it is used to create a <code>Contact</code> which 
 * can be used to represent the field within the source object.
 * 
 * @param field the field that the annotation comes from
 * @param label the annotation used to model the XML schema
 * @param list this is the list of annotations on the field
 */
private void scan(Field field, Annotation label, Annotation[] list) {
   if(label instanceof Attribute) {
      process(field, label, list);
   }
   if(label instanceof ElementUnion) {
      process(field, label, list);
   }
   if(label instanceof ElementListUnion) {
      process(field, label, list);
   }
   if(label instanceof ElementMapUnion) {
      process(field, label, list);
   }
   if(label instanceof ElementList) {
      process(field, label, list);
   }     
   if(label instanceof ElementArray) {
      process(field, label, list);
   }
   if(label instanceof ElementMap) {
      process(field, label, list);
   }
   if(label instanceof Element) {
      process(field, label, list);
   }       
   if(label instanceof Version) {
      process(field, label, list);
   }
   if(label instanceof Text) {
      process(field, label, list);
   }
   if(label instanceof Transient) {
      remove(field, label);
   }
}
项目:simplexml    文件:MethodScanner.java   
/**
 * This reflectively checks the annotation to determine the type 
 * of annotation it represents. If it represents an XML schema
 * annotation it is used to create a <code>Contact</code> which 
 * can be used to represent the method within the source object.
 * 
 * @param method the method that the annotation comes from
 * @param label the annotation used to model the XML schema
 * @param list this is the list of annotations on the method
 */ 
private void scan(Method method, Annotation label, Annotation[] list) throws Exception {
   if(label instanceof Attribute) {
      process(method, label, list);
   }
   if(label instanceof ElementUnion) {
      process(method, label, list);
   }
   if(label instanceof ElementListUnion) {
      process(method, label, list);
   }
   if(label instanceof ElementMapUnion) {
      process(method, label, list);
   }
   if(label instanceof ElementList) {
      process(method, label, list);
   }
   if(label instanceof ElementArray) {
      process(method, label, list);
   }
   if(label instanceof ElementMap) {
      process(method, label, list);
   }
   if(label instanceof Element) {
      process(method, label, list);
   }    
   if(label instanceof Version) {
      process(method, label, list);
   }
   if(label instanceof Text) {
      process(method, label, list);
   }
   if(label instanceof Transient) {
      remove(method, label, list);
   }
}
项目:simplexml    文件:ParameterFactory.java   
/**
 * Creates an entry that is used to select the constructor for the
 * parameter. Each parameter must implement a constructor that takes 
 * a constructor, and annotation, and the index of the parameter. If
 * the annotation is not know this method throws an exception.
 * 
 * @param label the XML annotation used to create the parameter
 * 
 * @return this returns the entry used to create a constructor
 */
private ParameterBuilder getBuilder(Annotation label) throws Exception{      
   if(label instanceof Element) {
      return new ParameterBuilder(ElementParameter.class, Element.class);
   }
   if(label instanceof ElementList) {
      return new ParameterBuilder(ElementListParameter.class, ElementList.class);
   }
   if(label instanceof ElementArray) {
      return new ParameterBuilder(ElementArrayParameter.class, ElementArray.class);               
   }
   if(label instanceof ElementMapUnion) {
      return new ParameterBuilder(ElementMapUnionParameter.class, ElementMapUnion.class, ElementMap.class);
   }
   if(label instanceof ElementListUnion) {
      return new ParameterBuilder(ElementListUnionParameter.class, ElementListUnion.class, ElementList.class);
   }
   if(label instanceof ElementUnion) {
      return new ParameterBuilder(ElementUnionParameter.class, ElementUnion.class, Element.class);
   }
   if(label instanceof ElementMap) {
      return new ParameterBuilder(ElementMapParameter.class, ElementMap.class);
   }
   if(label instanceof Attribute) {
      return new ParameterBuilder(AttributeParameter.class, Attribute.class);
   }
   if(label instanceof Text) {
      return new ParameterBuilder(TextParameter.class, Text.class);
   }
   throw new PersistenceException("Annotation %s not supported", label);
}
项目:simplexml    文件:SignatureScanner.java   
/**
 * This is used to create <code>Parameter</code> objects which are
 * used to represent the parameters in a constructor. Each parameter
 * contains an annotation an the index it appears in.
 * 
 * @param label this is the annotation used for the parameter
 * @param ordinal this is the position the parameter appears at
 * 
 * @return this returns the parameters for the constructor
 */
private List<Parameter> process(Annotation label, int ordinal) throws Exception{
   if(label instanceof Attribute) {
      return create(label, ordinal);
   }
   if(label instanceof Element) {
      return create(label, ordinal);
   }
   if(label instanceof ElementList) {
      return create(label, ordinal);
   }     
   if(label instanceof ElementArray) {
      return create(label, ordinal);
   }
   if(label instanceof ElementMap) {
      return create(label, ordinal);
   }
   if(label instanceof ElementListUnion) {
      return union(label, ordinal);
   }     
   if(label instanceof ElementMapUnion) {
      return union(label, ordinal);
   }
   if(label instanceof ElementUnion) {
      return union(label, ordinal);
   }
   if(label instanceof Text) {
      return create(label, ordinal);
   }
   return emptyList();
}
项目:simplexml    文件:LabelExtractor.java   
/**
 * Creates an entry that is used to select the constructor for the
 * label. Each label must implement a constructor that takes a
 * contact and the specific XML annotation for that field. If the
 * annotation is not know this method throws an exception.
 * 
 * @param label the XML annotation used to create the label
 * 
 * @return this returns the entry used to create a constructor
 */
private LabelBuilder getBuilder(Annotation label) throws Exception{   
   if(label instanceof Element) {
      return new LabelBuilder(ElementLabel.class, Element.class);
   }
   if(label instanceof ElementList) {
      return new LabelBuilder(ElementListLabel.class, ElementList.class);
   }
   if(label instanceof ElementArray) {
      return new LabelBuilder(ElementArrayLabel.class, ElementArray.class);               
   }
   if(label instanceof ElementMap) {
      return new LabelBuilder(ElementMapLabel.class, ElementMap.class);
   }
   if(label instanceof ElementUnion) {
      return new LabelBuilder(ElementUnionLabel.class, ElementUnion.class, Element.class);
   }
   if(label instanceof ElementListUnion) {
      return new LabelBuilder(ElementListUnionLabel.class, ElementListUnion.class, ElementList.class);
   }
   if(label instanceof ElementMapUnion) {
      return new LabelBuilder(ElementMapUnionLabel.class, ElementMapUnion.class, ElementMap.class);
   }
   if(label instanceof Attribute) {
      return new LabelBuilder(AttributeLabel.class, Attribute.class);
   }
   if(label instanceof Version) {
      return new LabelBuilder(VersionLabel.class, Version.class);
   }
   if(label instanceof Text) {
      return new LabelBuilder(TextLabel.class, Text.class);
   }
   throw new PersistenceException("Annotation %s not supported", label);
}
项目:simplexml    文件:ElementArrayLabel.java   
/**
 * Constructor for the <code>ElementArrayLabel</code> object. This
 * creates a label object, which can be used to convert an element
 * node to an array of XML serializable objects.
 * 
 * @param contact this is the contact that this label represents
 * @param label the annotation that contains the schema details
 * @param format this is used to style the elements for this label
 */
public ElementArrayLabel(Contact contact, ElementArray label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.decorator = new Qualifier(contact);
   this.required = label.required();
   this.type = contact.getType();
   this.entry = label.entry();
   this.data = label.data();
   this.name = label.name();
   this.format = format;
   this.label = label;
}
项目:simplexml    文件:StructureBuilder.java   
/**
 * This reflectively checks the annotation to determine the type 
 * of annotation it represents. If it represents an XML schema
 * annotation it is used to create a <code>Label</code> which can
 * be used to represent the field within the context object.
 * 
 * @param field the field that the annotation comes from
 * @param label the annotation used to model the XML schema
 * 
 * @throws Exception if there is more than one text annotation
 */   
public void process(Contact field, Annotation label) throws Exception {
   if(label instanceof Attribute) {
      process(field, label, attributes);
   }
   if(label instanceof ElementUnion) {
      union(field, label, elements);
   }
   if(label instanceof ElementListUnion) {
      union(field, label, elements);
   }
   if(label instanceof ElementMapUnion) {
      union(field, label, elements);
   }
   if(label instanceof ElementList) {
      process(field, label, elements);
   }
   if(label instanceof ElementArray) {
      process(field, label, elements);
   }
   if(label instanceof ElementMap) {
      process(field, label, elements);
   }
   if(label instanceof Element) {
      process(field, label, elements);
   }    
   if(label instanceof Version) {
      version(field, label);
   }
   if(label instanceof Text) {
      text(field, label);
   }
}
项目:simplexml    文件:AnnotationHandlerTest.java   
@ElementArray
@ElementList
@ElementMap
@Element
public void testHandler() throws Exception {
   AnnotationHandler elementHandler = new AnnotationHandler(Element.class);
   Element element = getClass().getDeclaredMethod("testHandler").getAnnotation(Element.class);

   System.err.println(elementHandler);
   System.err.println(element);

   AnnotationHandler elementListHandler = new AnnotationHandler(ElementList.class);
   ElementList elementList = getClass().getDeclaredMethod("testHandler").getAnnotation(ElementList.class);

   System.err.println(elementListHandler);
   System.err.println(elementList);

   AnnotationHandler elementMapHandler = new AnnotationHandler(ElementMap.class);
   ElementMap elementMap = getClass().getDeclaredMethod("testHandler").getAnnotation(ElementMap.class);

   System.err.println(elementMapHandler);
   System.err.println(elementMap);

   AnnotationHandler elementArrayHandler = new AnnotationHandler(ElementArray.class);
   ElementArray elementArray = getClass().getDeclaredMethod("testHandler").getAnnotation(ElementArray.class);

   System.err.println(elementArrayHandler);
   System.err.println(elementArray);
}
项目:simplexml    文件:MethodPartFactoryTest.java   
public void testMethodPart() throws Exception {
   assertTrue(Element.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getInteger"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(Element.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setInteger", int.class), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementMap.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getMap"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementMap.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setMap", Map.class), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementList.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getList"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementList.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setList", List.class), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementArray.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getArray"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementArray.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setArray", String[].class), new Annotation[0]).getAnnotation().getClass()));
}
项目:simplexml    文件:MethodScannerDefaultTest.java   
public void testMixedAnnotations() throws Exception {
   Map<String, Contact> map = getContacts(MixedAnnotations.class);

   assertFalse(map.get("array").isReadOnly());
   assertFalse(map.get("map").isReadOnly());
   assertFalse(map.get("name").isReadOnly());      
   assertFalse(map.get("value").isReadOnly());

   assertEquals(String[].class, map.get("array").getType());
   assertEquals(Map.class, map.get("map").getType());
   assertEquals(int.class, map.get("value").getType());      
   assertEquals(String.class, map.get("name").getType());

   assertEquals(Attribute.class, map.get("name").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation().annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation().annotationType());
   assertEquals(ElementArray.class, map.get("array").getAnnotation().annotationType());

   assertEquals(Attribute.class, map.get("name").getAnnotation(Attribute.class).annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation(Element.class).annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation(ElementMap.class).annotationType());
   assertEquals(ElementArray.class, map.get("array").getAnnotation(ElementArray.class).annotationType());

   assertNull(map.get("name").getAnnotation(Root.class));
   assertNull(map.get("value").getAnnotation(Root.class));
   assertNull(map.get("map").getAnnotation(Root.class));
   assertNull(map.get("array").getAnnotation(Root.class));
}
项目:simple-xml    文件:ElementArrayParameter.java   
/**   
 * Constructor for the <code>ElementArrayParameter</code> object.
 * This is used to create a parameter that can be used to 
 * determine a consistent name using the provided XML annotation.
 * 
 * @param factory this is the constructor the parameter is in
 * @param value this is the annotation used for the parameter
 * @param format this is the format used to style the elements
 * @param index this is the index the parameter appears at
 */
public ElementArrayParameter(Constructor factory, ElementArray value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new ElementArrayLabel(contact, value, format);
   this.expression = label.getExpression();
   this.path = label.getPath();
   this.type = label.getType();
   this.name = label.getName();
   this.key = label.getKey();
   this.index = index;
}
项目:simple-xml    文件:FieldScanner.java   
/**
 * This reflectively checks the annotation to determine the type 
 * of annotation it represents. If it represents an XML schema
 * annotation it is used to create a <code>Contact</code> which 
 * can be used to represent the field within the source object.
 * 
 * @param field the field that the annotation comes from
 * @param label the annotation used to model the XML schema
 * @param list this is the list of annotations on the field
 */
private void scan(Field field, Annotation label, Annotation[] list) {
   if(label instanceof Attribute) {
      process(field, label, list);
   }
   if(label instanceof ElementUnion) {
      process(field, label, list);
   }
   if(label instanceof ElementListUnion) {
      process(field, label, list);
   }
   if(label instanceof ElementMapUnion) {
      process(field, label, list);
   }
   if(label instanceof ElementList) {
      process(field, label, list);
   }     
   if(label instanceof ElementArray) {
      process(field, label, list);
   }
   if(label instanceof ElementMap) {
      process(field, label, list);
   }
   if(label instanceof Element) {
      process(field, label, list);
   }       
   if(label instanceof Version) {
      process(field, label, list);
   }
   if(label instanceof Text) {
      process(field, label, list);
   }
   if(label instanceof Transient) {
      remove(field, label);
   }
}
项目:simple-xml    文件:MethodScanner.java   
/**
 * This reflectively checks the annotation to determine the type 
 * of annotation it represents. If it represents an XML schema
 * annotation it is used to create a <code>Contact</code> which 
 * can be used to represent the method within the source object.
 * 
 * @param method the method that the annotation comes from
 * @param label the annotation used to model the XML schema
 * @param list this is the list of annotations on the method
 */ 
private void scan(Method method, Annotation label, Annotation[] list) throws Exception {
   if(label instanceof Attribute) {
      process(method, label, list);
   }
   if(label instanceof ElementUnion) {
      process(method, label, list);
   }
   if(label instanceof ElementListUnion) {
      process(method, label, list);
   }
   if(label instanceof ElementMapUnion) {
      process(method, label, list);
   }
   if(label instanceof ElementList) {
      process(method, label, list);
   }
   if(label instanceof ElementArray) {
      process(method, label, list);
   }
   if(label instanceof ElementMap) {
      process(method, label, list);
   }
   if(label instanceof Element) {
      process(method, label, list);
   }    
   if(label instanceof Version) {
      process(method, label, list);
   }
   if(label instanceof Text) {
      process(method, label, list);
   }
   if(label instanceof Transient) {
      remove(method, label, list);
   }
}
项目:simple-xml    文件:ParameterFactory.java   
/**
 * Creates an entry that is used to select the constructor for the
 * parameter. Each parameter must implement a constructor that takes 
 * a constructor, and annotation, and the index of the parameter. If
 * the annotation is not know this method throws an exception.
 * 
 * @param label the XML annotation used to create the parameter
 * 
 * @return this returns the entry used to create a constructor
 */
private ParameterBuilder getBuilder(Annotation label) throws Exception{      
   if(label instanceof Element) {
      return new ParameterBuilder(ElementParameter.class, Element.class);
   }
   if(label instanceof ElementList) {
      return new ParameterBuilder(ElementListParameter.class, ElementList.class);
   }
   if(label instanceof ElementArray) {
      return new ParameterBuilder(ElementArrayParameter.class, ElementArray.class);               
   }
   if(label instanceof ElementMapUnion) {
      return new ParameterBuilder(ElementMapUnionParameter.class, ElementMapUnion.class, ElementMap.class);
   }
   if(label instanceof ElementListUnion) {
      return new ParameterBuilder(ElementListUnionParameter.class, ElementListUnion.class, ElementList.class);
   }
   if(label instanceof ElementUnion) {
      return new ParameterBuilder(ElementUnionParameter.class, ElementUnion.class, Element.class);
   }
   if(label instanceof ElementMap) {
      return new ParameterBuilder(ElementMapParameter.class, ElementMap.class);
   }
   if(label instanceof Attribute) {
      return new ParameterBuilder(AttributeParameter.class, Attribute.class);
   }
   if(label instanceof Text) {
      return new ParameterBuilder(TextParameter.class, Text.class);
   }
   throw new PersistenceException("Annotation %s not supported", label);
}
项目:simple-xml    文件:SignatureScanner.java   
/**
 * This is used to create <code>Parameter</code> objects which are
 * used to represent the parameters in a constructor. Each parameter
 * contains an annotation an the index it appears in.
 * 
 * @param label this is the annotation used for the parameter
 * @param ordinal this is the position the parameter appears at
 * 
 * @return this returns the parameters for the constructor
 */
private List<Parameter> process(Annotation label, int ordinal) throws Exception{
   if(label instanceof Attribute) {
      return create(label, ordinal);
   }
   if(label instanceof Element) {
      return create(label, ordinal);
   }
   if(label instanceof ElementList) {
      return create(label, ordinal);
   }     
   if(label instanceof ElementArray) {
      return create(label, ordinal);
   }
   if(label instanceof ElementMap) {
      return create(label, ordinal);
   }
   if(label instanceof ElementListUnion) {
      return union(label, ordinal);
   }     
   if(label instanceof ElementMapUnion) {
      return union(label, ordinal);
   }
   if(label instanceof ElementUnion) {
      return union(label, ordinal);
   }
   if(label instanceof Text) {
      return create(label, ordinal);
   }
   return emptyList();
}
项目:simple-xml    文件:LabelExtractor.java   
/**
 * Creates an entry that is used to select the constructor for the
 * label. Each label must implement a constructor that takes a
 * contact and the specific XML annotation for that field. If the
 * annotation is not know this method throws an exception.
 * 
 * @param label the XML annotation used to create the label
 * 
 * @return this returns the entry used to create a constructor
 */
private LabelBuilder getBuilder(Annotation label) throws Exception{   
   if(label instanceof Element) {
      return new LabelBuilder(ElementLabel.class, Element.class);
   }
   if(label instanceof ElementList) {
      return new LabelBuilder(ElementListLabel.class, ElementList.class);
   }
   if(label instanceof ElementArray) {
      return new LabelBuilder(ElementArrayLabel.class, ElementArray.class);               
   }
   if(label instanceof ElementMap) {
      return new LabelBuilder(ElementMapLabel.class, ElementMap.class);
   }
   if(label instanceof ElementUnion) {
      return new LabelBuilder(ElementUnionLabel.class, ElementUnion.class, Element.class);
   }
   if(label instanceof ElementListUnion) {
      return new LabelBuilder(ElementListUnionLabel.class, ElementListUnion.class, ElementList.class);
   }
   if(label instanceof ElementMapUnion) {
      return new LabelBuilder(ElementMapUnionLabel.class, ElementMapUnion.class, ElementMap.class);
   }
   if(label instanceof Attribute) {
      return new LabelBuilder(AttributeLabel.class, Attribute.class);
   }
   if(label instanceof Version) {
      return new LabelBuilder(VersionLabel.class, Version.class);
   }
   if(label instanceof Text) {
      return new LabelBuilder(TextLabel.class, Text.class);
   }
   throw new PersistenceException("Annotation %s not supported", label);
}
项目:simple-xml    文件:ElementArrayLabel.java   
/**
 * Constructor for the <code>ElementArrayLabel</code> object. This
 * creates a label object, which can be used to convert an element
 * node to an array of XML serializable objects.
 * 
 * @param contact this is the contact that this label represents
 * @param label the annotation that contains the schema details
 * @param format this is used to style the elements for this label
 */
public ElementArrayLabel(Contact contact, ElementArray label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.decorator = new Qualifier(contact);
   this.required = label.required();
   this.type = contact.getType();
   this.entry = label.entry();
   this.data = label.data();
   this.name = label.name();
   this.format = format;
   this.label = label;
}
项目:simple-xml    文件:StructureBuilder.java   
/**
 * This reflectively checks the annotation to determine the type 
 * of annotation it represents. If it represents an XML schema
 * annotation it is used to create a <code>Label</code> which can
 * be used to represent the field within the context object.
 * 
 * @param field the field that the annotation comes from
 * @param label the annotation used to model the XML schema
 * 
 * @throws Exception if there is more than one text annotation
 */   
public void process(Contact field, Annotation label) throws Exception {
   if(label instanceof Attribute) {
      process(field, label, attributes);
   }
   if(label instanceof ElementUnion) {
      union(field, label, elements);
   }
   if(label instanceof ElementListUnion) {
      union(field, label, elements);
   }
   if(label instanceof ElementMapUnion) {
      union(field, label, elements);
   }
   if(label instanceof ElementList) {
      process(field, label, elements);
   }
   if(label instanceof ElementArray) {
      process(field, label, elements);
   }
   if(label instanceof ElementMap) {
      process(field, label, elements);
   }
   if(label instanceof Element) {
      process(field, label, elements);
   }    
   if(label instanceof Version) {
      version(field, label);
   }
   if(label instanceof Text) {
      text(field, label);
   }
}
项目:simple-xml    文件:AnnotationHandlerTest.java   
@ElementArray
@ElementList
@ElementMap
@Element
public void testHandler() throws Exception {
   AnnotationHandler elementHandler = new AnnotationHandler(Element.class);
   Element element = getClass().getDeclaredMethod("testHandler").getAnnotation(Element.class);

   System.err.println(elementHandler);
   System.err.println(element);

   AnnotationHandler elementListHandler = new AnnotationHandler(ElementList.class);
   ElementList elementList = getClass().getDeclaredMethod("testHandler").getAnnotation(ElementList.class);

   System.err.println(elementListHandler);
   System.err.println(elementList);

   AnnotationHandler elementMapHandler = new AnnotationHandler(ElementMap.class);
   ElementMap elementMap = getClass().getDeclaredMethod("testHandler").getAnnotation(ElementMap.class);

   System.err.println(elementMapHandler);
   System.err.println(elementMap);

   AnnotationHandler elementArrayHandler = new AnnotationHandler(ElementArray.class);
   ElementArray elementArray = getClass().getDeclaredMethod("testHandler").getAnnotation(ElementArray.class);

   System.err.println(elementArrayHandler);
   System.err.println(elementArray);
}
项目:simple-xml    文件:MethodPartFactoryTest.java   
public void testMethodPart() throws Exception {
   assertTrue(Element.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getInteger"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(Element.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setInteger", int.class), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementMap.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getMap"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementMap.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setMap", Map.class), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementList.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getList"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementList.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setList", List.class), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementArray.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("getArray"), new Annotation[0]).getAnnotation().getClass()));
   assertTrue(ElementArray.class.isAssignableFrom(new MethodPartFactory(new DetailScanner(MethodPartFactoryTest.class), new Support()).getInstance(Bean.class.getMethod("setArray", String[].class), new Annotation[0]).getAnnotation().getClass()));
}
项目:simple-xml    文件:MethodScannerDefaultTest.java   
public void testMixedAnnotations() throws Exception {
   Map<String, Contact> map = getContacts(MixedAnnotations.class);

   assertFalse(map.get("array").isReadOnly());
   assertFalse(map.get("map").isReadOnly());
   assertFalse(map.get("name").isReadOnly());      
   assertFalse(map.get("value").isReadOnly());

   assertEquals(String[].class, map.get("array").getType());
   assertEquals(Map.class, map.get("map").getType());
   assertEquals(int.class, map.get("value").getType());      
   assertEquals(String.class, map.get("name").getType());

   assertEquals(Attribute.class, map.get("name").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation().annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation().annotationType());
   assertEquals(ElementArray.class, map.get("array").getAnnotation().annotationType());

   assertEquals(Attribute.class, map.get("name").getAnnotation(Attribute.class).annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation(Element.class).annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation(ElementMap.class).annotationType());
   assertEquals(ElementArray.class, map.get("array").getAnnotation(ElementArray.class).annotationType());

   assertNull(map.get("name").getAnnotation(Root.class));
   assertNull(map.get("value").getAnnotation(Root.class));
   assertNull(map.get("map").getAnnotation(Root.class));
   assertNull(map.get("array").getAnnotation(Root.class));
}
项目:SlipStreamServer    文件:Node.java   
/**
 * Assembled notes. Includes notes from inherited images.
 */
@Transient
@ElementArray(required = false, entry = "note")
public String[] getNotes() {
    List<String> notes = new ArrayList<String>();
    ImageModule image = getImage();
    if (image != null) {
        notes.addAll(Arrays.asList(image.getNotes()));
    }
    return notes.toArray(new String[0]);
}
项目:SlipStreamServer    文件:Run.java   
/**
 * List of cloud service names used in the current run
 */
@ElementArray(required = false)
public String[] getCloudServiceNamesList() {
    if (cloudServiceNames == null) {
        return new String[]{};
    }
    Set<String> uniqueCloudServiceNames = new HashSet<String>(Arrays.asList(cloudServiceNames.split(",")));
    return uniqueCloudServiceNames.toArray(new String[uniqueCloudServiceNames.size()]);
}
项目:simple-xml-serializers    文件:TypeConverterTest.java   
@ElementArray(name = "types", entry = "type", empty = false)
@SuppressFBWarnings("EI_EXPOSE_REP")
public Type[] getTypes() {
    return types;
}
项目:simple-xml-serializers    文件:TypeConverterTest.java   
@ElementArray(name = "classes", entry = "class", empty = false)
@SuppressFBWarnings("EI_EXPOSE_REP")
public Class<?>[] getClasses() {
    return classes;
}
项目:simple-xml-serializers    文件:PersisterFactoryTest.java   
@SuppressFBWarnings("EI_EXPOSE_REP2")
public ArrayBody(@ElementArray(name = "body") String[] body) {
    this.body = body;
}
项目:simple-xml-serializers    文件:PersisterFactoryTest.java   
@ElementArray(name = "body", required = false)
@SuppressFBWarnings("EI_EXPOSE_REP")
public String[] getBody() {
    return body;
}
项目:simple-xml-serializers    文件:JavaPersistenceTest.java   
@SuppressFBWarnings("EI_EXPOSE_REP2")
public IntArray(@ElementArray(name = "values") int[] values) {
    this.values = values;
}
项目:simple-xml-serializers    文件:JavaPersistenceTest.java   
@ElementArray(name = "values")
@SuppressFBWarnings("EI_EXPOSE_REP")
public int[] getBody() {
    return values;
}
项目:simple-xml-serializers    文件:SimpleXmlInvocation.java   
public SimpleXmlInvocation(
        @Nonnull @Attribute(name = "method") String methodName,
        @Nonnull @ElementArray(name = "params", entry = "param") Class<?>[] parameterTypes,
        @Nonnull @ElementArray(name = "args", entry = "arg") Object[] arguments) {
    super(methodName, unwrap(parameterTypes), unwrap(arguments));
}
项目:simple-xml-serializers    文件:SimpleXmlInvocation.java   
@Override
@Nonnull
@ElementArray(name = "params", entry = "param", required = false, empty = false)
public Class<?>[] getParameterTypes() {
    return super.getParameterTypes();
}
项目:simplexml    文件:ConstructorInjectionTest.java   
public ArrayExample(@ElementArray(name="array") String[] array) {
   this.array = array;
}
项目:simplexml    文件:FieldScannerDefaultTest.java   
public void testNoAnnotations() throws Exception {
   Map<String, Contact> map = getContacts(NoAnnotations.class);

   assertFalse(map.get("name").isReadOnly());
   assertFalse(map.get("value").isReadOnly());
   assertFalse(map.get("date").isReadOnly());
   assertFalse(map.get("locale").isReadOnly());
   assertFalse(map.get("array").isReadOnly());
   assertFalse(map.get("list").isReadOnly());
   assertFalse(map.get("map").isReadOnly());

   assertEquals(String.class, map.get("name").getType());
   assertEquals(int.class, map.get("value").getType());
   assertEquals(Date.class, map.get("date").getType());
   assertEquals(Locale.class, map.get("locale").getType());
   assertEquals(int[].class, map.get("array").getType());
   assertEquals(List.class, map.get("list").getType());
   assertEquals(Map.class, map.get("map").getType());

   assertEquals(Element.class, map.get("name").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("date").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("locale").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("array").getAnnotation().annotationType());
   assertEquals(ElementArray.class, map.get("strings").getAnnotation().annotationType());
   assertEquals(ElementList.class, map.get("list").getAnnotation().annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation().annotationType());

   assertEquals(Element.class, map.get("name").getAnnotation(Element.class).annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation(Element.class).annotationType());
   assertEquals(Element.class, map.get("date").getAnnotation(Element.class).annotationType());
   assertEquals(Element.class, map.get("locale").getAnnotation(Element.class).annotationType());
   assertEquals(Element.class, map.get("array").getAnnotation(Element.class).annotationType());
   assertEquals(ElementArray.class, map.get("strings").getAnnotation(ElementArray.class).annotationType());
   assertEquals(ElementList.class, map.get("list").getAnnotation(ElementList.class).annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation(ElementMap.class).annotationType());

   assertNull(map.get("name").getAnnotation(Root.class));
   assertNull(map.get("value").getAnnotation(Root.class));
   assertNull(map.get("date").getAnnotation(Root.class));
   assertNull(map.get("locale").getAnnotation(Root.class));
   assertNull(map.get("array").getAnnotation(Root.class));
   assertNull(map.get("strings").getAnnotation(Root.class));
   assertNull(map.get("list").getAnnotation(Root.class));
   assertNull(map.get("map").getAnnotation(Root.class));
}
项目:simplexml    文件:MethodScannerDefaultTest.java   
public void testNoAnnotations() throws Exception {
   Map<String, Contact> map = getContacts(NoAnnotations.class);

   assertFalse(map.get("date").isReadOnly());
   assertFalse(map.get("customer").isReadOnly());
   assertFalse(map.get("name").isReadOnly());      
   assertFalse(map.get("price").isReadOnly());
   assertFalse(map.get("list").isReadOnly());
   assertFalse(map.get("map").isReadOnly());
   assertFalse(map.get("array").isReadOnly());

   assertEquals(Date.class, map.get("date").getType());
   assertEquals(String.class, map.get("customer").getType());
   assertEquals(String.class, map.get("name").getType());      
   assertEquals(int.class, map.get("price").getType());
   assertEquals(List.class, map.get("list").getType());
   assertEquals(Map.class, map.get("map").getType());
   assertEquals(String[].class, map.get("array").getType());

   assertEquals(Element.class, map.get("date").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("customer").getAnnotation().annotationType());
   assertEquals(Element.class, map.get("name").getAnnotation().annotationType());      
   assertEquals(Element.class, map.get("price").getAnnotation().annotationType());
   assertEquals(ElementList.class, map.get("list").getAnnotation().annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation().annotationType());
   assertEquals(ElementArray.class, map.get("array").getAnnotation().annotationType());

   assertEquals(Element.class, map.get("date").getAnnotation(Element.class).annotationType());
   assertEquals(Element.class, map.get("customer").getAnnotation(Element.class).annotationType());
   assertEquals(Element.class, map.get("name").getAnnotation(Element.class).annotationType());      
   assertEquals(Element.class, map.get("price").getAnnotation(Element.class).annotationType());
   assertEquals(ElementList.class, map.get("list").getAnnotation(ElementList.class).annotationType());
   assertEquals(ElementMap.class, map.get("map").getAnnotation(ElementMap.class).annotationType());
   assertEquals(ElementArray.class, map.get("array").getAnnotation(ElementArray.class).annotationType());

   assertNull(map.get("date").getAnnotation(Root.class));
   assertNull(map.get("customer").getAnnotation(Root.class));
   assertNull(map.get("name").getAnnotation(Root.class));
   assertNull(map.get("price").getAnnotation(Root.class));
   assertNull(map.get("list").getAnnotation(Root.class));
   assertNull(map.get("map").getAnnotation(Root.class));
   assertNull(map.get("array").getAnnotation(Root.class));
}
项目:simple-xml    文件:ConstructorInjectionTest.java   
public ArrayExample(@ElementArray(name="array") String[] array) {
   this.array = array;
}