4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
TextAttribute.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz, Jan Planer xplane01@stud.fit.vutbr.cz
4  * File: TextAttribute.java
5  * Description: Class representing attribute of type Text
6  */
7 
8 package cz.vutbr.fit.knot.annotations.entity.attribute;
9 
12 import java.util.Iterator;
13 import javax.persistence.DiscriminatorValue;
14 import javax.persistence.Entity;
15 
16 /**
17  * @file TextAttribute.java
18  *
19  * @brief Class representing attribute of type Text.
20  */
21 
22 /**
23  * Class representing attribute of type Text.
24  *
25  * @brief Class representing attribute of type Text.
26  */
27 @Entity
28 @DiscriminatorValue(value="Text")
29 public class TextAttribute extends StringAttribute {
30 
31  /**
32  * Gets value of the attribute
33  *
34  * @return value of the attribute
35  */
36  @Override
37  public Object getValue() {
38  return this.textValue;
39  }
40 
41  /**
42  * Sets value of the attribute. Value should already be a native java value.
43  *
44  * @param value New value of the attribute
45  */
46  @Override
47  public void setValue(Object value) {
48  this.textValue = (String) value;
49  }
50 
51  /**
52  * Parses provided value and sets that value as a value of attribute
53  *
54  * @param value new value of the attribute in raw form from XML
55  */
56  @Override
57  public void setRawValue(String value) {
58  this.setValue(value);
59  }
60 
61  /**
62  * Helper function,which returns XML part for comments.
63  *
64  * @param proto11 If true, protocol version is greater then 1.0
65  * @return XML part for comments
66  */
67  @Override
68  public String getCommentXmlPart(boolean proto11) {
69  return "<a:comment>"
70  + "<![CDATA["
71  + comment
72  + "]]>"
73  + "</a:comment>";
74  }
75 
76  /**
77  * Returns serialized informations about attribute of annotation in XML
78  *
79  * @param proto11 If true, protocol version is greater then 1.0
80  * @param tmpIdForNested If true, nested annotations will have attribute tmpId
81  * @param withOntology If true, URI in ontology will be serialized, if false, it will be omitted
82  * @return Returns serialized informations about attribute of annotation in XML
83  */
84  @Override
85  public String toXMLString(boolean proto11, boolean tmpIdForNested, boolean withOntology) {
86  String ontoString = "";
87 
88  if(withOntology){
89  if(!getTypeOntologyUri().isEmpty()){
90  ontoString += " typeOntologyUri=\""+getTypeOntologyUri()+"\"";
91  }
92 
93  Iterator<AnnotTypeAttr> typeAttrIt = refAnnotation.getAnnotType().getAttributes().iterator();
94  while(typeAttrIt.hasNext()){
95  AnnotTypeAttr actualAttr = typeAttrIt.next();
96  if(name.equals(actualAttr.getName())){
97  if(actualAttr.getUriInOntology() != null){
98  ontoString += " ontologyUri=\"" + actualAttr.getUriInOntology() + "\"";
99  }
100  }
101  }
102  }
103 
104  if (this.textValue == null) {
105  return "<a:attribute name=\"" + name + "\"" + ontoString + " type=\"" + simpleType + "\">"
106  + "<a:Content>"
107  + "<![CDATA[]]>"
108  + "</a:Content>"
109  + getCommentXmlPart(proto11)
110  + "</a:attribute>";
111  }
112  return "<a:attribute name=\"" + name + "\"" + ontoString + " type=\"" + simpleType + "\">"
113  + "<a:Content>"
114  + "<![CDATA["
115  + this.textValue
116  + "]]>"
117  + "</a:Content>"
118  + getCommentXmlPart(proto11)
119  + "</a:attribute>";
120  }
121 
122  /**
123  * Gets URI addres in ontology for this type of attribute
124  *
125  * @return Return URI addres in ontology for this type of attribute.
126  */
127  @Override
128  public String getTypeOntologyUri(){
129  return Constants.TEXT_URI;
130  }
131 } // class TextAttribute
Class representing attribute of type String..
Class representing attribute of type of annotation.
String toXMLString(boolean proto11, boolean tmpIdForNested, boolean withOntology)
Class representing attribute of type Text.