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 MetaCompoundChild extends MetaChild implements Mappable {
021:
022: public static final String TAG_REF = "ref";
023: public static final String TAG_CONTAINMENT_TYPE = "containmentType";
024: public static final String TAG_CASCADE_INSERT = "cascadeInsert";
025: public static final String TAG_CASCADE_DELETE = "cascadeDelete";
026: public static final String TAG_FACTORY_METHOD = "factoryMethod";
027: public static final String TAG_NAME = "name";
028:
029: public static final ContainmentType CONTAINMENT_HAS = ContainmentType.HAS;
030: public static final ContainmentType CONTAINMENT_IS = ContainmentType.IS;
031:
032: private String name;
033: private ContainmentType containmentType;
034: private boolean cascadeInsert;
035: private boolean cascadeDelete;
036: private String factoryMethod;
037:
038: public MetaCompoundChild() {
039: }
040:
041: public MetaCompoundChild(Map map) {
042: fromMap(map);
043: }
044:
045: public ContainmentType getContainmentType() {
046: return containmentType;
047: }
048:
049: public void setContainmentType(ContainmentType containmentType) {
050: this .containmentType = containmentType;
051: }
052:
053: public String getName() {
054: return name;
055: }
056:
057: public void setName(String name) {
058: this .name = name;
059: }
060:
061: public String getFactoryMethod() {
062: return factoryMethod;
063: }
064:
065: public boolean isCascadeInsert() {
066: return cascadeInsert;
067: }
068:
069: public void setCascadeInsert(boolean cascadeInsert) {
070: this .cascadeInsert = cascadeInsert;
071: }
072:
073: public boolean isCascadeDelete() {
074: return cascadeDelete;
075: }
076:
077: public void setCascadeDelete(boolean cascadeDelete) {
078: this .cascadeDelete = cascadeDelete;
079: }
080:
081: public Map toMap() {
082: LinkedHashMap map = new LinkedHashMap();
083: map.put(TAG_REF, ref.toMap());
084: map.put(TAG_CONTAINMENT_TYPE, containmentType.getName());
085: map.put(TAG_CASCADE_INSERT, Boolean.valueOf(cascadeInsert));
086: map.put(TAG_CASCADE_DELETE, Boolean.valueOf(cascadeDelete));
087: map.put(TAG_FACTORY_METHOD, factoryMethod);
088: map.put(TAG_NAME, name);
089: return map;
090: }
091:
092: public void fromMap(Map map) {
093: PropertyMap propertyMap = PropertyMap.toPropertyMap(map);
094:
095: Map refMap = propertyMap.getPropertyMap(TAG_REF, true);
096: ref = new MetaRef(refMap);
097: cascadeInsert = propertyMap.getBoolean(TAG_CASCADE_INSERT);
098: cascadeDelete = propertyMap.getBoolean(TAG_CASCADE_DELETE);
099: containmentType = ContainmentType.string2type(propertyMap
100: .getProperty(TAG_CONTAINMENT_TYPE, true));
101: factoryMethod = propertyMap.getProperty(TAG_FACTORY_METHOD);
102: name = propertyMap.getProperty(TAG_NAME);
103: }
104:
105: public static class ContainmentType {
106:
107: private static final String S_HAS = "has";
108: private static final String S_IS = "is";
109: static final ContainmentType HAS = new ContainmentType(S_HAS);
110: static final ContainmentType IS = new ContainmentType(S_IS);
111:
112: private String name;
113:
114: public ContainmentType(String name) {
115: this .name = name;
116: }
117:
118: public String getName() {
119: return name;
120: }
121:
122: public String toString() {
123: return name;
124: }
125:
126: public static ContainmentType string2type(String name) {
127: if (S_HAS.equals(name)) {
128: return HAS;
129: } else if (S_IS.equals(name)) {
130: return IS;
131: } else {
132: throw new IllegalArgumentException(
133: "Unsupported containment type: " + name);
134: }
135: }
136:
137: }
138: }
|