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