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