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 com.completex.objective.components.persistency.meta.MetaModel;
012: import com.completex.objective.components.persistency.ColumnType;
013: import com.completex.objective.components.persistency.MetaTable;
014: import com.completex.objective.components.persistency.MetaColumn;
015: import com.completex.objective.util.PropertyMap;
016:
017: import java.util.LinkedHashMap;
018: import java.util.Map;
019: import java.util.Set;
020: import java.util.Properties;
021:
022: /**
023: * @author Gennady Krizhevsky
024: */
025: public interface MetaModelsExtractor {
026: /**
027: * @param propertiesPath
028: * @return meta models
029: * @throws Exception
030: */
031: ExtractStruct extractMetaModels(String propertiesPath)
032: throws Exception;
033:
034: ExtractStruct extractMetaModels(String propertiesPath,
035: Properties env) throws Exception;
036:
037: String javaType(ColumnType type);
038:
039: Map prepareClassTableTemplateMap(MetaTable table,
040: LineStruct classStruct, LineStruct intfStruct);
041:
042: Map prepareInterfaceTableMap(MetaTable table, LineStruct intfStruct);
043:
044: static class LineStruct implements Cloneable {
045: String inFilePath;
046: String exFilePath;
047: String outputPath;
048: String packageName;
049: String templatePath;
050: String filterPattern;
051: String classPrefix;
052: String classSuffix;
053: String parentClass;
054: String implements String;
055: boolean generateInterfaces;
056: boolean generateLifeCycleCtl;
057: boolean generateBean = true;
058: boolean debug;
059:
060: String genericImports;
061: String specificImports;
062:
063: String metaAssemblyTemplatePath;
064: String metaAssemblyClassPrefix;
065: String metaAssemblyClassSuffix;
066:
067: public Object clone() throws CloneNotSupportedException {
068: return super .clone();
069: }
070: }
071:
072: static class LineStructBlock implements Cloneable {
073: LineStruct classStruct;
074: LineStruct intfStruct;
075: PropertyMap propertyMap;
076:
077: private LineStructBlock[] blocks;
078:
079: public LineStructBlock(LineStruct classStruct,
080: LineStruct intfStruct, PropertyMap propertyMap) {
081: this .classStruct = classStruct;
082: this .intfStruct = intfStruct;
083: this .propertyMap = propertyMap;
084: }
085:
086: public Object clone() throws CloneNotSupportedException {
087: LineStructBlock block = (LineStructBlock) super .clone();
088: block.classStruct = (LineStruct) classStruct.clone();
089: block.intfStruct = intfStruct == null ? null
090: : (LineStruct) intfStruct.clone();
091: return block;
092: }
093:
094: LineStructBlock[] splitBlocks()
095: throws CloneNotSupportedException {
096: if (this .blocks == null) {
097: String[] externals = classStruct.exFilePath.split(",");
098: LineStructBlock[] blocks = new LineStructBlock[externals.length];
099: for (int i = 0; i < blocks.length; i++) {
100: blocks[i] = (LineStructBlock) clone();
101: blocks[i].classStruct.exFilePath = externals[i]
102: .trim();
103: if (blocks[i].intfStruct != null) {
104: blocks[i].intfStruct.exFilePath = externals[i]
105: .trim();
106: }
107: }
108: this .blocks = blocks;
109: }
110: return this .blocks;
111: }
112:
113: public PropertyMap getPropertyMap() {
114: return propertyMap;
115: }
116: }
117:
118: public static class ExtractStructEntry {
119:
120: public ExtractStructEntry() {
121: }
122:
123: public ExtractStructEntry(Number modelIndex,
124: MetaTable metaTables) {
125: this .modelIndex = modelIndex;
126: this .metaTable = metaTables;
127: }
128:
129: private Number modelIndex;
130: private MetaTable metaTable;
131: private boolean used;
132: private String baseClassPackageName;
133:
134: public Number getModelIndex() {
135: return modelIndex;
136: }
137:
138: public void setModelIndex(Number modelIndex) {
139: this .modelIndex = modelIndex;
140: }
141:
142: public MetaTable getMetaTable() {
143: return metaTable;
144: }
145:
146: public void setMetaTable(MetaTable metaTable) {
147: this .metaTable = metaTable;
148: }
149:
150: public boolean isUsed() {
151: return used;
152: }
153:
154: public void setUsed(boolean used) {
155: this .used = used;
156: }
157:
158: public String getBaseClassPackageName() {
159: return baseClassPackageName;
160: }
161:
162: public void setBaseClassPackageName(String baseClassPackageName) {
163: this .baseClassPackageName = baseClassPackageName;
164: }
165: }
166:
167: public static class ExtractStruct {
168:
169: private MetaModelsExtractor metaModelsExtractor;
170: private LineStructBlock[] blocks;
171: private MetaModel[] metaModels;
172: private LinkedHashMap entries = new LinkedHashMap();
173:
174: public ExtractStruct() {
175: }
176:
177: public ExtractStruct(MetaModelsExtractor metaModelsExtractor,
178: LineStructBlock[] blocks) {
179: this .metaModelsExtractor = metaModelsExtractor;
180: this .blocks = blocks;
181: }
182:
183: public ExtractStructEntry putEntry(String key,
184: ExtractStructEntry entry) {
185: return (ExtractStructEntry) entries.put(key, entry);
186: }
187:
188: public ExtractStructEntry getEntry(String key) {
189: return (ExtractStructEntry) entries.get(key);
190: }
191:
192: public Set getEntryKeys() {
193: return entries.keySet();
194: }
195:
196: public LineStructBlock getBlock(int i) {
197: return blocks[i];
198: }
199:
200: public LineStructBlock[] getBlocks() {
201: return blocks;
202: }
203:
204: public MetaModel getMetaModel(int i) {
205: return metaModels[i];
206: }
207:
208: public MetaModel[] getMetaModels() {
209: return metaModels;
210: }
211:
212: public void setMetaModels(MetaModel[] metaModels) {
213: this .metaModels = metaModels;
214: }
215:
216: public MetaModelsExtractor getMetaModelsExtractor() {
217: return metaModelsExtractor;
218: }
219:
220: public void resetExcludeColumns() {
221: if (metaModels != null) {
222: for (int i = 0; i < metaModels.length; i++) {
223: MetaModel metaModel = metaModels[i];
224: for (MetaModel.MetaTableIterator it = metaModel
225: .tableIterator(); it.hasNext();) {
226: MetaTable table = it.nextMetaTable();
227: for (int j = 0; j < table.size(); j++) {
228: MetaColumn column = table.getColumn(j);
229: column.setExclude(false);
230: }
231: }
232: }
233: }
234: }
235:
236: }
237: }
|