1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.opensaml.ws.wssecurity.impl;
19
20 import org.joda.time.DateTime;
21 import org.joda.time.chrono.ISOChronology;
22 import org.joda.time.format.DateTimeFormatter;
23 import org.joda.time.format.ISODateTimeFormat;
24 import org.opensaml.ws.wssecurity.AttributedDateTime;
25 import org.opensaml.ws.wssecurity.IdBearing;
26 import org.opensaml.xml.util.AttributeMap;
27
28
29
30
31
32 public class AttributedDateTimeImpl extends AbstractWSSecurityObject implements AttributedDateTime {
33
34
35 private DateTimeFormatter formatter;
36
37
38 private DateTime dateTimeValue;
39
40
41 private String stringValue;
42
43
44 private String id;
45
46
47 private AttributeMap unknownAttributes;
48
49
50
51
52
53
54
55
56 public AttributedDateTimeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
57 super(namespaceURI, elementLocalName, namespacePrefix);
58 formatter = ISODateTimeFormat.dateTime().withChronology(ISOChronology.getInstanceUTC());
59 unknownAttributes = new AttributeMap(this);
60 }
61
62
63 public DateTime getDateTime() {
64 return dateTimeValue;
65 }
66
67
68 public void setDateTime(DateTime newDateTime) {
69 dateTimeValue = newDateTime;
70 String formattedDateTime = formatter.print(dateTimeValue);
71 stringValue = prepareForAssignment(stringValue, formattedDateTime);
72 }
73
74
75 public String getValue() {
76 return stringValue;
77 }
78
79
80 public void setValue(String newValue) {
81 dateTimeValue = new DateTime(newValue).withChronology(ISOChronology.getInstanceUTC());
82 stringValue = prepareForAssignment(stringValue, newValue);
83 }
84
85
86 public String getWSUId() {
87 return id;
88 }
89
90
91 public void setWSUId(String newId) {
92 String oldID = id;
93 id = prepareForAssignment(id, newId);
94 registerOwnID(oldID, id);
95 manageQualifiedAttributeNamespace(IdBearing.WSU_ID_ATTR_NAME, id != null);
96 }
97
98
99 public AttributeMap getUnknownAttributes() {
100 return unknownAttributes;
101 }
102
103
104 public DateTimeFormatter getDateTimeFormatter() {
105 return formatter;
106 }
107
108
109 public void setDateTimeFormatter(DateTimeFormatter newFormatter) {
110 if (newFormatter == null) {
111 throw new IllegalArgumentException("The specified DateTimeFormatter may not be null");
112 }
113 formatter = newFormatter;
114
115 setDateTime(getDateTime());
116 }
117
118 }