org.simpleframework.xml.Attribute Java Examples

The following examples show how to use org.simpleframework.xml.Attribute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FieldScannerDefaultTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testMixedAnnotations() throws Exception {
   Map<String, Contact> map = getContacts(MixedAnnotations.class);
   
   assertEquals(map.size(), 3);
   assertFalse(map.get("name").isReadOnly());
   assertFalse(map.get("value").isReadOnly());
   assertFalse(map.get("list").isReadOnly());
   
   assertEquals(String.class, map.get("name").getType());
   assertEquals(int.class, map.get("value").getType());
   assertEquals(List.class, map.get("list").getType());
   
   assertEquals(Element.class, map.get("name").getAnnotation().annotationType());
   assertEquals(Attribute.class, map.get("value").getAnnotation().annotationType());
   assertEquals(ElementList.class, map.get("list").getAnnotation().annotationType());
   
   assertEquals(Element.class, map.get("name").getAnnotation(Element.class).annotationType());
   assertEquals(Attribute.class, map.get("value").getAnnotation(Attribute.class).annotationType());
   assertEquals(ElementList.class, map.get("list").getAnnotation(ElementList.class).annotationType());
   
   assertNull(map.get("name").getAnnotation(Root.class));
   assertNull(map.get("value").getAnnotation(Root.class));
   assertNull(map.get("list").getAnnotation(Root.class));
}
 
Example #2
Source File: MethodScannerDefaultTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testMixedAnnotationsWithNoDefaults() throws Exception {
   Map<String, Contact> map = getContacts(MixedAnnotations.class);
   
   assertEquals(map.size(), 4);
   assertFalse(map.get("name").isReadOnly());
   assertFalse(map.get("value").isReadOnly());
   
   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(Attribute.class, map.get("name").getAnnotation(Attribute.class).annotationType());
   assertEquals(Element.class, map.get("value").getAnnotation(Element.class).annotationType());
   
   assertNull(map.get("name").getAnnotation(Root.class));
   assertNull(map.get("value").getAnnotation(Root.class));
}
 
Example #3
Source File: UnionComplicatedPathMixTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public ComplicatedExample(
      @Path("x:path[1]") @ElementMap(name="a") Map<Key, Entry> map,
      @Path("x:path[2]") @ElementList(name="a") List<Entry> list,
      @Element(name="elementOne") String elementOne,
      @Element(name="elementTwo") String elementTwo,
      @Element(name="elementThree") String elementThree,
      @Text String text,
      @Path("x:path[2]/x:someOtherPath") @Attribute(name="attribute_one") String attribute_one,
      @Path("x:path[2]/x:someOtherPath") @Attribute(name="attribute_two") String attribute_two) 
{
   this.map = map;
   this.list = list;
   this.elementOne = elementOne;
   this.elementTwo = elementTwo;
   this.elementThree = elementThree;
   this.text = text;
   this.attribute_one = attribute_one;
   this.attribute_two = attribute_two;
}
 
Example #4
Source File: Pod.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
public Pod(@Attribute(name = "error") final boolean error,
           @Attribute(name = "primary") final boolean primary,
           @Attribute(name = "title") final String title,
           @Attribute(name = "scanner") final String scanner,
           @Attribute(name = "id") final String id,
           @Attribute(name = "position") final long position,
           @Attribute(name = "numsubpods") final long numsubpods,
           @ElementList(inline = true, name = "subpods") final List<SubPod> subpods,
           @Element(name = "states") final States states,
           @Element(name = "infos") final Infos infos,
           @Element(name = "definitions", required = false) final Definitions definitions) {
    this.error = error;
    this.title = title;
    this.scanner = scanner;
    this.id = id;
    this.position = position;
    this.numsubpods = numsubpods;
    this.subpods = subpods;
    this.primary = primary;
    this.states = states;
    this.infos = infos;
    this.definitions = definitions;
}
 
Example #5
Source File: AnnotationFactory.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: ConstructorParameterMatchTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public BoardStateMove(
      @Attribute(name="from") String from,
      @Attribute(name="to") String to,
      @Attribute(name="fromPiece") String fromPiece,
      @Attribute(name="toPiece") String toPiece,
      @Attribute(name="moveDirection") String moveDirection)
{
   this.moveDirection = moveDirection;
   this.fromPiece = fromPiece;
   this.toPiece = toPiece;
   this.from = from;
   this.to = to;
}
 
Example #7
Source File: SpellCheck.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public SpellCheck(@Attribute(name = "suggestion") final String suggestion,
                  @Attribute(name = "text") final String text,
                  @Attribute(name = "word") final String word) {
    this.suggestion = suggestion;
    this.text = text;
    this.word = word;
}
 
Example #8
Source File: StateList.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public StateList(@Attribute(name = "count") final long count,
                 @Attribute(name = "delimiters", required = false) final String delimiters,
                 @ElementList(inline = true, name = "state") final List<State> state,
                 @Attribute(name = "value", required = false) final String value) {
    this.count = count;
    this.delimiters = delimiters;
    this.state = state;
    this.value = value;
}
 
Example #9
Source File: States.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public States(@Attribute(name = "count") final long count,
              @ElementList(inline = true, name = "state") final List<State> state,
              @Element(name = "statelist", required = false) final StateList stateList) {
    this.count = count;
    this.state = state;
    this.stateList = stateList;
}
 
