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.kernel.*;
036: import de.ug2t.model.*;
037: import de.ug2t.unifiedGui.*;
038: import de.ug2t.unifiedGui.transformer.*;
039: import de.ug2t.unifiedGui.validator.*;
040:
041: public class MoLwUnlimitedValueTree extends MoValueTree {
042: private TreeMap pem_others = null;
043:
044: /**
045: * @throws Exception
046: */
047: public MoLwUnlimitedValueTree() throws Exception {
048: super ();
049: }
050:
051: /**
052: * @param xName
053: * @param xParent
054: * @param xVal
055: * @param xTr
056: * @param xObs
057: * @param xUiMap
058: * @param xUiErr
059: * @throws Exception
060: */
061: public MoLwUnlimitedValueTree(String xName, KeTreeNode xParent,
062: IUnValidator xVal, IUnTransformer xTr, Vector xObs,
063: UnComponent xUiMap, IMoMappingErrorHandler xUiErr)
064: throws Exception {
065: super (xName, xParent, xVal, xTr, xObs, xUiMap, xUiErr);
066: }
067:
068: /**
069: * @param xName
070: * @param xParent
071: * @throws Exception
072: */
073: public MoLwUnlimitedValueTree(String xName, KeTreeNode xParent)
074: throws Exception {
075: super (xName, xParent);
076: }
077:
078: public IMoValue pcmf_addValue(String xName, IMoValue xValue) {
079: if (this .pdm_transformer != null)
080: if (xValue instanceof IMoSingleValue) {
081: Object l_obj = null;
082: l_obj = this .pdm_transformer
083: .pcmf_transform(((IMoSingleValue) xValue)
084: .pcmf_getValue());
085: ((IMoSingleValue) xValue).pcmf_setValue(l_obj);
086: ((IMoSingleValue) xValue).pcmf_setParent(this );
087: }
088:
089: IMoValue l_old = this .pcmf_getModelValue(xName);
090:
091: try {
092: if (xValue instanceof IMoSingleValue)
093: ((IMoSingleValue) xValue).pcmf_setParent(this );
094:
095: if (xValue instanceof KeTreeNode)
096: this .pcmf_addNode(xName, (KeTreeNode) xValue);
097: else {
098: if (this .pem_others == null)
099: this .pem_others = new TreeMap();
100:
101: this .pem_others.put(xName, xValue);
102: }
103: } catch (Exception e) {
104: KeLog.pcmf_logException("ug2t", this , e);
105: }
106: ;
107: this .pdmf_callObservers();
108:
109: return (l_old);
110: }
111:
112: public IMoValue pcmf_getModelValue(String xName) {
113: IMoValue l_ret = null;
114: l_ret = (IMoValue) this .pcmf_getSubNode(xName);
115: if (l_ret == null) {
116: if (this .pem_others != null)
117: l_ret = (IMoValue) this .pem_others.get(xName);
118: }
119:
120: return (l_ret);
121: }
122:
123: public IMoValue pcmf_removeValue(String xName) {
124: IMoValue l_ret = null;
125: l_ret = (IMoValue) this .pcmf_removeNode(xName);
126: if (l_ret == null) {
127: if (this .pem_others != null)
128: l_ret = (IMoValue) this .pem_others.remove(xName);
129: }
130:
131: if (l_ret instanceof IMoSingleValue)
132: ((IMoSingleValue) l_ret).pcmf_setParent(null);
133:
134: this .pdmf_callObservers();
135:
136: return (l_ret);
137: }
138:
139: public IMoValue pcmf_cloneModelValue(boolean xChilds, boolean xFull) {
140: IMoValueContainer l_new = null;
141: String l_name = null;
142:
143: try {
144: l_new = new MoLwValueTree(this .pcmf_getName(), null,
145: this .pdm_validator, this .pdm_transformer,
146: this .pdm_observers, this .pdm_uiMap, this .pdm_uiErr);
147: l_new.pcmf_setMyTemplate(this .pcmf_getMyTemplate());
148: l_new.pcmf_setMyTemplateObj(this .pcmf_getMyTemplateObj());
149: ((MoLwValueTree) l_new).pcmf_setView(IKeViewable.ViewTools
150: .pcmf_cloneViewToLocal(this , this .pcmf_getView()));
151:
152: if (xChilds == true && xFull == false) {
153: Iterator l_itk = this .pcmf_getSubNameIterator();
154: Iterator l_itv = this .pcmf_getSubIterator();
155: IMoValue l_val = null;
156: Object l_sub = null;
157:
158: while (l_itk.hasNext()) {
159: l_name = (String) l_itk.next();
160: MoChildDescriptor l_desc = this
161: .pcmf_getDesc(l_name);
162: if (l_desc != null) {
163: if (l_desc.pcmf_isManatory()) {
164: l_sub = l_itv.next();
165: if (l_sub instanceof MoLwValueTree)
166: l_val = (IMoValue) l_sub;
167: else
168: l_val = (IMoValue) ((KeTreeNode) l_sub)
169: .pcmf_getValue();
170:
171: l_new.pcmf_addValue(l_name, l_val
172: .pcmf_cloneModelValue(xChilds,
173: xFull));
174: }
175: }
176: }
177: if (this .pem_others != null) {
178: l_itk = this .pem_others.keySet().iterator();
179: l_itv = this .pem_others.values().iterator();
180: l_val = null;
181:
182: while (l_itk.hasNext()) {
183: l_name = (String) l_itk.next();
184: l_val = (IMoValue) l_itv.next();
185: MoChildDescriptor l_desc = this
186: .pcmf_getDesc(l_name);
187: if (l_desc != null) {
188: if (l_desc.pcmf_isManatory()) {
189: l_new.pcmf_addValue(l_name, l_val
190: .pcmf_cloneModelValue(xChilds,
191: xFull));
192: }
193: }
194: }
195: }
196: } else if (xChilds == true && xFull == true) {
197: Iterator l_itk = this .pcmf_getSubNameIterator();
198: Iterator l_itv = this .pcmf_getSubIterator();
199: IMoValue l_val = null;
200: Object l_sub = null;
201:
202: while (l_itk.hasNext()) {
203: l_name = (String) l_itk.next();
204: l_sub = l_itv.next();
205:
206: if (l_sub instanceof MoLwValueTree)
207: l_val = (IMoValue) l_sub;
208: else
209: l_val = (IMoValue) ((KeTreeNode) l_sub)
210: .pcmf_getValue();
211:
212: l_new.pcmf_addValue(l_name, l_val
213: .pcmf_cloneModelValue(xChilds, xFull));
214: }
215:
216: if (this .pem_others != null) {
217: l_itv = this .pem_others.values().iterator();
218: l_itk = this .pem_others.keySet().iterator();
219: l_val = null;
220:
221: while (l_itk.hasNext()) {
222: l_name = (String) l_itk.next();
223: l_val = (IMoValue) l_itv.next();
224: l_new.pcmf_addValue(l_name, l_val
225: .pcmf_cloneModelValue(xChilds, xFull));
226: }
227: }
228: }
229: } catch (Exception e) {
230: KeLog.pcmf_logException("ug2t", this , e);
231: }
232: ;
233:
234: l_new.pcmf_setReader(this .pdm_reader);
235: l_new.pcmf_setWriter(this .pdm_writer);
236:
237: return (l_new);
238: }
239:
240: public Iterator pcmf_getSubValueNameIt() {
241: ArrayList l_vect = null;
242: if (this .pdm_allSubs == null)
243: l_vect = new ArrayList();
244: else
245: l_vect = this .pcmf_getAllSubNames();
246:
247: if (this .pem_others != null)
248: l_vect.addAll(this .pem_others.keySet());
249:
250: return (l_vect.iterator());
251: }
252:
253: public Iterator pcmf_getSubValueIt() {
254: ArrayList l_vect = null;
255: if (this .pdm_allSubs == null)
256: l_vect = new ArrayList();
257: else
258: l_vect = new ArrayList(this.pdm_allSubs);
259:
260: if (this.pem_others != null)
261: l_vect.addAll(this.pem_others.values());
262:
263: return (l_vect.iterator());
264: }
265: }
|