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.tools.generators;
010:
011: import java.util.ArrayList;
012: import java.util.LinkedHashMap;
013: import java.util.List;
014:
015: /**
016: * @author Gennady Krizhevsky
017: */
018: public class DependencyEntity {
019:
020: static final String LIST_IMPL = "ArrayList";
021: static final String MAP_IMPL = "LinkedHashMap";
022:
023: public static final LinkedHashMap STANDARD_TYPES_2_JAVA_MAP = new LinkedHashMap();
024:
025: static {
026: STANDARD_TYPES_2_JAVA_MAP.put("string", "String");
027: STANDARD_TYPES_2_JAVA_MAP.put("hex_string", "String");
028: STANDARD_TYPES_2_JAVA_MAP.put("number", "Number");
029: STANDARD_TYPES_2_JAVA_MAP.put("comp_number", "Number");
030: STANDARD_TYPES_2_JAVA_MAP.put("timestamp", "Timestamp");
031: STANDARD_TYPES_2_JAVA_MAP.put("boolean", "Boolean");
032: STANDARD_TYPES_2_JAVA_MAP.put("dynamic", "dynamic");
033:
034: STANDARD_TYPES_2_JAVA_MAP.put(LIST_IMPL, LIST_IMPL);
035: STANDARD_TYPES_2_JAVA_MAP.put(MAP_IMPL, MAP_IMPL);
036: }
037:
038: private List dependencies = new ArrayList(); // List of class names this entity is dependent upon
039: private List innerClassDependencies = new ArrayList(); // List of class names this entity is dependent upon
040: private boolean gottenClassDependencies;
041:
042: private String name;
043: private String className;
044: private int level;
045: private String pad = "";
046: private int standardClass;
047: public static final int LOCAL = 0;
048: public static final int STANDARD = 1;
049: public static final int LIST = 2;
050: public static final int MAP = 3;
051:
052: public DependencyEntity(String name, String className, int level) {
053: this .name = name;
054: this .className = className;
055: this .level = level;
056:
057: if ((STANDARD_TYPES_2_JAVA_MAP.containsKey(className) || STANDARD_TYPES_2_JAVA_MAP
058: .containsValue(className))) {
059: if (className.indexOf("List") >= 0) {
060: standardClass = LIST;
061: } else if (className.indexOf("Map") >= 0) {
062: standardClass = MAP;
063: } else {
064: standardClass = STANDARD;
065: }
066: } else {
067: standardClass = LOCAL;
068: }
069:
070: for (int i = 0; i < level; i++) {
071: this .pad += " ";
072: }
073:
074: }
075:
076: public void loadInnerClassDependencies(DependencyEntity rootEntity) {
077: if (!gottenClassDependencies) {
078: loadInnerClassDependencies(rootEntity, this );
079: gottenClassDependencies = true;
080: }
081: }
082:
083: protected void loadInnerClassDependencies(
084: DependencyEntity rootEntity, DependencyEntity parentEntity) {
085:
086: //
087: // Get all the stuff from this object:
088: //
089: for (int i = 0; i < dependencies.size(); i++) {
090: if (!rootEntity
091: .containsDependencyByClassName(getDependency(i)
092: .getClassName())
093: && !STANDARD_TYPES_2_JAVA_MAP
094: .containsValue(getDependency(i)
095: .getClassName())
096: && !parentEntity
097: .containsInnerClassDependencyByClassName(getDependency(
098: i).getClassName())) {
099: parentEntity.addInnerClassDependency(getDependency(i));
100: }
101:
102: getDependency(i).loadInnerClassDependencies(rootEntity,
103: parentEntity);
104: }
105: }
106:
107: public boolean containsInnerClassDependencyByClassName(String name) {
108: for (int i = 0; i < innerClassDependencies.size(); i++) {
109: if (name.equals(getDependency(i).getClassName())) {
110: return true;
111: }
112: }
113: return false;
114: }
115:
116: public boolean containsDependencyByName(String name) {
117: for (int i = 0; i < dependencies.size(); i++) {
118: if (name.equals(getDependency(i).getName())) {
119: return true;
120: }
121: }
122: return false;
123: }
124:
125: public boolean containsDependencyByClassName(String name) {
126: for (int i = 0; i < dependencies.size(); i++) {
127: if (name.equals(getDependency(i).getClassName())) {
128: return true;
129: }
130: }
131: return false;
132: }
133:
134: public boolean addInnerClassDependency(
135: DependencyEntity dependencyEntity) {
136: return innerClassDependencies.add(dependencyEntity);
137: }
138:
139: public boolean addDependency(DependencyEntity dependencyEntity) {
140: return dependencies.add(dependencyEntity);
141: }
142:
143: public boolean contains(DependencyEntity dependency) {
144: return dependencies.contains(dependency);
145: }
146:
147: public String getName() {
148: return name;
149: }
150:
151: public void setName(String name) {
152: this .name = name;
153: }
154:
155: public String getClassName() {
156: return className;
157: }
158:
159: public void setClassName(String className) {
160: this .className = className;
161: }
162:
163: public List getDependOn() {
164: return dependencies;
165: }
166:
167: public List getDependencies() {
168: return dependencies;
169: }
170:
171: public List getInnerClassDependencies() {
172: return innerClassDependencies;
173: }
174:
175: public DependencyEntity getDependency(int i) {
176: return (DependencyEntity) dependencies.get(i);
177: }
178:
179: public String getPad() {
180: return pad;
181: }
182:
183: public int getLevel() {
184: return level;
185: }
186:
187: public int standardClass() {
188: return standardClass;
189: }
190:
191: public String toString() {
192: return dependencies.size() == 0 ? pad + className + "::" + name
193: + " : level " + level : "\n" + pad + className + "::"
194: + name + " : level " + level + " dependencies--> "
195: + dependencies + "\n";
196: }
197:
198: }
|