4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
SugDurationAttribute.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: SugDurationAttribute.java
5  * Description: Class representing attribute of type Duration for prupose of suggestion
6  */
7 
8 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.attributes;
9 
11 import javax.persistence.DiscriminatorValue;
12 import javax.persistence.Entity;
13 import javax.xml.datatype.DatatypeFactory;
14 import javax.xml.datatype.Duration;
15 
16 /**
17  * @file SugDurationAttribute.java
18  *
19  * @brief Class representing attribute of type Duration for prupose of suggestion
20  */
21 
22 /**
23  * Class representing attribute of type Duration
24  *
25  * @brief Class representing attribute of type Duration for prupose of suggestion
26  */
27 @Entity
28 @DiscriminatorValue("Duration")
29 public class SugDurationAttribute extends SugBaseAttribute {
30 
31  /**
32  * Gets value of the attribute
33  *
34  * @return object of type Duration
35  */
36  @Override
37  public Object getValue() {
38  try {
39  return (Object) DatatypeFactory.newInstance().newDuration(this.stringValue);
40  } catch (Exception e) {
41  return null;
42  }
43  }
44 
45  /**
46  * Returns string representation of duration according to RFC 3339
47  *
48  * @return string representation of duration according to RFC 3339
49  */
50  @Override
51  public String getStringValue() {
52  return this.stringValue;
53  }
54 
55  /**
56  * Sets value of the attribute. Value should already be a native java Duration value.
57  *
58  * @param value object of type Duration
59  */
60  @Override
61  public void setValue(Object value) {
62  this.stringValue = ((Duration) value).toString();
63  }
64 
65  /**
66  * Parses provided value and sets that value as a value of attribute
67  *
68  * @param value new value of the attribute in raw form from XML
69  */
70  @Override
71  public void setRawValue(String value) throws IllegalArgumentException {
72  try {
73  Duration d = DatatypeFactory.newInstance().newDuration(value);
74  this.stringValue = d.toString();
75  } catch (Exception e) {
76  throw new IllegalArgumentException("Value " + value
77  + " is not a valid Duration value according to http://www.w3.org/TR/xmlschema-2/#duration");
78  }
79  }
80 
81  /**
82  * Checks if attribute value is empty or default value
83  *
84  * @return true, if attribute value is empty
85  */
86  @Override
87  public boolean isEmpty() {
88  return stringValue == null || stringValue.equals("");
89  }
90 
91  /**
92  * Gets URI addres in ontology for this type of attribute
93  *
94  * @return Return URI addres in ontology for this type of attribute.
95  */
96  @Override
97  public String getTypeOntologyUri(){
99  }
100 }
Class representing attribute of type Duration for prupose of suggestion.