01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.meta;
10:
11: import com.completex.objective.util.PropertyMap;
12: import com.completex.objective.components.persistency.Mappable;
13:
14: import java.util.Iterator;
15: import java.util.LinkedHashMap;
16: import java.util.Map;
17:
18: /**
19: * @author Gennady Krizhevsky
20: */
21: public class MetaComplex implements Mappable {
22:
23: public static final String TAG_COMPLEX_CHILDREN = "children";
24:
25: private Map children = new LinkedHashMap(); // Map<MetaComplexChild>
26:
27: public MetaComplex() {
28: }
29:
30: public MetaComplex(Map map) {
31: fromMap(map);
32: }
33:
34: public Map getChildren() {
35: return children;
36: }
37:
38: public Map toMap() {
39: Map map = new LinkedHashMap();
40: Map childrenMap = new LinkedHashMap();
41: map.put(MetaComplex.TAG_COMPLEX_CHILDREN, childrenMap);
42: for (Iterator it = children.keySet().iterator(); it.hasNext();) {
43: String key = (String) it.next();
44: MetaComplexChild child = (MetaComplexChild) children
45: .get(key);
46: childrenMap.put(key, child.toMap());
47: child.setName(key);
48: }
49: return map;
50: }
51:
52: public void fromMap(Map map) {
53: PropertyMap propertyMap = PropertyMap.toPropertyMap(map);
54: PropertyMap childrenMap = propertyMap
55: .getPropertyMap(MetaComplex.TAG_COMPLEX_CHILDREN);
56: if (childrenMap != null) {
57: for (Iterator it = childrenMap.keySet().iterator(); it
58: .hasNext();) {
59: String key = (String) it.next();
60: PropertyMap childMap = childrenMap.getPropertyMap(key);
61: MetaComplexChild child = new MetaComplexChild(childMap);
62: children.put(key, child);
63: child.setName(key);
64: }
65: }
66: }
67:
68: }
|