Example #10
Source File: MethodScannerDefaultTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testExtendedAnnotations() throws Exception {
   Map<String, Contact> map = getContacts(ExtendedAnnotations.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(Element.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(Element.class, map.get("array").getAnnotation(Element.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));
}
 
Example #11
Source File: Warnings.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public Warnings(@Attribute(name = "count") final long count,
                @Element(name = "reinterpret", required = false) final Reinterpret reinterpret,
                @Element(name = "spellcheck", required = false) final SpellCheck spellcheck) {
    this.count = count;
    this.reinterpret = reinterpret;
    this.spellcheck = spellcheck;
}
 
Example #12
Source File: MethodScannerDefaultTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #13
Source File: Assumption.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public Assumption(@Attribute(name = "count") final long count,
                  @Attribute(name = "template", required = false) final String template,
                  @Attribute(name = "type") final String type,
                  @ElementList(inline = true, name = "value") final List<Value> values,
                  @Attribute(name = "word", required = false) final String word,
                  @Attribute(name = "current", required = false) final long current,
                  @Attribute(name = "desc", required = false) final String desc) {
    this.count = count;
    this.template = template;
    this.type = type;
    this.values = values;
    this.word = word;
    this.current = current;
    this.desc = desc;
}
 
Example #14
Source File: Reinterpret.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public Reinterpret(@Attribute(name = "level", required = false) final String level,
                   @Attribute(name = "new", required = false) final String replaced,
                   @Attribute(name = "score", required = false) final double score,
                   @Attribute(name = "text", required = false) final String text,
                   @ElementList(inline = true, name = "alternative", required = false)
                   final List<Alternative> alternatives) {
    this.level = level;
    this.replaced = replaced;
    this.score = score;
    this.text = text;
    this.alternatives = alternatives;
}
 
Example #15
Source File: ParameterFactory.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #16
Source File: SignatureScanner.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #17
Source File: LabelExtractor.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: AttributeParameter.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**   
 * Constructor for the <code>AttributeParameter</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 index this is the index the parameter appears at
 * @param format this is the format used to style the paths
 */
public AttributeParameter(Constructor factory, Attribute value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new AttributeLabel(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;
}
 
Example #19
Source File: StructureBuilder.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
   }
}
 
Example #20
Source File: AttributeLabel.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the <code>AttributeLabel</code> object. This 
 * is used to create a label that can convert from an object to an
 * XML attribute and vice versa. This requires the annotation and
 * contact extracted from the XML schema class.
 * 
 * @param contact this is the field from the XML schema class
 * @param label represents the annotation for the field
 * @param format this is the format used to style the path
 */
public AttributeLabel(Contact contact, Attribute label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.decorator = new Qualifier(contact);
   this.required = label.required();
   this.type = contact.getType();
   this.empty = label.empty();
   this.name = label.name();      
   this.format = format;
   this.label = label; 
}
 
Example #21
Source File: ConstructorInjectionMatchParametersTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Example(
      @Attribute(name="name") String name,
      @Element(name="value") String value,
      @Attribute(name="type") Integer type)
{
   this.name = name;
   this.value = value;
   this.type = type;
}
 
Example #22
Source File: Test1Test.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Test1(
      @Attribute(name="iri") final String identifier,
      @Path(value="resource")@Attribute(name="iri") final String identifier1)
{
   super();
   this.identifier = identifier;
   this.identifier1 = identifier1;
}
 
Example #23
Source File: NestedElementTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public NestedElementExample(
        @Element(name="city") String city,
        @Element(name="street") String street,
        @Element(name="mobile") String mobile,
        @Element(name="home") String home,
        @Attribute(name="area-code") int areaCode) 
{
   this.city=city;
   this.street=street;
   this.mobile=mobile;
   this.home=home;   
   this.areaCode = areaCode;
}
 
Example #24
Source File: PathWithTextAndElementTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
private OtherPathWithTextAndElementExample(
      @Path("valuePath/path") @Attribute(name="name") String a,
      @Path("someOtherPath/path") @Element(name="name") String b,
      @Text String c) 
{
   this.a = a;
   this.b = b;
   this.c = c;
}
 
Example #25
Source File: PathWithTextAndElementTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
private PathWithMultipleTextExample(
      @Attribute(name="a") String a,
      @Path("valuePath[1]") @Text String b,
      @Attribute(name="c") String c,
      @Path("valuePath[2]") @Text String d)
{
   this.a = a;
   this.b = b;
   this.c = c;
   this.d = d;
}
 
Example #26
Source File: PathConstructorAmbiguityTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Test1(
      @Attribute(name="iri")  String identifier,
      @Path(value="resource") @Attribute(name="iri") String identifier1)
{
   this.identifier = identifier;
   this.identifier1 = identifier1;
}
 
Example #27
Source File: DecoratorTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public Friend(@Element(name="member") Member member, @ElementList(name="messages") List<Message> messages, @Attribute(name="status") Status status) {
    this.messages = messages;
    this.member = member;
    this.status = status;
}
 
Example #28
Source File: DecoratorTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Attribute
public String getTitle() {
    return title;
}
 
Example #29
Source File: Sources.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
public Sources(@Attribute(name = "count") final long count,
               @ElementList(inline = true, name = "source") final List<Source> sources) {
    this.count = count;
    this.sources = sources;
}
 
Example #30
Source File: DecoratorTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Attribute
public void setTitle(String title) {
    this.title = title;
}