View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the
5    * "License"); you may not use this file except in compliance with the
6    * License.  You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * The DTO for a Context.
32   *
33   * @author Kamal
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       * Constructs a new ContextInfo.
68       */
69      public ContextInfo() {
70          this.locale = new LocaleInfo();
71          this.currentDate = new Date();
72      }
73  
74      /**
75       * Constructs a new ContextInfo from another Context.
76       *
77       * @param context the context to copy
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     // Compatibility methods
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 }