4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
SugDateTimeAttribute.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: SugDateTimeAttribute.java
5  * Description: Class representing attribute of type DateTimefor prupose of suggestion
6  */
7 
8 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.attributes;
9 
12 import java.util.Date;
13 import java.util.TimeZone;
14 import javax.persistence.DiscriminatorValue;
15 import javax.persistence.Entity;
16 
17 /**
18  * @file SugDateTimeAttribute.java
19  *
20  * @brief Class representing attribute of type DateTime prupose of suggestion
21  */
22 
23 /**
24  * Class representing attribute of type DateTime prupose of suggestion
25  *
26  * @brief Class representing attribute of type DateTime prupose of suggestion
27  */
28 @Entity
29 @DiscriminatorValue("DateTime")
31  /**
32  * Gets value of the attribute
33  *
34  * @return value of the attribute
35  */
36  @Override
37  public Object getValue() {
38  return dateValue;
39  }
40 
41  /**
42  * Sets value of the attribute. Value should already be a native java Date value.
43  *
44  * @param value new value of the attribute
45  */
46  @Override
47  public void setValue(Object value) {
48  this.dateValue = (Date) value;
49  }
50 
51  /**
52  * Converts date to string in format according to RFC 3339
53  *
54  * @return Date in string in format according to RFC 3339
55  */
56  @Override
57  protected String xmlFormatValue() {
58  if (dateValue == null) {
59  return "";
60  }
61  if(this.stringValue != null){
62  String originalOffset = TimeZone.getDefault().getID();
63  TimeZone.setDefault(TimeZone.getTimeZone("GMT" + this.stringValue));
64  String ret = Util.toRFC3339Date(dateValue);
65  TimeZone.setDefault(TimeZone.getTimeZone(originalOffset));
66  return ret;
67  }
68  else{
69  return Util.toRFC3339Date(dateValue);
70  }
71  }
72 
73  /**
74  * Parses provided value and sets that value as a value of attribute
75  *
76  * @param value Date time value in format according to RFC 3339
77  */
78  @Override
79  public void setRawValue(String value) throws IllegalArgumentException {
80  String zone = Util.parseTimeZoneID(value);
81  String originalOffset = TimeZone.getDefault().getID();
82  if(zone != null){
83  TimeZone.setDefault(TimeZone.getTimeZone("GMT" + zone));
84  this.stringValue = zone;
85  }
86  try {
87  this.dateValue = Util.parseRFC3339Date(value);
88  } catch (Exception e) {
89  throw new IllegalArgumentException("Value " + value + " is not a valid RFC3339 date time");
90  }
91  if(zone != null){
92  TimeZone.setDefault(TimeZone.getTimeZone(originalOffset));
93  }
94  }
95 
96  /**
97  * Gets URI addres in ontology for this type of attribute
98  *
99  * @return Return URI addres in ontology for this type of attribute.
100  */
101  @Override
102  public String getTypeOntologyUri(){
104  }
105 }
Class representing attribute of type DateTime prupose of suggestion.
Utility class (manipulates RFC 3339 dates)
Definition: Util.java:29