1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.r2.common.dto;
17
18 import java.io.Serializable;
19 import java.util.Date;
20 import java.util.List;
21
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAnyElement;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlType;
27
28 import org.kuali.student.r2.common.infc.Context;
29
30
31
32
33
34
35 @XmlAccessorType(XmlAccessType.FIELD)
36 @XmlType(name = "ContextInfo", propOrder = {
37 "authenticatedPrincipalId", "principalId",
38 "currentDate", "locale", "timeZone",
39 "attributes", "_futureElements" })
40
41 public class ContextInfo
42 extends HasAttributesInfo
43 implements Context, Serializable {
44
45 private static final long serialVersionUID = 1L;
46
47 @XmlElement
48 private String authenticatedPrincipalId;
49
50 @XmlElement
51 private String principalId;
52
53 @XmlElement
54 private Date currentDate;
55
56 @XmlElement
57 private LocaleInfo locale;
58
59 @XmlElement
60 private String timeZone;
61
62 @XmlAnyElement
63 private List<Object> _futureElements;
64
65
66
67
68
69 public ContextInfo() {
70 this.locale = new LocaleInfo();
71 this.currentDate = new Date();
72 }
73
74
75
76
77
78
79 public ContextInfo(Context context) {
80 super(context);
81
82 this.authenticatedPrincipalId = context.getAuthenticatedPrincipalId();
83 this.principalId = context.getPrincipalId();
84
85 if (context.getLocale() != null) {
86 this.locale = new LocaleInfo(context.getLocale());
87 }
88
89 if (context.getCurrentDate() != null) {
90 this.currentDate = new Date(context.getCurrentDate().getTime());
91 } else {
92 this.currentDate = new Date();
93 }
94
95 this.timeZone = context.getTimeZone();
96 }
97
98 @Override
99 public String getAuthenticatedPrincipalId() {
100 return authenticatedPrincipalId;
101 }
102
103 public void setAuthenticatedPrincipalId(String authenticatedPrincipalId) {
104 this.authenticatedPrincipalId = authenticatedPrincipalId;
105 }
106
107 @Override
108 public String getPrincipalId() {
109 return principalId;
110 }
111
112 public void setPrincipalId(String principalId) {
113 this.principalId = principalId;
114 }
115
116 @Override
117 public Date getCurrentDate() {
118 return currentDate;
119 }
120
121 public void setCurrentDate(Date currentDate) {
122 this.currentDate = currentDate;
123 }
124
125 @Override
126 public LocaleInfo getLocale() {
127 return this.locale;
128 }
129
130 public void setLocale(LocaleInfo locale) {
131 this.locale = locale;
132 }
133
134 @Override
135 public String getTimeZone() {
136 return timeZone;
137 }
138
139 public void setTimeZone(String timeZone) {
140 this.timeZone = timeZone;
141 }
142
143
144
145 @Deprecated
146 public static ContextInfo getInstance(String principalId, String localeLanguage, String localeRegion) {
147 LocaleInfo localeInfo = new LocaleInfo();
148 localeInfo.setLocaleLanguage(localeLanguage);
149 localeInfo.setLocaleRegion(localeRegion);
150
151 ContextInfo ctx = new ContextInfo();
152 ctx.setAuthenticatedPrincipalId(principalId);
153 ctx.setPrincipalId(principalId);
154 ctx.setLocale(localeInfo);
155
156 return ctx;
157 }
158 }