1 /*
2 * File: AbstractAttribute.java
3 * Created: 23.2.2006 10:43:19
4 *
5 * Copyright 2007 Michal Burda.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 package net.sf.webmancer.db;
23
24 import java.util.Collection;
25 import java.util.Vector;
26
27 /**
28 * @author Michal Burda
29 */
30 public abstract class AbstractAttribute implements IAttribute {
31 /**
32 *
33 */
34 private String description;
35
36 /**
37 *
38 */
39 private String initialValue;
40
41 /**
42 *
43 */
44 private String name;
45
46 /**
47 *
48 */
49 private boolean mandatory;
50
51 /**
52 *
53 */
54 private String id;
55
56 /**
57 *
58 */
59 private IDataSet parent;
60
61 /**
62 *
63 */
64 private boolean primary;
65
66 /**
67 *
68 */
69 private boolean derived;
70
71 /**
72 *
73 */
74 private boolean inDatabase;
75
76 /**
77 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#getDescription()
78 */
79 public String getDescription() {
80 return this.description;
81 }
82
83 /**
84 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#getInitialValue()
85 */
86 public String getInitialValue() {
87 return this.initialValue;
88 }
89
90 /**
91 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#getName()
92 */
93 public String getName() {
94 return this.name;
95 }
96
97 /**
98 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#isMandatory()
99 */
100 public boolean isMandatory() {
101 return this.mandatory;
102 }
103
104 /**
105 * @see net.sf.webmancer.db.ICommonAttributeInformation#getId()
106 */
107 public String getId() {
108 return this.id;
109 }
110
111 /**
112 * @see net.sf.webmancer.db.ICommonAttributeInformation#getParentDataSet()
113 */
114 public IDataSet getParentDataSet() {
115 return this.parent;
116 }
117
118 /**
119 * @see net.sf.webmancer.db.ICommonAttributeInformation#isPrimaryKey()
120 */
121 public boolean isPrimaryKey() {
122 return this.primary;
123 }
124
125 /**
126 * @see net.sf.webmancer.db.IBackEndAttributeInformation#isDerived()
127 */
128 public boolean isDerived() {
129 return this.derived;
130 }
131
132 /**
133 * @see net.sf.webmancer.db.IBackEndAttributeInformation#isInDatabase()
134 */
135 public boolean isInDatabase() {
136 return this.inDatabase;
137 }
138
139 /**
140 * Sets the derived.
141 *
142 * @param derived the derived to set
143 */
144 public void setDerived(final boolean derived) {
145 this.derived = derived;
146 }
147
148 /**
149 * Sets the description.
150 *
151 * @param description the description to set
152 */
153 public void setDescription(final String description) {
154 this.description = description;
155 }
156
157 /**
158 * Sets the id.
159 *
160 * @param id the id to set
161 */
162 public void setId(final String id) {
163 this.id = id;
164 }
165
166 /**
167 * Sets the inDatabase.
168 *
169 * @param inDatabase the inDatabase to set
170 */
171 public void setInDatabase(final boolean inDatabase) {
172 this.inDatabase = inDatabase;
173 }
174
175 /**
176 * Sets the initialValue.
177 *
178 * @param initialValue the initialValue to set
179 */
180 public void setInitialValue(final String initialValue) {
181 this.initialValue = initialValue;
182 }
183
184 /**
185 * Sets the mandatory.
186 *
187 * @param mandatory the mandatory to set
188 */
189 public void setMandatory(final boolean mandatory) {
190 this.mandatory = mandatory;
191 }
192
193 /**
194 * Sets the name.
195 *
196 * @param name the name to set
197 */
198 public void setName(final String name) {
199 this.name = name;
200 }
201
202 /**
203 * Sets the parent.
204 *
205 * @param parent the parent to set
206 */
207 public void setParentDataSet(final IDataSet parent) {
208 this.parent = parent;
209 }
210
211 /**
212 * Sets the primary.
213 *
214 * @param primary the primary to set
215 */
216 public void setPrimary(final boolean primary) {
217 this.primary = primary;
218 }
219
220 /**
221 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#preProcessConditionInput(java.lang.String)
222 */
223 public String preProcessConditionInput(String input) {
224 return input.trim();
225 }
226
227 /**
228 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#preProcessInput(java.lang.String)
229 */
230 public String preProcessInput(String input) {
231 return input.trim();
232 }
233
234 /**
235 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#validateInput(java.lang.String)
236 */
237 public Collection<String> validateInput(String input) {
238 Vector<String> errors = new Vector<String>();
239 if (input == null || input.length() <= 0) {
240 errors.add("is mandatory");
241 }
242 return errors;
243 }
244
245 /**
246 * Returns -1, which means unlimited length of user input.
247 *
248 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#getMaximumInputLength()
249 */
250 public int getMaximumInputLength() {
251 return -1;
252 }
253
254 /**
255 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#convertInternalToInput(java.lang.Object)
256 */
257 public abstract String convertInternalToInput(Object internal);
258
259 /**
260 * @see net.sf.webmancer.db.IFrontEndAttributeInformation#convertInternalToOutput(java.lang.Object)
261 */
262 public abstract String convertInternalToOutput(Object internal);
263
264 /**
265 * @see net.sf.webmancer.db.IBackEndAttributeInformation#convertDbToInternal(java.lang.Object)
266 */
267 public abstract Object convertDbToInternal(Object dbValue);
268
269 }