001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.meta;
010:
011: import com.completex.objective.util.PropertyMap;
012: import com.completex.objective.components.persistency.Mappable;
013:
014: import java.util.LinkedHashMap;
015: import java.util.Map;
016:
017: /**
018: * @author Gennady Krizhevsky
019: */
020: public class MetaObjectReference implements Referencing, Mappable {
021: /*
022: CPX_TEST_MASTER = {
023: className = "CpxTestMaster"
024: base = {
025: tableName = TEST_MASTER
026: # tableAlias = XXX
027: # className = XXX
028: }
029:
030: complexChildren = {
031: slave = {
032: relationshipType = one_to_many
033: name = CPX_TEST_SLAVE
034: factory_method = cpxFactorySlave
035: lazy = TRUE
036: cascade_inserts = FALSE
037: cascade_updates = FALSE
038: cascade_deletes = FALSE
039: multipleResultFactory = com.completex.objective.components.persistency.type.TracingArrayListCollectionFactory
040: }
041: }
042:
043: compound = {
044: delegateFactory = {}
045: children = {
046: masterAttr = {
047: ref = {
048: name = TEST_MASTER_ATTR # Name of one of objectsReferences from this file
049: # or alias from external descriptor
050: # className = XXX
051: }
052: containmentType = has # has | is
053: cascadeInsert = true
054: cascadeDelete = true
055: }
056: }
057: }
058: }
059: */
060:
061: private String className;
062: private String interfaceName;
063: private MetaRef base;
064: private MetaComplex complex;
065: private MetaCompound compound;
066: //
067: // Tags:
068: //
069: public static final String TAG_CLASS_NAME = "className";
070: public static final String TAG_INTERFACE_NAME = "interfaceName";
071: public static final String TAG_BASE_OBJECT_NAME = "base";
072: public static final String TAG_COMPLEX = "complex";
073: public static final String TAG_COMPOUND = "compound";
074:
075: public MetaObjectReference() {
076: }
077:
078: public MetaObjectReference(Map map) {
079: fromMap(map);
080: }
081:
082: public Map toMap() {
083: Map map = new LinkedHashMap();
084: map.put(TAG_CLASS_NAME, className);
085: map.put(TAG_INTERFACE_NAME, interfaceName);
086: map.put(TAG_BASE_OBJECT_NAME, base.toMap());
087:
088: if (complex != null) {
089: map.put(TAG_COMPLEX, complex.toMap());
090: }
091:
092: if (compound != null) {
093: map.put(TAG_COMPOUND, compound.toMap());
094: }
095:
096: return map;
097: }
098:
099: public void fromMap(Map map) {
100: PropertyMap propertyMap = PropertyMap.toPropertyMap(map);
101: className = propertyMap.getProperty(TAG_CLASS_NAME);
102: interfaceName = propertyMap.getProperty(TAG_INTERFACE_NAME);
103: Map baseMap = propertyMap.getPropertyMap(TAG_BASE_OBJECT_NAME);
104: base = new MetaRef(baseMap);
105:
106: PropertyMap complexMap = propertyMap
107: .getPropertyMap(TAG_COMPLEX);
108: if (complexMap != null) {
109: complex = new MetaComplex(complexMap);
110: }
111:
112: PropertyMap compoundMap = propertyMap
113: .getPropertyMap(TAG_COMPOUND);
114: if (compoundMap != null) {
115: compound = new MetaCompound(compoundMap);
116: }
117: }
118:
119: public String getClassName() {
120: return className;
121: }
122:
123: public void setClassName(String className) {
124: this .className = className;
125: }
126:
127: public String getInterfaceName() {
128: return interfaceName;
129: }
130:
131: public void setInterfaceName(String interfaceName) {
132: this .interfaceName = interfaceName;
133: }
134:
135: public MetaRef getBase() {
136: return base;
137: }
138:
139: public void setBase(MetaRef base) {
140: this .base = base;
141: }
142:
143: public MetaComplex getComplex() {
144: return complex;
145: }
146:
147: public MetaCompound getCompound() {
148: return compound;
149: }
150:
151: public boolean isCompound() {
152: return compound != null && !compound.isEmpty();
153: }
154:
155: public Map getCompoundChildren() {
156: return compound == null ? null : compound.getChildren();
157: }
158:
159: public boolean hasCompoundChildren() {
160: return isCompound() && compound.hasChildren();
161: }
162:
163: public String toString() {
164: return toMap().toString();
165: }
166:
167: }
|