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