001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.model.values;
032:
033: import java.util.*;
034:
035: import de.ug2t.model.*;
036: import de.ug2t.unifiedGui.*;
037: import de.ug2t.unifiedGui.transformer.*;
038: import de.ug2t.unifiedGui.validator.*;
039:
040: /**
041: * @author Dirk
042: *
043: * date: 13.07.2003 project: WiSer-Framework
044: *
045: * <p>
046: * This class represents one value-object in the model
047: * </p>
048: */
049: public class MoSingleValue extends MoValue implements IMoSingleValue {
050: private Object pem_value = null;
051: private Object pem_valueUnChecked = null;
052: private IUnTransformer pem_toUITrans = null;
053: private IUnTransformer pem_fromUITrans = null;
054: private IMoValueContainer pem_parent = null;
055:
056: /**
057: * @param xVal
058: * @param xTr
059: * @param xObs
060: * @param xUiMap
061: * @param xUiErr
062: */
063: public MoSingleValue(IUnValidator xVal, IUnTransformer xTr,
064: Vector xObs, UnComponent xUiMap,
065: IMoMappingErrorHandler xUiErr) {
066: super (xVal, xTr, xObs, xUiMap, xUiErr);
067: }
068:
069: public MoSingleValue(Object xValue, IUnValidator xVal,
070: IUnTransformer xTr, Vector xObs, UnComponent xUiMap,
071: IMoMappingErrorHandler xUiErr) {
072: super (xVal, xTr, xObs, xUiMap, xUiErr);
073: this .pcmf_setValueValidate(xValue);
074: }
075:
076: public MoSingleValue(Object xValue) {
077: this .pcmf_setValueValidate(xValue);
078: }
079:
080: /**
081: *
082: */
083: public MoSingleValue() {
084: super ();
085: }
086:
087: /**
088: * <p>
089: * This function returns the stored value
090: * </p>
091: * <p>
092: *
093: *
094: * @return a Object with the stored value
095: * </p>
096: */
097: public Object pcmf_getValue() {
098: return (this .pem_value);
099: } // end pcmf_getValue
100:
101: /**
102: * <p>
103: * This function sets the value of the value object. This value is not valid
104: * (and will not be return by the getValue method) until the validator is
105: * called
106: * </p>
107: * <p>
108: *
109: *
110: * @return a Object with the previous value stored in the value object
111: * </p>
112: * <p>
113: * @param xValue
114: * is the value which is stored by the value object
115: * </p>
116: */
117: public void pcmf_setValue(Object xValue) {
118: if (this .pdm_transformer != null)
119: xValue = this .pdm_transformer.pcmf_transform(xValue);
120:
121: this .pem_valueUnChecked = xValue;
122: } // end pcmf_setValue
123:
124: /**
125: * <p>
126: * This function sets the value of the value object. The validator is called
127: * immediately
128: * </p>
129: * <p>
130: *
131: *
132: * @return a Object with the previous value stored in the value object
133: * </p>
134: * <p>
135: * @param xValue
136: * is the value which is stored by the value object
137: * </p>
138: */
139: public Object pcmf_setValueValidate(Object xValue) {
140: Object l_oldV = this .pem_value;
141:
142: if (this .pdm_transformer != null)
143: xValue = this .pdm_transformer.pcmf_transform(xValue);
144:
145: this .pem_valueUnChecked = xValue;
146:
147: if (this .pdm_validator != null) {
148: if (this .pdm_validator
149: .pcmf_validate(this .pem_valueUnChecked) == null) {
150: this .pem_value = xValue;
151: this .pemf_callObservers();
152:
153: return (l_oldV);
154: }
155: } else {
156: this .pem_value = xValue;
157: return (l_oldV);
158: }
159:
160: return xValue;
161: } // end pcmf_setValue
162:
163: /**
164: * <p>
165: * Gets the validator of this value
166: * </p>
167: * <p>
168: *
169: *
170: * @return a IUnValidator
171: * </p>
172: */
173: public IUnValidator pcmf_getValidator() {
174: return (this .pdm_validator);
175: } // end pcmf_getValidator
176:
177: /**
178: * <p>
179: * Does ...
180: * </p>
181: * <p>
182: *
183: *
184: * @return a boolean with ...
185: * </p>
186: */
187: public boolean pcmf_model2UI() {
188: if (this .pdm_uiMap == null)
189: return (false);
190:
191: if (this .pem_toUITrans == null)
192: this .pdm_uiMap.pcmf_setValue(this .pem_value);
193: else
194: this .pdm_uiMap.pcmf_setValue(this .pem_toUITrans
195: .pcmf_transform(this ));
196:
197: return (true);
198: } // end pcmf_model2UI
199:
200: /**
201: * <p>
202: * Does ...
203: * </p>
204: * <p>
205: *
206: *
207: * @return a boolean with ...
208: * </p>
209: */
210: public boolean pcmf_UI2Model() {
211: if (this .pdm_uiMap == null)
212: return (false);
213:
214: Object l_value = this .pdm_uiMap.pcmf_getValue();
215:
216: if (this .pem_fromUITrans == null)
217: this .pcmf_setValue(l_value);
218: else
219: this .pcmf_setValue(this .pem_fromUITrans
220: .pcmf_transform(l_value));
221:
222: return (true);
223: } // end pcmf_UI2Model
224:
225: /**
226: * <p>
227: * Does ...
228: * </p>
229: * <p>
230: *
231: * @return a IMoValue with ...
232: * </p>
233: */
234: public IMoValue pcmf_cloneModelValue(boolean xChilds, boolean xFull) {
235: MoSingleValue l_new = new MoSingleValue(this .pdm_validator,
236: this .pdm_transformer, this .pdm_observers,
237: this .pdm_uiMap, this .pdm_uiErr);
238:
239: l_new.pdm_writer = this .pdm_writer;
240: l_new.pdm_reader = this .pdm_reader;
241:
242: l_new.pdm_myTemplateObj = this .pdm_myTemplateObj;
243: l_new.pdm_myTemplate = this .pdm_myTemplate;
244: l_new.pdm_uiErr = this .pdm_uiErr;
245:
246: l_new.pcmf_setValue(this .pem_value);
247: l_new.pcmf_validate();
248:
249: l_new.pcmf_setFromUITransformer(this .pem_fromUITrans);
250: l_new.pcmf_setToUITransformer(this .pem_toUITrans);
251:
252: return (l_new);
253: } // end pcmf_cloneModelValue
254:
255: public IMoValue pcmf_cloneModelValue(boolean xChilds) {
256: return (pcmf_cloneModelValue(true, true));
257: }
258:
259: /**
260: * <p>
261: * Does...
262: * </p>
263: * <p>
264: *
265: * @return a Type with
266: * </p>
267: * <p>
268: * @param
269: * </p>
270: */
271: public boolean pcmf_validate() {
272: String l_error = null;
273:
274: if (this .pdm_validator != null) {
275: if ((l_error = this .pdm_validator
276: .pcmf_validate(this .pem_valueUnChecked)) == null) {
277: this .pem_value = this .pem_valueUnChecked;
278: this .pemf_callObservers();
279:
280: return (true);
281: }
282: } else {
283: this .pem_value = this .pem_valueUnChecked;
284: this .pemf_callObservers();
285:
286: return (true);
287: }
288: if (this .pdm_uiErr != null && this .pdm_uiMap != null)
289: this .pdm_uiErr.pcmf_setUiElemet2Error(this .pdm_uiMap,
290: l_error);
291:
292: return (false);
293: }
294:
295: public String toString() {
296: return (this .pem_value.toString());
297: }
298:
299: public IUnTransformer pcmf_setToUITransformer(IUnTransformer xTrans) {
300: IUnTransformer l_trans = this .pem_toUITrans;
301: this .pem_toUITrans = xTrans;
302:
303: return (l_trans);
304: }
305:
306: public IUnTransformer pcmf_setFromUITransformer(
307: IUnTransformer xTrans) {
308: IUnTransformer l_trans = this .pem_fromUITrans;
309: this .pem_fromUITrans = xTrans;
310:
311: return (l_trans);
312: }
313:
314: public void pcmf_setParent(IMoValueContainer xParent) {
315: this .pem_parent = xParent;
316: }
317:
318: public IMoValueContainer pcmf_getParent() {
319: return (this .pem_parent);
320: }
321: } // end MoSingleValue
|