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 MoLwValueTree extends MoLimitedValueTree {
042: private TreeMap pem_others = null;
043:
044: /**
045: * @throws Exception
046: */
047: public MoLwValueTree() 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 MoLwValueTree(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 MoLwValueTree(String xName, KeTreeNode xParent)
074: throws Exception {
075: super (xName, xParent);
076: }
077:
078: public IMoValue pcmf_addValue(String xName, IMoValue xValue) {
079: IMoValue l_old = this .pcmf_getModelValue(xName);
080:
081: try {
082: if (xValue instanceof IMoSingleValue)
083: ((IMoSingleValue) xValue).pcmf_setParent(this );
084:
085: if (xValue instanceof KeTreeNode)
086: this .pcmf_addNode(xName, (KeTreeNode) xValue);
087: else {
088: if (this .pem_others == null)
089: this .pem_others = new TreeMap();
090:
091: this .pem_others.put(xName, xValue);
092: }
093: } catch (Exception e) {
094: KeLog.pcmf_logException("ug2t", this , e);
095: }
096: ;
097: this .pdmf_callObservers();
098:
099: return (l_old);
100: }
101:
102: public IMoValue pcmf_getModelValue(String xName) {
103: IMoValue l_ret = null;
104: l_ret = (IMoValue) this .pcmf_getSubNode(xName);
105: if (l_ret == null) {
106: if (this .pem_others != null)
107: l_ret = (IMoValue) this .pem_others.get(xName);
108: }
109: return (l_ret);
110: }
111:
112: public IMoValue pcmf_removeValue(String xName) {
113: IMoValue l_ret = null;
114: l_ret = (IMoValue) this .pcmf_removeNode(xName);
115: if (l_ret == null) {
116: if (this .pem_others != null)
117: l_ret = (IMoValue) this .pem_others.remove(xName);
118: }
119:
120: if (l_ret instanceof IMoSingleValue)
121: ((IMoSingleValue) l_ret).pcmf_setParent(null);
122:
123: this .pdmf_callObservers();
124:
125: return (l_ret);
126: }
127:
128: public IMoValue pcmf_cloneModelValue(boolean xChilds, boolean xFull) {
129: IMoValueContainer l_new = null;
130: String l_name = null;
131:
132: try {
133: l_new = new MoLwValueTree(this .pcmf_getName(), null, null,
134: null, null, this .pdm_uiMap, null);
135: l_new.pcmf_setMyTemplate(this .pcmf_getMyTemplate());
136: l_new.pcmf_setMyTemplateObj(this .pcmf_getMyTemplateObj());
137: ((MoLwValueTree) l_new).pcmf_setView(IKeViewable.ViewTools
138: .pcmf_cloneViewToLocal(this , this .pcmf_getView()));
139:
140: if (xChilds == true && xFull == false) {
141: Iterator l_itk = this .pcmf_getSubNameIterator();
142: Iterator l_itv = this .pcmf_getSubIterator();
143: IMoValue l_val = null;
144: Object l_sub = null;
145:
146: while (l_itk.hasNext()) {
147: l_name = (String) l_itk.next();
148: MoChildDescriptor l_desc = this
149: .pcmf_getDesc(l_name);
150: if (l_desc != null) {
151: if (l_desc.pcmf_isManatory()) {
152: l_sub = l_itv.next();
153: if (l_sub instanceof MoLwValueTree)
154: l_val = (IMoValue) l_sub;
155: else
156: l_val = (IMoValue) ((KeTreeNode) l_sub)
157: .pcmf_getValue();
158:
159: l_new.pcmf_addValue(l_name, l_val
160: .pcmf_cloneModelValue(xChilds,
161: xFull));
162: }
163: }
164: }
165:
166: if (this .pem_others != null) {
167: l_itk = this .pem_others.keySet().iterator();
168: l_itv = this .pem_others.values().iterator();
169: l_val = null;
170:
171: while (l_itk.hasNext()) {
172: l_name = (String) l_itk.next();
173: l_val = (IMoValue) l_itv.next();
174: MoChildDescriptor l_desc = this
175: .pcmf_getDesc(l_name);
176: if (l_desc != null) {
177: if (l_desc.pcmf_isManatory()) {
178: l_new.pcmf_addValue(l_name, l_val
179: .pcmf_cloneModelValue(xChilds,
180: xFull));
181: }
182: }
183: }
184: }
185: } else if (xChilds == true && xFull == true) {
186: Iterator l_itk = this .pcmf_getSubNameIterator();
187: Iterator l_itv = this .pcmf_getSubIterator();
188: IMoValue l_val = null;
189: Object l_sub = null;
190:
191: while (l_itk.hasNext()) {
192: l_name = (String) l_itk.next();
193: l_sub = l_itv.next();
194:
195: if (l_sub instanceof MoLwValueTree)
196: l_val = (IMoValue) l_sub;
197: else
198: l_val = (IMoValue) ((KeTreeNode) l_sub)
199: .pcmf_getValue();
200:
201: l_new.pcmf_addValue(l_name, l_val
202: .pcmf_cloneModelValue(xChilds, xFull));
203: }
204:
205: if (this .pem_others != null) {
206: l_itv = this .pem_others.values().iterator();
207: l_itk = this .pem_others.keySet().iterator();
208: l_val = null;
209:
210: while (l_itk.hasNext()) {
211: l_name = (String) l_itk.next();
212: l_val = (IMoValue) l_itv.next();
213: l_new.pcmf_addValue(l_name, l_val
214: .pcmf_cloneModelValue(xChilds, xFull));
215: }
216: }
217: }
218: } catch (Exception e) {
219: KeLog.pcmf_logException("ug2t", this , e);
220: }
221: ;
222:
223: return (l_new);
224: }
225:
226: public Iterator pcmf_getSubValueNameIt() {
227: ArrayList l_vect = null;
228: if (this .pdm_allSubs == null)
229: l_vect = new ArrayList();
230: else
231: l_vect = this .pcmf_getAllSubNames();
232:
233: if (this .pem_others != null)
234: l_vect.addAll(this .pem_others.keySet());
235:
236: return (l_vect.iterator());
237: }
238:
239: public Iterator pcmf_getSubValueIt() {
240: ArrayList l_vect = null;
241: if (this .pdm_allSubs == null)
242: l_vect = new ArrayList();
243: else
244: l_vect = new ArrayList(this.pdm_allSubs);
245:
246: if (this.pem_others != null)
247: l_vect.addAll(this.pem_others.values());
248:
249: return (l_vect.iterator());
250: }
251: }
|