001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006,2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.poll.model;
021:
022: import java.util.Date;
023: import java.util.List;
024: import java.util.Stack;
025:
026: import org.sakaiproject.entity.api.ResourceProperties;
027: import org.sakaiproject.component.cover.ServerConfigurationService;
028: import org.w3c.dom.Document;
029: import org.w3c.dom.Element;
030: import org.sakaiproject.entity.api.Entity;
031:
032: import org.apache.commons.lang.builder.ToStringBuilder;
033:
034: public class PollImpl implements Poll {
035:
036: private static final long serialVersionUID = 1L;
037: private Long id;
038: private String owner;
039: private String siteId;
040: private Date creationDate;
041: private String pollText;
042: private String description;
043:
044: private int minOptions = 1;
045: private int maxOptions = 1;
046:
047: private Date voteOpen;
048: private Date voteClose;
049:
050: private List options;
051: private List votes;
052:
053: private String displayResult = "open";
054: private boolean limitVoting = true;
055:
056: public PollImpl() {
057: //set the defaults
058: this .pollText = "";
059: this .description = "";
060: this .minOptions = 1;
061: this .maxOptions = 1;
062: this .limitVoting = true;
063: this .voteOpen = new Date();
064: this .voteClose = new Date(voteOpen.getTime()
065: + (long) (7 * 24 * 60 * 60 * 100));
066: this .displayResult = "open";
067: }
068:
069: public Long getPollId() {
070: return id;
071: }
072:
073: public void setPollId(Long id) {
074: this .id = id;
075: }
076:
077: public String getOwner() {
078: return owner;
079: }
080:
081: public void setOwner(String owner) {
082: this .owner = owner;
083: }
084:
085: public String getSiteId() {
086: return siteId;
087: }
088:
089: public void setSiteId(String siteId) {
090: this .siteId = siteId;
091: }
092:
093: public Date getCreationDate() {
094: return creationDate;
095: }
096:
097: public void setCreationDate(Date creationDate) {
098: this .creationDate = creationDate;
099: }
100:
101: public String getText() {
102: return pollText;
103: }
104:
105: public void setText(String poll) {
106: this .pollText = poll;
107: }
108:
109: public void setMinOptions(int value) {
110: this .minOptions = value;
111: }
112:
113: public int getMinOptions() {
114: return this .minOptions;
115: }
116:
117: public void setMaxOptions(int value) {
118: this .maxOptions = value;
119: }
120:
121: public int getMaxOptions() {
122: return this .maxOptions;
123: }
124:
125: public void setVoteOpen(Date value) {
126: this .voteOpen = value;
127: }
128:
129: public Date getVoteOpen() {
130: return this .voteOpen;
131: }
132:
133: public void setVoteClose(Date value) {
134: this .voteClose = value;
135: }
136:
137: public Date getVoteClose() {
138: return this .voteClose;
139: }
140:
141: public void setDisplayResult(String value) {
142: this .displayResult = value;
143: }
144:
145: public String getDisplayResult() {
146: return this .displayResult;
147: }
148:
149: /**
150: * Options and operators for votes and options
151: */
152:
153: public void setVotes(List value) {
154: this .votes = value;
155: }
156:
157: public List getVotes() {
158: return this .votes;
159: }
160:
161: public void addVote(Vote vote) {
162: votes.add(vote);
163:
164: }
165:
166: public void setOptions(List value) {
167: this .options = value;
168: }
169:
170: public List getPollOptions() {
171: return this .options;
172: }
173:
174: public void addOption(Option option) {
175: this .options.add(option);
176:
177: }
178:
179: public void setLimitVoting(boolean value) {
180: this .limitVoting = value;
181: }
182:
183: public boolean getLimitVoting() {
184: return this .limitVoting;
185:
186: }
187:
188: public void setDetails(String value) {
189: this .description = value;
190: }
191:
192: public String getDetails() {
193: return this .description;
194: }
195:
196: /*
197: * Basic comparison functions for objects
198: * Uses commons-lang to make it so we can be sure about comparisons as long
199: * as the data in the object is the same
200: */
201:
202: public String toString() {
203: return new ToStringBuilder(this ).append(this .id).append(
204: this .owner).append(this .siteId).append(
205: this .creationDate).append(this .pollText).toString();
206: }
207:
208: /*
209: * Entity Methods
210: */
211: public String getUrl() {
212: return ServerConfigurationService.getAccessUrl() + "/poll/"
213: + this .getId();
214: }
215:
216: public String getReference() {
217:
218: return ServerConfigurationService.getAccessUrl() + "/poll/"
219: + Entity.SEPARATOR + this .getId();
220: }
221:
222: public String getUrl(String arg0) {
223:
224: return getUrl();
225: }
226:
227: public String getReference(String arg0) {
228:
229: return getReference();
230: }
231:
232: public String getId() {
233: // TODO Auto-generated method stub
234: return null;
235: }
236:
237: public ResourceProperties getProperties() {
238: // TODO Auto-generated method stub
239: return null;
240: }
241:
242: public Element toXml(Document arg0, Stack arg1) {
243: // TODO Auto-generated method stub
244: return null;
245: }
246:
247: }
|