4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
PersonAttribute.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: PersonAttribute.java
5  * Description: Class representing attribute of type Person
6  */
7 
8 package cz.vutbr.fit.knot.annotations.entity.attribute;
9 
13 import javax.persistence.DiscriminatorValue;
14 import javax.persistence.Entity;
15 import javax.persistence.NamedQueries;
16 import javax.persistence.NamedQuery;
17 
18 /**
19  * @file PersonAttribute.java
20  *
21  * @brief Class representing attribute of type Person
22  */
23 
24 /**
25  * Class representing attribute of type Person (deprecated type)
26  *
27  * @brief Class representing attribute of type Person
28  */
29 @Entity
30 @DiscriminatorValue("person")
31 @NamedQueries({
32  @NamedQuery(name = "Attribute.findByUserValue", query = "SELECT a FROM Attribute a WHERE a.userValue = :userValue"),
33 })
34 public class PersonAttribute extends StructuredAttribute {
35 
36  /**
37  * Constructor
38  */
39  public PersonAttribute() {
40  }
41 
42  /**
43  * Constructor of attribute of type Person
44  *
45  * @param name Name of attribute
46  * @param person Value of attribute person (user)
47  * @param refAnnotation Annotation to which this attribute belongs
48  */
49  public PersonAttribute(String name, User person, Annotation refAnnotation) {
50  this.name = name;
51  this.simpleType = "person";
52  this.refAnnotation = refAnnotation;
53  this.user = person;
54  }
55 
56  /**
57  * Gets value of the attribute
58  *
59  * @return value of the attribute
60  */
61  @Override
62  public Object getValue() {
63  return this.user;
64  }
65 
66  /**
67  * Sets value of the attribute. Value should already be a native java value.
68  *
69  * @param person New value of the attribute
70  */
71  @Override
72  public void setValue(Object person) {
73  this.user = (User) person;
74  }
75 
76  /**
77  * XML of the structured attribute looks like this:
78  * @verbatim
79  * <a:attribute ...... >
80  * <nested>
81  * <value1>...</value1>
82  * <value2>...</value2>
83  * </nested>
84  * </a:attribute>
85  * @endverbatim
86  *
87  * This method returns the content of the a:attribute element with all nested
88  * elements.
89  *
90  * @return Returns the content of the a:attribute element with all nested elements.
91  */
92  @Override
93  protected String getXmlBody() {
94  return "<a:person id=\"" + user.getEmail() + "\"/>";
95  }
96 
97  /**
98  * Parses provided value and sets that value as a value of attribute
99  *
100  * This method should not be used, because this type of attribute is processed
101  * in MessageProcessor.
102  *
103  * @param values new value of the attribute in raw form from XML
104  */
105  @Override
106  public void setRawValues(Object values) throws IllegalArgumentException {
107  throw new UnsupportedOperationException("Server internal error.");
108  }
109 
110  /**
111  * XML of the structured attribute looks like this:
112  * @verbatim
113  * <a:attribute ...... >
114  * <nested>
115  * <value1>...</value1>
116  * <value2>...</value2>
117  * </nested>
118  * </a:attribute>
119  * @endverbatim
120  *
121  * @return the name of the "nested" attribute , which is "Person" for this type
122  */
123  @Override
124  public String getXmlAttributeName() {
125  return "Person";
126  }
127 
128  /**
129  * Gets URI addres in ontology for this type of attribute
130  *
131  * @return Return URI addres in ontology for this type of attribute.
132  */
133  @Override
134  public String getTypeOntologyUri(){
135  return Constants.PERSON_URI;
136  }
137 } // class PersonAttribute
Abstract class representing more complex attribute.
Class representing user.
Definition: User.java:51
PersonAttribute(String name, User person, Annotation refAnnotation)
Class representing attribute of type Person.