01: package com.completex.objective.tools.generators;
02:
03: import com.completex.objective.components.persistency.MetaTable;
04: import com.completex.objective.components.persistency.meta.MetaObjectModel;
05: import com.completex.objective.components.persistency.meta.MetaObjectReference;
06: import com.completex.objective.components.persistency.meta.MetaRef;
07: import com.completex.objective.components.persistency.meta.MetaComplexChild;
08:
09: /**
10: * @author Gennady Krizhevsky
11: */
12: public class ComplexChildHandler extends BaseExtractHandler {
13:
14: protected MetaTable rootMetaTable;
15:
16: protected ComplexChildHandler() {
17: }
18:
19: public ComplexChildHandler(MetaObjectReference metaObjectReference,
20: MetaModelsExtractor.ExtractStruct extractStruct,
21: MetaObjectModel metaObjectModel, String key,
22: boolean generateClasses) {
23: this .metaObjectReference = metaObjectReference;
24: this .extractStruct = extractStruct;
25: this .metaObjectModel = metaObjectModel;
26: this .key = key;
27: this .generateClassesOnly = generateClasses;
28:
29: handle();
30: }
31:
32: protected void handle() {
33: extractRootMetaTable();
34: }
35:
36: /**
37: *
38: * Extract child base name.
39: *
40: * @param key
41: * @param childReferencing
42: */
43: public void handleChild(String key,
44: MetaComplexChild childReferencing) {
45: extractBase(childReferencing);
46: }
47:
48: protected MetaRef extractRootMetaTable() {
49: MetaRef baseRef = metaObjectReference.getBase();
50: if (baseRef.getName() == null) {
51: throw new IllegalArgumentException(
52: "Base reference name is null for metaObjectReference ["
53: + key + "]");
54: }
55:
56: //
57: // 2. Set root meta table:
58: //
59: MetaModelsExtractor.ExtractStructEntry rootEntry = extractRootEntry(baseRef);
60: rootMetaTable = rootEntry.getMetaTable();
61: return baseRef;
62: }
63:
64: protected MetaModelsExtractor.ExtractStructEntry extractRootEntry(
65: MetaRef base) {
66: MetaModelsExtractor.ExtractStructEntry parentEntry = extractStruct
67: .getEntry(base.getName());
68: if (parentEntry == null) {
69: MetaObjectReference parentReference = metaObjectModel
70: .getMetaObjectReference(base.getName());
71: if (parentReference == null) {
72: return null;
73: } else {
74: return extractRootEntry(parentReference.getBase());
75: }
76: }
77: return parentEntry;
78: }
79:
80: protected MetaTable extractChildMetaTable(MetaRef childBase) {
81: MetaTable childMetaTable = null;
82: String refName = childBase.getName();
83: MetaModelsExtractor.ExtractStructEntry entry = extractRootEntry(childBase);
84: if (entry != null && refName != null) {
85: childMetaTable = entry.getMetaTable();
86: }
87: return childMetaTable;
88: }
89: }
|