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.channel.ho.*;
036: import de.ug2t.kernel.*;
037: import de.ug2t.model.*;
038: import de.ug2t.model.persistence.*;
039: import de.ug2t.unifiedGui.*;
040: import de.ug2t.unifiedGui.transformer.*;
041: import de.ug2t.unifiedGui.validator.*;
042:
043: /**
044: *
045: * @author dvonderweiden
046: *
047: * Created: 06:58:41, 2003 Comment: Kann auch mehrere Kindobjekte mit dem selben
048: * schlüssel speichern, ist vom HoGenericTreeNode abgeleitet ist daher
049: * kompatibel zhu allen Ui-elementen
050: */
051: public class MoRemotedValueTree extends HoGenericTreeNode implements
052: IMoValueContainer {
053: protected IUnValidator pdm_validator = null;
054: protected IUnTransformer pdm_transformer = null;
055: protected Vector pdm_observers = null;
056: protected UnComponent pdm_uiMap = null;
057: protected IMoMappingErrorHandler pdm_uiErr = null;
058: protected IMoReader pdm_reader = null;
059: protected IMoWriter pdm_writer = null;
060: protected String pdm_myTemplate = null;
061: protected IMoValue pdm_myTemplateObj = null;
062: private TreeMap pem_desc = null;
063:
064: public MoChildDescriptor pcmf_getDesc(String xName) {
065: if (pem_desc == null || xName == null)
066: return (null);
067:
068: return ((MoChildDescriptor) this .pem_desc.get(xName));
069: }
070:
071: public MoChildDescriptor pcmf_addDesc(String xName,
072: MoChildDescriptor xDesc) {
073: if (this .pem_desc == null)
074: this .pem_desc = new TreeMap();
075:
076: return ((MoChildDescriptor) this .pem_desc.put(xName, xDesc));
077: }
078:
079: /**
080: * @param xName
081: * @param xParent
082: * @throws Exception
083: */
084: public MoRemotedValueTree(String xName, HoGenericTreeNode xParent,
085: IUnValidator xVal, IUnTransformer xTr, Vector xObs,
086: UnComponent xUiMap, IMoMappingErrorHandler xUiErr)
087: throws Exception {
088: super (xName);
089: this .pcmf_setEarlyAutoDelete(true);
090:
091: this .pdm_validator = xVal;
092: this .pdm_transformer = xTr;
093: this .pdm_observers = xObs;
094: this .pdm_uiMap = xUiMap;
095: this .pdm_uiErr = xUiErr;
096:
097: if (xParent == null) {
098: this .pdm_myTemplate = null;
099: this .pdm_myTemplateObj = this ;
100: } else {
101: this .pdm_myTemplate = xParent.pcmf_getName();
102: this .pdm_myTemplateObj = (IMoValueContainer) xParent;
103: }
104:
105: return;
106: }
107:
108: /**
109: * @param xName
110: * @param xParent
111: * @throws Exception
112: */
113: public MoRemotedValueTree(String xName, HoGenericTreeNode xParent)
114: throws Exception {
115: super (xName);
116: this .pcmf_setEarlyAutoDelete(true);
117:
118: if (xParent == null) {
119: this .pdm_myTemplate = null;
120: this .pdm_myTemplateObj = this ;
121: } else {
122: this .pdm_myTemplate = xParent.pcmf_getName();
123: this .pdm_myTemplateObj = (IMoValueContainer) xParent;
124: }
125:
126: return;
127: }
128:
129: /**
130: *
131: * @param xName
132: * @param xParent
133: * @throws Exception
134: */
135: public MoRemotedValueTree() throws Exception {
136: super ("");
137: this .pcmf_setEarlyAutoDelete(true);
138:
139: this .pdm_myTemplate = null;
140: this .pdm_myTemplateObj = this ;
141:
142: return;
143: }
144:
145: /**
146: * <p>
147: * ...
148: * </p>
149: * <p>
150: *
151: * </p>
152: */
153: private void pemf_callObservers() {
154: if (this .pdm_observers != null) {
155: Iterator l_it = this .pdm_observers.iterator();
156: while (l_it.hasNext())
157: ((IMoObserver) l_it.next()).pcmf_modelChanged(this );
158: }
159: }
160:
161: /**
162: * <p>
163: * Does...
164: * </p>
165: * <p>
166: *
167: * @return a Type with
168: * </p>
169: * <p>
170: * @param
171: * </p>
172: */
173: public IUnValidator pcmf_setValidator(IUnValidator xValidator) {
174: IUnValidator l_val = this .pdm_validator;
175: this .pdm_validator = xValidator;
176:
177: return (l_val);
178: }
179:
180: /**
181: * <p>
182: * Does...
183: * </p>
184: * <p>
185: *
186: * @return a Type with
187: * </p>
188: * <p>
189: * @param
190: * </p>
191: */
192: public UnComponent pcmf_setUiMap(UnComponent xMap) {
193: UnComponent l_ui = this .pdm_uiMap;
194: this .pdm_uiMap = xMap;
195:
196: return (l_ui);
197: }
198:
199: /**
200: * <p>
201: * Does...
202: * </p>
203: * <p>
204: *
205: * @return a Type with
206: * </p>
207: * <p>
208: * @param
209: * </p>
210: */
211: public IMoObserver pcmf_addObserver(IMoObserver xObserv) {
212: if (this .pdm_observers == null)
213: this .pdm_observers = new Vector();
214:
215: this .pdm_observers.add(xObserv);
216:
217: return (xObserv);
218: }
219:
220: /**
221: * <p>
222: * Does...
223: * </p>
224: * <p>
225: *
226: * @return a Type with
227: * </p>
228: * <p>
229: * @param
230: * </p>
231: */
232: public IMoObserver pcmf_removeObserver(IMoObserver xObs) {
233: if (this .pdm_observers == null)
234: return (null);
235:
236: return (this .pdm_observers.remove(xObs) ? xObs : null);
237: }
238:
239: /**
240: * <p>
241: * Does...
242: * </p>
243: * <p>
244: *
245: * @return a Type with
246: * </p>
247: * <p>
248: * @param
249: * </p>
250: */
251: public IMoMappingErrorHandler pcmf_setUiErrorGW(
252: IMoMappingErrorHandler xGw) {
253: IMoMappingErrorHandler l_err = this .pdm_uiErr;
254: this .pdm_uiErr = xGw;
255:
256: return (l_err);
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 IMoValue pcmf_addValue(String xName, IMoValue xValue) {
272: KeTreeNode l_node = null;
273:
274: if (this .pdm_transformer != null)
275: if (xValue instanceof IMoSingleValue) {
276: Object l_obj = null;
277: l_obj = this .pdm_transformer
278: .pcmf_transform(((IMoSingleValue) xValue)
279: .pcmf_getValue());
280: ((IMoSingleValue) xValue).pcmf_setValue(l_obj);
281: ((IMoSingleValue) xValue).pcmf_setParent(this );
282: }
283:
284: try {
285: if (xValue instanceof MoRemotedValueTree)
286: l_node = (MoRemotedValueTree) xValue;
287: else {
288: if (xValue instanceof IMoSingleValue)
289: ((IMoSingleValue) xValue).pcmf_setParent(this );
290:
291: l_node = new HoGenericTreeNode(xName);
292: l_node.pcmf_setEarlyAutoDelete(true);
293: l_node.pcmf_setValue(xValue);
294: }
295: } catch (Exception e) {
296: KeLog.pcmf_logException("ug2t", this , e);
297: }
298: ;
299: l_node = this .pcmf_addNode(xName, l_node);
300: this .pemf_callObservers();
301:
302: if (l_node == null)
303: return (null);
304: else
305: return (l_node instanceof IMoValue ? (IMoValue) l_node
306: : (IMoValue) l_node.pcmf_getValue());
307: }
308:
309: /**
310: * <p>
311: * Does...
312: * </p>
313: * <p>
314: *
315: * @return a Type with
316: * </p>
317: * <p>
318: * @param
319: * </p>
320: */
321: public IMoValue pcmf_getModelValue(String xName) {
322: HoGenericTreeNode l_node = null;
323: l_node = (HoGenericTreeNode) this .pcmf_getSubNode(xName);
324: if (l_node == null)
325: return (null);
326: if (l_node instanceof MoRemotedValueTree)
327: return ((IMoValue) l_node);
328: else
329: return ((IMoValue) l_node.pcmf_getValue());
330: }
331:
332: /**
333: * <p>
334: * Does...
335: * </p>
336: * <p>
337: *
338: * @return a Type with
339: * </p>
340: * <p>
341: * @param
342: * </p>
343: */
344: public IMoValue pcmf_removeValue(String xName) {
345: HoGenericTreeNode l_node = null;
346: l_node = (HoGenericTreeNode) this .pcmf_removeNode(xName);
347: IMoValue l_ret = null;
348:
349: if (l_node instanceof IMoValue)
350: l_ret = (IMoValue) l_node;
351: else
352: l_ret = (IMoValue) l_node.pcmf_getValue();
353:
354: if (l_ret instanceof IMoSingleValue)
355: ((IMoSingleValue) l_ret).pcmf_setParent(null);
356:
357: this .pemf_callObservers();
358:
359: return (l_ret);
360: }
361:
362: /**
363: * <p>
364: * Does...
365: * </p>
366: * <p>
367: *
368: * @return a Type with
369: * </p>
370: * <p>
371: * @param
372: * </p>
373: */
374: public IMoValue pcmf_cloneModelValue(boolean xChilds, boolean xFull) {
375: IMoValueContainer l_new = null;
376: String l_name = null;
377:
378: try {
379: l_new = new MoRemotedValueTree(this .pcmf_getName(), null,
380: this .pdm_validator, this .pdm_transformer,
381: this .pdm_observers, this .pdm_uiMap, this .pdm_uiErr);
382: l_new.pcmf_setMyTemplate(this .pcmf_getMyTemplate());
383: l_new.pcmf_setMyTemplateObj(this .pcmf_getMyTemplateObj());
384: ((MoRemotedValueTree) l_new)
385: .pcmf_setView(IKeViewable.ViewTools
386: .pcmf_cloneViewToLocal(this , this
387: .pcmf_getView()));
388:
389: if (xChilds == true && xFull == false) {
390: Iterator l_itk = this .pcmf_getSubNameIterator();
391: Iterator l_itv = this .pcmf_getSubIterator();
392: IMoValue l_val = null;
393: Object l_sub = null;
394:
395: while (l_itk.hasNext()) {
396: l_name = (String) l_itk.next();
397: l_sub = l_itv.next();
398: MoChildDescriptor l_desc = this
399: .pcmf_getDesc(l_name);
400: if (l_desc != null) {
401: if (l_desc.pcmf_isManatory()) {
402: if (l_sub instanceof MoRemotedValueTree)
403: l_val = (IMoValue) l_sub;
404: else
405: l_val = (IMoValue) ((KeTreeNode) l_sub)
406: .pcmf_getValue();
407:
408: l_new.pcmf_addValue(l_name, l_val
409: .pcmf_cloneModelValue(xChilds,
410: xFull));
411: }
412: }
413: }
414: } else if (xChilds == true && xFull == true) {
415: Iterator l_itk = this .pcmf_getSubNameIterator();
416: Iterator l_itv = this .pcmf_getSubIterator();
417: IMoValue l_val = null;
418: Object l_sub = null;
419:
420: while (l_itk.hasNext()) {
421: l_name = (String) l_itk.next();
422: l_sub = l_itv.next();
423:
424: if (l_sub instanceof MoRemotedValueTree)
425: l_val = (IMoValue) l_sub;
426: else
427: l_val = (IMoValue) ((KeTreeNode) l_sub)
428: .pcmf_getValue();
429:
430: l_new.pcmf_addValue(l_name, l_val
431: .pcmf_cloneModelValue(xChilds, xFull));
432: }
433: }
434: } catch (Exception e) {
435: KeLog.pcmf_logException("ug2t", this , e);
436: }
437: ;
438:
439: l_new.pcmf_setReader(this .pdm_reader);
440: l_new.pcmf_setWriter(this .pdm_writer);
441:
442: return (l_new);
443: }
444:
445: public IMoValue pcmf_cloneModelValue(boolean xChilds) {
446: return (pcmf_cloneModelValue(xChilds, true));
447: }
448:
449: /**
450: * <p>
451: * Does ...
452: * </p>
453: * <p>
454: *
455: *
456: * @return a boolean with ...
457: * </p>
458: */
459: public boolean pcmf_model2UI() {
460: boolean l_ret = true;
461: Iterator l_it = this .pcmf_getSubValueIt();
462: MoChildDescriptor l_desc = null;
463: String l_name = null;
464: boolean l_doMap = true;
465: IMoValueContainer l_tpl = (IMoValueContainer) this
466: .pcmf_getMyTemplateObj();
467:
468: if (l_tpl == null)
469: l_tpl = this ;
470:
471: while (l_it.hasNext()) {
472: IMoValue l_val = (IMoValue) l_it.next();
473: l_name = l_val.pcmf_getMyTemplate();
474: l_desc = l_tpl.pcmf_getDesc(l_name);
475: if (l_desc != null)
476: l_doMap = l_desc.isPem_mapWithParent2Ui();
477:
478: if (l_doMap)
479: l_ret = l_val.pcmf_model2UI();
480: else
481: l_doMap = true;
482: }
483: return (l_ret);
484: } // end pcmf_model2UI
485:
486: /**
487: * <p>
488: * Does ...
489: * </p>
490: * <p>
491: *
492: *
493: * @return a boolean with ...
494: * </p>
495: */
496: public boolean pcmf_UI2Model() {
497: boolean l_ret = true;
498: Iterator l_it = this .pcmf_getSubValueIt();
499: MoChildDescriptor l_desc = null;
500: String l_name = null;
501: boolean l_doMap = true;
502: IMoValueContainer l_tpl = (IMoValueContainer) this
503: .pcmf_getMyTemplateObj();
504:
505: if (l_tpl == null)
506: l_tpl = this ;
507:
508: while (l_it.hasNext()) {
509: IMoValue l_val = (IMoValue) l_it.next();
510: l_name = l_val.pcmf_getMyTemplate();
511: l_desc = l_tpl.pcmf_getDesc(l_name);
512: if (l_desc != null)
513: l_doMap = l_desc.isPem_mapWithParent2Ui();
514:
515: if (l_doMap)
516: l_ret = l_val.pcmf_UI2Model() ? l_ret : false;
517: else
518: l_doMap = true;
519: }
520: return (l_ret);
521: } // end pcmf_UI2Model
522:
523: /**
524: * <p>
525: * Does...
526: * </p>
527: * <p>
528: *
529: * @return a Type with
530: * </p>
531: * <p>
532: * @param
533: * </p>
534: */
535:
536: public boolean pcmf_validate() {
537: boolean l_ret = true;
538: Iterator l_it = this .pcmf_getSubValueIt();
539: Vector l_error = new Vector();
540:
541: while (l_it.hasNext()) {
542: IMoValue l_val = (IMoValue) l_it.next();
543: if (l_val.pcmf_validate() == false) {
544: l_ret = false;
545: l_error.add(l_val.pcmf_getUiMap());
546: }
547: }
548: ;
549: if (l_ret == true && this .pdm_validator != null) {
550: l_ret = this .pdm_validator.pcmf_validate(this ) == null ? true
551: : false;
552: if (l_ret == false && this .pdm_uiMap != null)
553: l_error.add(this .pdm_uiMap);
554: }
555: ;
556: if (l_ret == false && this .pdm_uiErr != null)
557: this .pdm_uiErr.pcmf_setUiElemets2Error(l_error);
558:
559: if (l_ret == true)
560: this .pemf_callObservers();
561:
562: return (l_ret);
563: }
564:
565: /**
566: * <p>
567: * Does...
568: * </p>
569: * <p>
570: *
571: * @return a Type with
572: * </p>
573: * <p>
574: * @param
575: * </p>
576: */
577: public boolean pcmf_read(IMoValue xTpl) {
578: return (this .pdm_reader.pcmf_tplRead(xTpl, this ));
579: }
580:
581: /**
582: * <p>
583: * Does...
584: * </p>
585: * <p>
586: *
587: * @return a Type with
588: * </p>
589: * <p>
590: * @param
591: * </p>
592: */
593: public boolean pcmf_write() {
594: return (this .pdm_writer.pcmf_writeModel(this ));
595: }
596:
597: /**
598: * <p>
599: * Does...
600: * </p>
601: * <p>
602: *
603: * @return a Type with
604: * </p>
605: * <p>
606: * @param
607: * </p>
608: */
609: public IMoReader pcmf_setReader(IMoReader xReader) {
610: IMoReader l_pr = this .pdm_reader;
611: this .pdm_reader = xReader;
612:
613: return (l_pr);
614: }
615:
616: /**
617: * <p>
618: * Does...
619: * </p>
620: * <p>
621: *
622: * @return a Type with
623: * </p>
624: * <p>
625: * @param
626: * </p>
627: */
628: public IMoWriter pcmf_setWriter(IMoWriter xWriter) {
629: IMoWriter l_pw = this .pdm_writer;
630: this .pdm_writer = xWriter;
631:
632: return (l_pw);
633: }
634:
635: /**
636: * <p>
637: * Does...
638: * </p>
639: * <p>
640: *
641: * @return a Type with
642: * </p>
643: * <p>
644: * @param
645: * </p>
646: */
647: public Iterator pcmf_getSubValueNameIt() {
648: return (this .pcmf_getSubNameIterator());
649: }
650:
651: /**
652: * <p>
653: * Does ...
654: * </p>
655: * <p>
656: *
657: * @param ...
658: * </p>
659: * <p>
660: * @return ...
661: * </p>
662: */
663: public Iterator pcmf_getSubValueIt() {
664: if (this .pdm_allSubs == null)
665: return (new ArrayList().iterator());
666:
667: Iterator l_it = this .pdm_allSubs.iterator();
668: ArrayList l_vect = new ArrayList(this .pdm_allSubs.size());
669: Object l_value = null;
670:
671: while (l_it.hasNext()) {
672: l_value = l_it.next();
673: if (l_value instanceof MoRemotedValueTree)
674: l_vect.add(l_value);
675: else
676: l_vect.add(((KeTreeNode) l_value).pcmf_getValue());
677: }
678:
679: return (l_vect.iterator());
680: }
681:
682: /**
683: * <p>
684: * Does ...
685: * </p>
686: * <p>
687: *
688: *
689: *
690: * @return a IUnTransformer with ...
691: * </p>
692: * <p>
693: * @param xTr
694: * ...
695: * </p>
696: */
697: public IUnTransformer pcmf_getTransformer() {
698: return (this .pdm_transformer);
699: }
700:
701: /**
702: * <p>
703: * Does ...
704: * </p>
705: * <p>
706: *
707: *
708: *
709: * @return a IUnTransformer with ...
710: * </p>
711: * <p>
712: * @param xTr
713: * ...
714: * </p>
715: */
716: public IUnTransformer pcmf_setTransformer(IUnTransformer xTrans) {
717: IUnTransformer l_trans = this .pdm_transformer;
718: this .pdm_transformer = xTrans;
719: return (l_trans);
720: }
721:
722: /**
723: * <p>
724: * Does ...
725: * </p>
726: * <p>
727: *
728: *
729: *
730: * @return a Type with ...
731: * </p>
732: * <p>
733: * @param ...
734: * </p>
735: */
736: public IMoMappingErrorHandler pcmf_getUiErrorGW() {
737: return (this .pdm_uiErr);
738: }
739:
740: /**
741: * <p>
742: * Does ...
743: * </p>
744: * <p>
745: *
746: *
747: *
748: * @return a UnComponent with ...
749: * </p>
750: * <p>
751: * @param xMap
752: * ...
753: * </p>
754: */
755: public UnComponent pcmf_getUiMap() {
756: return (this .pdm_uiMap);
757: }
758:
759: /**
760: * <p>
761: * Does...
762: * </p>
763: * <p>
764: *
765: * @return a Type with
766: * </p>
767: * <p>
768: * @param
769: * </p>
770: */
771: public IMoReader pcmf_getReader() {
772: return (this .pdm_reader);
773: }
774:
775: /**
776: * <p>
777: * Does ...
778: * </p>
779: * <p>
780: *
781: *
782: *
783: * @return a UnComponent with ...
784: * </p>
785: * <p>
786: * @param xMap
787: * ...
788: * </p>
789: */
790: public Vector pcmf_getObservers() {
791: return (this .pdm_observers);
792: }
793:
794: /**
795: * <p>
796: * Does...
797: * </p>
798: * <p>
799: *
800: * @return a Type with
801: * </p>
802: * <p>
803: * @param
804: * </p>
805: */
806: public IMoWriter pcmf_getWriter() {
807: return (this .pdm_writer);
808: }
809:
810: /**
811: * <p>
812: * Does...
813: * </p>
814: * <p>
815: *
816: * @return a Type with
817: * </p>
818: * <p>
819: * @param
820: * </p>
821: */
822: public String pcmf_getMyTemplate() {
823: return (this .pdm_myTemplate);
824: }
825:
826: /**
827: * <p>
828: * Does...
829: * </p>
830: * <p>
831: *
832: * @return a Type with
833: * </p>
834: * <p>
835: * @param
836: * </p>
837: */
838: public String pcmf_setMyTemplate(String xTpl) {
839: String l_old = this .pdm_myTemplate;
840: this .pdm_myTemplate = xTpl;
841:
842: return (l_old);
843: };
844:
845: /**
846: * <p>
847: * Does ...
848: * </p>
849: * <p>
850: *
851: * @param ...
852: * </p>
853: * <p>
854: * @return ...
855: * </p>
856: */
857: public IMoValue pcmf_getNewModelValue(String xName, boolean xChilds) {
858: IMoValue l_mod = null;
859:
860: try {
861: IMoValue l_val = this .pcmf_getModelValue(xName);
862: if (l_val == null) {
863: KeLog.pcmf_log("ug2t",
864: "this model-value-type is not allowed: "
865: + xName, this , KeLog.ERROR);
866: return (null);
867: }
868: l_mod = l_val.pcmf_cloneModelValue(xChilds, false);
869: l_mod.pcmf_setMyTemplate(xName);
870: l_mod.pcmf_setMyTemplateObj(l_val);
871: } catch (Exception e) {
872: KeLog.pcmf_logException("ug2t", this , e);
873: }
874: ;
875:
876: return (l_mod);
877: }
878:
879: public IMoValue pcmf_getMyTemplateObj() {
880: return (this .pdm_myTemplateObj);
881: }
882:
883: public IMoValue pcmf_setMyTemplateObj(IMoValue xTpl) {
884: IMoValue l_old = this .pdm_myTemplateObj;
885: this .pdm_myTemplateObj = xTpl;
886:
887: return (l_old);
888: }
889:
890: public IMoValueContainer pcmf_getValueContainer(String xName) {
891: return ((IMoValueContainer) this .pcmf_getModelValue(xName));
892: }
893:
894: public IMoSingleValue pcmf_getSingleValue(String xName) {
895: return ((IMoSingleValue) this .pcmf_getModelValue(xName));
896: }
897:
898: public IMoValueContainer pcmf_getParent() {
899: return ((IMoValueContainer) this.pcmf_getParentNode());
900: }
901: }
|