4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
StructuredAttribute.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: StructuredAttribute.java
5  * Description: Base class for more complex attributes, which are stored in
6  * different table, such as Person, GeoPoint...
7  */
8 
9 package cz.vutbr.fit.knot.annotations.entity.attribute;
10 
12 import java.util.Iterator;
13 import javax.persistence.MappedSuperclass;
14 
15 /**
16  * @file StructuredAttribute.java
17  *
18  * @brief Abstract class representing more complex attribute
19  */
20 
21 /**
22  * Abstract class representing more complex attribute
23  *
24  * @brief Abstract class representing more complex attribute
25  */
26 @MappedSuperclass
27 public abstract class StructuredAttribute extends BaseAttribute {
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 = refAnnotation.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 tmpIdForNested If true, nested annotations will have attribute tmpId
122  * @param withOntology If true, URI in ontology will be serialized, if false, it will be omittedv
123  * @return Returns serialized informations about attribute of annotation in XML
124  */
125  @Override
126  public String toXMLString(boolean proto11, boolean tmpIdForNested, boolean withOntology) {
127 
128  if (this.getValue() == null) {
129  return super.toXMLString(proto11, tmpIdForNested, false);
130  }
131  return getXmlStart(withOntology)
132  + getXmlBody()
133  + getCommentXmlPart(proto11)
134  + getXmlEnd();
135  }
136 
137  /**
138  * Parses provided value and sets that value as a value of attribute
139  *
140  * This method should not be used because structured attributes are not
141  * represented by single value.
142  *
143  * @param value new value of the attribute in raw form from XML
144  */
145  @Override
146  public void setRawValue(String value) throws IllegalArgumentException {
147  throw new UnsupportedOperationException("Structured attributes are not represented by single value.");
148  }
149 
150  /**
151  * Checks if attribute is structured. Structured attribute is for example
152  * GeoPointAttribute
153  *
154  * @return true, if attribute is structured
155  */
156  @Override
157  public boolean isStructured() {
158  return true;
159  }
160 
161  /**
162  * Parses provided values and sets that values as a values of the attribute
163  *
164  * @param values New values of the attribute in raw forms from XML
165  */
166  public abstract void setRawValues(Object values) throws IllegalArgumentException;
167 
168 
169  /**
170  * XML of the structured attribute looks like this:
171  * @verbatim
172  * <a:attribute ...... >
173  * <nested>
174  * <value1>...</value1>
175  * <value2>...</value2>
176  * </nested>
177  * </a:attribute>
178  * @endverbatim
179  *
180  * @return the name of the "nested" attribute
181  */
182  public abstract String getXmlAttributeName();
183 
184  /**
185  * Gets URI addres in ontology for this type of attribute
186  *
187  * @return Return URI addres in ontology for this type of attribute.
188  */
189  @Override
190  public String getTypeOntologyUri(){
191  if(this.attributeType.getUriInOntology() != null)
192  {
193  return this.attributeType.getUriInOntology();
194  }else
195  {
196  return "";
197  }
198  }
199 } // StructuredAttribute()
String toXMLString(boolean proto11, boolean tmpIdForNested, boolean withOntology)
Class representing attribute of type of annotation.
Abstract class representing more complex attribute.
Base class representing attribute of annotation.