View Javadoc

1   /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   *
19   * For further informations on the SmartWeb Framework please visit
20   *
21   *                        http://smartweb.sourceforge.net
22   */
23   
24  package net.smartlab.web.poll;
25  
26  import java.util.List;
27  
28  import net.smartlab.web.Enumeration;
29  
30  /**
31   * TODO documentation
32   * @author rlogiacco
33   */
34  public class Question {
35  
36  	private long id;
37  
38  	private String title;
39  
40  	private String description;
41  
42  	private Type type;
43  	
44  	private boolean required;
45  
46  	/**
47  	 * @directed directed
48  	 * @link aggregation <{net.smartlab.web.poll.Answer}>
49  	 * @supplierCardinality 1..*
50  	 */
51  	private List answers = null;
52  
53  	/**
54  	 * TODO documentation
55  	 * @return returns the <code>id</code>.
56  	 */
57  	public long getId() {
58  		return id;
59  	}
60  
61  	/**
62  	 * TODO documentation
63  	 * @param id the <code>id</code> to set.
64  	 */
65  	public void setId(long id) {
66  		this.id = id;
67  	}
68  
69  	/**
70  	 * TODO documentation
71  	 * @return returns the <code>answers</code>.
72  	 */
73  	public List getAnswers() {
74  		return answers;
75  	}
76  
77  	/**
78  	 * TODO documentation
79  	 * @param answers the <code>answers</code> to set.
80  	 */
81  	public void setAnswers(List answers) {
82  		this.answers = answers;
83  	}
84  
85  	/**
86  	 * TODO documentation
87  	 * @param answer
88  	 */
89  	public void addAnswer(Answer answer) {
90  		answers.add(answer);
91  	}
92  
93  	/**
94  	 * TODO documentation
95  	 * @return returns the <code>description</code>.
96  	 */
97  	public String getDescription() {
98  		return description;
99  	}
100 
101 	/**
102 	 * TODO documentation
103 	 * @param description the <code>description</code> to set.
104 	 */
105 	public void setDescription(String description) {
106 		this.description = description;
107 	}
108 
109 	/**
110 	 * TODO documentation
111 	 * @return returns the <code>title</code>.
112 	 */
113 	public String getTitle() {
114 		return title;
115 	}
116 
117 	/**
118 	 * TODO documentation
119 	 * @param title the <code>title</code> to set.
120 	 */
121 	public void setTitle(String title) {
122 		this.title = title;
123 	}
124 
125 	/**
126 	 * TODO documentation
127 	 * @return returns the <code>type</code>.
128 	 */
129 	public Type getType() {
130 		return type;
131 	}
132 
133 	/**
134 	 * TODO documentation
135 	 * @param type the <code>type</code> to set.
136 	 */
137 	public void setType(Type type) {
138 		this.type = type;
139 	}
140 
141 	/**
142 	 * TODO documentation
143 	 * @author rlogiacco
144 	 */
145 	public static class Type extends Enumeration {
146 
147 		private static final long serialVersionUID = -2830589290044816317L;
148 
149 		/**
150 		 * TODO documentation
151 		 */
152 		public static final Type OPEN = new Type('O', "poll.type.open");
153 
154 		/**
155 		 * TODO documentation
156 		 */
157 		public static final Type SINGLE = new Type('S', "poll.type.single");
158 
159 		/**
160 		 * TODO documentation
161 		 */
162 		public static final Type MULTIPLE = new Type('M', "poll.type.multiple");
163 
164 		/**
165 		 * TODO documentation
166 		 */
167 		public static final Type[] LIST = new Type[] {SINGLE, MULTIPLE, OPEN};
168 
169 		/**
170 		 * TODO documentation
171 		 * @param id
172 		 * @param display
173 		 */
174 		private Type(int id, String display) {
175 			super(id, display);
176 		}
177 
178 		/**
179 		 * @see net.smartlab.web.Enumeration#decode(int)
180 		 */
181 		public Enumeration decode(int id) {
182 			switch (id) {
183 				case 'O':
184 					return OPEN;
185 				case 'S':
186 					return SINGLE;
187 				case 'M':
188 					return MULTIPLE;
189 				default:
190 					return null;
191 			}
192 		}
193 
194 		public Enumeration decode(String code) {
195 			return this.decode((int)code.toUpperCase().charAt(0));
196 		}
197 	}
198 }