org.simpleframework.xml.Text Java Examples

The following examples show how to use org.simpleframework.xml.Text. 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: 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 #2
Source File: TextLabel.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the <code>TextLabel</code> object. This is
 * used to create a label that can convert a XML node into a 
 * primitive value from an XML element text value.
 * 
 * @param contact this is the contact this label represents
 * @param label this is the annotation for the contact 
 * @param format this is the format used for this label
 */
public TextLabel(Contact contact, Text label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.required = label.required();
   this.type = contact.getType();
   this.empty = label.empty();
   this.data = label.data();
   this.contact = contact;
   this.label = label;  
}
 
Example #3
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 #4
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 #5
Source File: PathWithTextAndElementTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
private PathWithTextAndElementExample(
      @Text String text,
      @Path("some/path") @Attribute(name="name") String value,
      @Path("some") @Element(name="name") String item) 
{
   this.item = item;
   this.value = value;
   this.text = text;
}
 
Example #6
Source File: Alternative.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
public Alternative(@Attribute(name = "level", required = false) final String level,
                   @Attribute(name = "score", required = false) final double score,
                   @Text final String text) {
    this.level = level;
    this.score = score;
    this.text = text;
}
 
Example #7
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 #8
Source File: GroupExtractor.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * This is used to register the provided label is a text label.
 * Registration as a text label can only happen if the field or
 * method has a <code>Text</code> annotation declared on it.
 * 
 * @param label this is the label to register as text
 */
private void registerText(Label label) throws Exception {
   Contact contact = label.getContact();
   Text value = contact.getAnnotation(Text.class);
   
   if(value != null) {
      text = new TextListLabel(label, value);
   }
}
 
Example #9
Source File: TextParameter.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**   
 * Constructor for the <code>TextParameter</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 for this parameter
 * @param index this is the index the parameter appears at
 */
public TextParameter(Constructor factory, Text value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new TextLabel(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 #10
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 #11
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 #12
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 #13
Source File: MethodScanner.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>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);
   }
}
 
Example #14
Source File: FieldScanner.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>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);
   }
}
 
Example #15
Source File: StaticTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text
private String getContent() {
   return text;
}
 
Example #16
Source File: ConstructorScannerTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public ClashInText(
@Path("a/b/x") @Text String a,
@Path("a/b/x") @Text String b){}
 
Example #17
Source File: StaticTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text
public void setContent(String text) {
   this.text = text;
}
 
Example #18
Source File: DecoratorTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text(data=true)
public String getText() {
    return text;
}
 
Example #19
Source File: DecoratorTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text(data=true)
public void setText(String text) {
    this.text = text;
}
 
Example #20
Source File: MethodScannerTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text
public long getLength() {
   return length;
}
 
Example #21
Source File: OrderWithInvalidPathAndTextTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public InvalidOrder(@Text String text) {
   this.text = text;
}
 
Example #22
Source File: TextConstructorInjectionWithTransformTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public Embargo(@Text DateTime embargo_datetime, @Attribute(name="name") String name) {
    this.embargo_datetime = embargo_datetime;
    this.name = name;
}
 
Example #23
Source File: MethodScannerTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text
public void setLength(long length) {
   this.length = length;
}
 
Example #24
Source File: PathTextTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public TextExample(
      @Path("path[1]/details") @Text String x, 
      @Path("path[2]/details") @Text String z) {
   this.a = x;
   this.b = z;
}
 
Example #25
Source File: TutorialTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text
public void setContent(String text) {
   this.text = text;
}
 
Example #26
Source File: TutorialTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
@Text
private String getContent() {
   return text;
}
 
Example #27
Source File: PathWithTextInAPathTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public InvalidTextWithCrossingPath(
   @Path("a/b") @Text String a,
   @Path("a/b/c") @Text String b) {
      this.a = a;
      this.b = b;
}
 
Example #28
Source File: PathWithTextInAPathTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public InvalidTextWithElement(
   @Text String a,
   @Element(name="c") String b) {
      this.a = a;
      this.b = b;
}
 
Example #29
Source File: ConstructorScannerTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public ClashBetweenElementUnionAndText(
@Path("a/b") @ElementUnion({
   @Element(name="x"),
   @Element(name="y")
}) String a,
@Path("a/b/x") @Text String b){}
 
Example #30
Source File: ConstructorScannerTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public ClashBetweenElementAndText(
@Path("a/b/c") @Text String a,
@Element(name="c") String c) {}