4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
SugStructuredAttribute.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: SugStructuredAttribute.java
5  * Description: Base class for more komplex attributes of suggestion, which are stored in
6  * different table, such as Person, GeoPoint...
7  */
8 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.attributes;
9 
11 import java.util.Iterator;
12 import javax.persistence.MappedSuperclass;
13 
14 /**
15  * @file SugStructuredAttribute.java
16  *
17  * @brief Abstract class representing more complex attribute of suggestion
18  */
19 
20 
21 /**
22  * Abstract class representing more complex attribute of suggestion
23  *
24  * @brief Abstract class representing more complex attribute of suggestion
25  */
26 @MappedSuperclass
27 public abstract class SugStructuredAttribute extends SugBaseAttribute {
28 
29  /**
30  * Helper function,which returns XML part for comments.
31  *
32  * @param proto11 If true, protocol version is greater then 1.0
33  * @return XML part for comments
34  */
35  @Override
36  public String getCommentXmlPart(boolean proto11) {
37  return "<a:comment>"
38  + "<![CDATA["
39  + comment
40  + "]]>"
41  + "</a:comment>";
42  }
43 
44  /**
45  * XML of the structured attribute looks like this:
46  * @verbatim
47  * <a:attribute ...... >
48  * <nested>
49  * <value1>...</value1>
50  * <value2>...</value2>
51  * </nested>
52  * </a:attribute>
53  * @endverbatim
54  *
55  * This method returns the starting element for the a:attribute element.
56  *
57  * @param withOntology If true, URI in ontology will be serialized, if false, it will be omitted
58  * @return Returns the starting element for the a:attribute element.
59  */
60  protected String getXmlStart(boolean withOntology) {
61  String ontoString = "";
62  if(withOntology){
63  if(!getTypeOntologyUri().isEmpty()){
64  ontoString += " typeOntologyUri=\""+getTypeOntologyUri()+"\"";
65  }
66 
67  Iterator<AnnotTypeAttr> typeAttrIt = refSuggestion.getAnnotType().getAttributes().iterator();
68  while(typeAttrIt.hasNext()){
69  AnnotTypeAttr actualAttr = typeAttrIt.next();
70  if(name.equals(actualAttr.getName())){
71  if(actualAttr.getUriInOntology() != null){
72  ontoString += " ontologyUri=\"" + actualAttr.getUriInOntology() + "\"";
73  }
74  }
75  }
76  }
77  return "<a:attribute name=\"" + name + "\"" + ontoString + " type=\"" + simpleType + "\">";
78  }
79 
80  /**
81  * XML of the structured attribute looks like this:
82  * @verbatim
83  * <a:attribute ...... >
84  * <nested>
85  * <value1>...</value1>
86  * <value2>...</value2>
87  * </nested>
88  * </a:attribute>
89  * @endverbatim
90  *
91  * This method returns the ending element for the a:attribute element.
92  *
93  * @return Returns the ending element for the a:attribute element.
94  */
95  protected String getXmlEnd() {
96  return "</a:attribute>";
97  }
98 
99  /**
100  * XML of the structured attribute looks like this:
101  * @verbatim
102  * <a:attribute ...... >
103  * <nested>
104  * <value1>...</value1>
105  * <value2>...</value2>
106  * </nested>
107  * </a:attribute>
108  * @endverbatim
109  *
110  * This method returns the content of the a:attribute element with all nested
111  * elements.
112  *
113  * @return Returns the content of the a:attribute element with all nested elements.
114  */
115  protected abstract String getXmlBody();
116 
117  /**
118  * Returns serialized informations about attribute of annotation in XML
119  *
120  * @param proto11 If true, protocol version is greater then 1.0
121  * @param withOntology If true, URI in ontology will be serialized, if false, it will be omitted
122  * @return Returns serialized informations about attribute of annotation in XML
123  */
124  @Override
125  public String toXMLString(boolean proto11, boolean withOntology) {
126 
127  if (this.getValue() == null) {
128  return super.toXMLString(proto11, false);
129  }
130  return getXmlStart(withOntology)
131  + getXmlBody()
132  + getCommentXmlPart(proto11)
133  + getXmlEnd();
134  }
135 
136  /**
137  * Parses provided value and sets that value as a value of attribute
138  *
139  * This method should not be used because structured attributes are not
140  * represented by single value.
141  *
142  * @param value new value of the attribute in raw form from XML
143  */
144  @Override
145  public void setRawValue(String value) throws IllegalArgumentException {
146  throw new UnsupportedOperationException("Structured attributes are not represented by single value.");
147  }
148 
149  /**
150  * Checks if attribute is structured. Structured attribute is for example
151  * GeoPointAttribute
152  *
153  * @return true, if attribute is structured
154  */
155  @Override
156  public boolean isStructured() {
157  return true;
158  }
159 
160  /**
161  * Parses provided values and sets that values as a values of the attribute
162  *
163  * @param values New values of the attribute in raw forms from XML
164  */
165  public abstract void setRawValues(Object values) throws IllegalArgumentException;
166 
167 
168  /**
169  * XML of the structured attribute looks like this:
170  * @verbatim
171  * <a:attribute ...... >
172  * <nested>
173  * <value1>...</value1>
174  * <value2>...</value2>
175  * </nested>
176  * </a:attribute>
177  * @endverbatim
178  *
179  * @return the name of the "nested" attribute
180  */
181  public abstract String getXmlAttributeName();
182 
183  /**
184  * Gets URI addres in ontology for this type of attribute
185  *
186  * @return Return URI addres in ontology for this type of attribute.
187  */
188  @Override
189  public String getTypeOntologyUri(){
190  if(this.attributeType.getUriInOntology() != null)
191  {
192  return this.attributeType.getUriInOntology();
193  }else
194  {
195  return "";
196  }
197  }
198 } // public abstract class SugStructuredAttribute
Class representing attribute of type of annotation.