Subversion Repository Public Repository

litesoft

Diff Revisions 948 vs 950 for /trunk/Java/PoVoGenerator/Generator/src/org/litesoft/generator/GenerateVOMetaDataGO.java

Diff revisions: vs.
  @@ -1,195 +1,195 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.generator;
3 -
4 - import org.litesoft.aokeyhole.objects.*;
5 - import org.litesoft.aokeyhole.objects.properties.*;
6 - import org.litesoft.bo.*;
7 - import org.litesoft.bo.attributes.*;
8 - import org.litesoft.codegen.*;
9 - import org.litesoft.commonfoundation.typeutils.*;
10 -
11 - public class GenerateVOMetaDataGO extends AbstractVOFileGenerator {
12 - public GenerateVOMetaDataGO( ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, DerivedObjectTuple pDerivedFromObject, ObjectRef pObjectRef,
13 - ObjectRef pParentObjectRef ) {
14 - super( pErrorSinc, pObjectMetaData, pDerivedFromObject, pObjectRef, "MetaDataGO", pParentObjectRef );
15 - }
16 -
17 - @Override
18 - protected void LLaddImports() {
19 - addImports( //
20 - "org.litesoft.bo.*", //
21 - "org.litesoft.bo.attributes.*", //
22 - "org.litesoft.bo.views.*", //
23 - "org.litesoft.core.util.*", //
24 - null );
25 - }
26 -
27 - @Override
28 - protected void LLaddClassDefinition() {
29 - String zClassName = mClassName;
30 - String zExtendsName = getExtends( "AbstractVo" ) + "MetaData";
31 -
32 - if ( mIsParent ) {
33 - zClassName += "<T extends " + mObjectName + ">";
34 - zExtendsName += "<T>";
35 - } else {
36 - zExtendsName += "<" + mObjectName + ">";
37 - }
38 -
39 - makeClassAbstract();
40 - addClassDefinition( zClassName, zExtendsName, mObjectName + "Names" );
41 - }
42 -
43 - @Override
44 - protected void LLaddClassBody() {
45 - addTopValidOptions( "vo" );
46 - if ( !mIsParent ) {
47 - getInstance();
48 - }
49 - createViewObject();
50 - getDerivedFromRegisteredObjectType();
51 - createObjectUniqueKey();
52 - getDisplayValueFormat();
53 - if ( !mIsParent ) {
54 - sInstance();
55 - }
56 - constructor();
57 - }
58 -
59 - private void getInstance() {
60 - addLine( "public static synchronized " + mObjectName + "MetaData getInstance()" );
61 - addBlockStart();
62 - addLine( "if ( sInstance == null )" );
63 - addBlockStart();
64 - addLine( "sInstance = new " + mObjectName + "MetaData();" );
65 - addBlockEnd();
66 - addLine( "return sInstance;" );
67 - addBlockEnd();
68 - addBlankLine();
69 - }
70 -
71 - private void createViewObject() {
72 - addLine( "@Override" );
73 - if ( mIsParent ) {
74 - addMethodPublic( "T", "createViewObject", "boolean pNew", "TransactionSet pTransactionSet" );
75 - addLine( "throw unavailableMethod();" );
76 - } else {
77 - addMethodPublic( mObjectName, "createViewObject", "boolean pNew", "TransactionSet pTransactionSet" );
78 - addLine( "return new " + mObjectName + "( pNew, pTransactionSet );" );
79 - }
80 - addMethodEnd();
81 - }
82 -
83 - private void getDerivedFromRegisteredObjectType() {
84 - addLine( "@Override" );
85 - addMethodPublic( "String", "getDerivedFromRegisteredObjectType" );
86 - if ( mIsParent ) {
87 - addLine( "throw unavailableMethod();" );
88 - } else {
89 - addLine( "return " + quote( mDerivedFromObject.getDerivedFrom() ) + ";" );
90 - }
91 - addMethodEnd();
92 - }
93 -
94 - private void createObjectUniqueKey() {
95 - addLine( "@Override" );
96 - addMethodPublic( "ObjectUniqueKey", "createObjectUniqueKey", "BoAccessor pBoAccessor" );
97 - if ( mIsParent ) {
98 - addLine( "throw unavailableMethod();" );
99 - } else {
100 - addLine( mObjectName + " zView = (" + mObjectName + ") pBoAccessor;" );
101 - addLine( "return zView.isNew() ? createNewObjectUniqueKey( pBoAccessor ) : ObjectUniqueKey.createExisting( zView.getID() );" );
102 - }
103 - addMethodEnd();
104 - }
105 -
106 - private void getDisplayValueFormat() {
107 - addLine( "@Override" );
108 - String zDisplayValueFormat = Strings.noEmpty( mObjectMetaData.getPropertyManager().get_String( PMD_DisplayValueFormat.NAME, "" ) );
109 - addMethodPublic( "String", "getDisplayValueFormat" );
110 - if ( mIsParent ) {
111 - addLine( "throw unavailableMethod();" );
112 - } else {
113 - addLine( "return " + quote( zDisplayValueFormat ) + ";" );
114 - }
115 - addMethodEnd();
116 - }
117 -
118 - private void sInstance() {
119 - addLine( "private static " + mObjectName + "MetaData sInstance = null;" );
120 - addBlankLine();
121 - }
122 -
123 - private void constructor() {
124 - if ( mIsParent ) {
125 - addLine( "@SuppressWarnings({\"unchecked\"})" );
126 - addConstructorProtected( mClassName, "Class<T> pViewObjectClass", "VoAttributeList<T> pChildAttributes" );
127 - addLine( "super( pViewObjectClass, (VoAttributeList<T>) createLocals().augment( pChildAttributes ) );" );
128 - addMethodEnd();
129 - } else {
130 - addConstructorProtected( mClassName );
131 - addLine( "super( " + mObjectName + ".class, createLocals() );" );
132 - addMethodEnd();
133 - }
134 -
135 - addLine( "private static VoAttributeList<" + mObjectName + "> createLocals()" );
136 - addBlockStart();
137 - addLine( "VoAttribute[] zAttributes = //" );
138 - indentStart();
139 - indentStart();
140 - addLine( "{ //" );
141 - indentPlus( 2 );
142 - for ( AttributeProxy zAttribute : getAttributes() ) {
143 - attributeAsParam( zAttribute );
144 - }
145 - indentMinus( 2 );
146 - addLine( "};" );
147 - indentEnd();
148 - indentEnd();
149 - addLine( "return new VoAttributeList<" + mObjectName + ">( zAttributes );" );
150 - addBlockEnd();
151 - }
152 -
153 - private void attributeAsParam( AttributeProxy pAttribute ) {
154 - String zName = pAttribute.getName();
155 - String zTypeExtra = createAttributeTypedCall( pAttribute, "VO", "new SimpleVoAttribute<" + mObjectName + ">( a" + zName, "" );
156 - BoAttribute.AttributeType zType = pAttribute.getBoAttributeType();
157 - Mutability zMutability = pAttribute.getMutability();
158 -
159 - addBlockStart();
160 -
161 - addLine( "@Override" );
162 - addMethodPublic( "String", "getDerivedFromAttributePath" );
163 - addLine( "return " + quote( pAttribute.getDerivedFromAttribute() ) + ";" );
164 - addMethodEnd();
165 -
166 - addLine( "@Override" );
167 - addMethodPublic( "boolean", "isQueryViewAttribute" );
168 - addLine( "return " + pAttribute.isQueryView() + ";" );
169 - addMethodEnd();
170 -
171 - addLine( "@Override" );
172 - addMethodProtected( "Object", "LLgetAttributeValue", mObjectName + " pVO" );
173 - addLine( "return pVO.get" + zName + "();" );
174 - addMethodEnd();
175 -
176 - String zSetBody;
177 - if ( Mutability.RO.equals( zMutability ) && pAttribute.isVirtual() ) {
178 - addLine( "@Override" );
179 - addMethodPublic( "boolean", "isSetable" );
180 - addLine( "return false;" );
181 - addMethodEnd();
182 -
183 - zSetBody = "throw new UnsupportedOperationException( \"'" + zName + "' is a Read Only attribute\" );";
184 - } else {
185 - zSetBody = "pVO.set" + zName + "( TypeConverter.to_" + zType + "( " + zTypeExtra + "pValue ) );";
186 - }
187 -
188 - addLine( "@Override" );
189 - addMethodPublic( "void", "setAttributeValue", mObjectName + " pVO", "Object pValue" );
190 - addLine( zSetBody );
191 - addBlockEnd();
192 -
193 - addBlockEnd( ", //" );
194 - }
195 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.generator;
3 +
4 + import org.litesoft.aokeyhole.objects.*;
5 + import org.litesoft.aokeyhole.objects.properties.*;
6 + import org.litesoft.bo.*;
7 + import org.litesoft.bo.attributes.*;
8 + import org.litesoft.codegen.*;
9 + import org.litesoft.commonfoundation.base.*;
10 +
11 + public class GenerateVOMetaDataGO extends AbstractVOFileGenerator {
12 + public GenerateVOMetaDataGO( ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, DerivedObjectTuple pDerivedFromObject, ObjectRef pObjectRef,
13 + ObjectRef pParentObjectRef ) {
14 + super( pErrorSinc, pObjectMetaData, pDerivedFromObject, pObjectRef, "MetaDataGO", pParentObjectRef );
15 + }
16 +
17 + @Override
18 + protected void LLaddImports() {
19 + addImports( //
20 + "org.litesoft.bo.*", //
21 + "org.litesoft.bo.attributes.*", //
22 + "org.litesoft.bo.views.*", //
23 + "org.litesoft.core.util.*", //
24 + null );
25 + }
26 +
27 + @Override
28 + protected void LLaddClassDefinition() {
29 + String zClassName = mClassName;
30 + String zExtendsName = getExtends( "AbstractVo" ) + "MetaData";
31 +
32 + if ( mIsParent ) {
33 + zClassName += "<T extends " + mObjectName + ">";
34 + zExtendsName += "<T>";
35 + } else {
36 + zExtendsName += "<" + mObjectName + ">";
37 + }
38 +
39 + makeClassAbstract();
40 + addClassDefinition( zClassName, zExtendsName, mObjectName + "Names" );
41 + }
42 +
43 + @Override
44 + protected void LLaddClassBody() {
45 + addTopValidOptions( "vo" );
46 + if ( !mIsParent ) {
47 + getInstance();
48 + }
49 + createViewObject();
50 + getDerivedFromRegisteredObjectType();
51 + createObjectUniqueKey();
52 + getDisplayValueFormat();
53 + if ( !mIsParent ) {
54 + sInstance();
55 + }
56 + constructor();
57 + }
58 +
59 + private void getInstance() {
60 + addLine( "public static synchronized " + mObjectName + "MetaData getInstance()" );
61 + addBlockStart();
62 + addLine( "if ( sInstance == null )" );
63 + addBlockStart();
64 + addLine( "sInstance = new " + mObjectName + "MetaData();" );
65 + addBlockEnd();
66 + addLine( "return sInstance;" );
67 + addBlockEnd();
68 + addBlankLine();
69 + }
70 +
71 + private void createViewObject() {
72 + addLine( "@Override" );
73 + if ( mIsParent ) {
74 + addMethodPublic( "T", "createViewObject", "boolean pNew", "TransactionSet pTransactionSet" );
75 + addLine( "throw unavailableMethod();" );
76 + } else {
77 + addMethodPublic( mObjectName, "createViewObject", "boolean pNew", "TransactionSet pTransactionSet" );
78 + addLine( "return new " + mObjectName + "( pNew, pTransactionSet );" );
79 + }
80 + addMethodEnd();
81 + }
82 +
83 + private void getDerivedFromRegisteredObjectType() {
84 + addLine( "@Override" );
85 + addMethodPublic( "String", "getDerivedFromRegisteredObjectType" );
86 + if ( mIsParent ) {
87 + addLine( "throw unavailableMethod();" );
88 + } else {
89 + addLine( "return " + quote( mDerivedFromObject.getDerivedFrom() ) + ";" );
90 + }
91 + addMethodEnd();
92 + }
93 +
94 + private void createObjectUniqueKey() {
95 + addLine( "@Override" );
96 + addMethodPublic( "ObjectUniqueKey", "createObjectUniqueKey", "BoAccessor pBoAccessor" );
97 + if ( mIsParent ) {
98 + addLine( "throw unavailableMethod();" );
99 + } else {
100 + addLine( mObjectName + " zView = (" + mObjectName + ") pBoAccessor;" );
101 + addLine( "return zView.isNew() ? createNewObjectUniqueKey( pBoAccessor ) : ObjectUniqueKey.createExisting( zView.getID() );" );
102 + }
103 + addMethodEnd();
104 + }
105 +
106 + private void getDisplayValueFormat() {
107 + addLine( "@Override" );
108 + String zDisplayValueFormat = ConstrainTo.significantOrNull( mObjectMetaData.getPropertyManager().get_String( PMD_DisplayValueFormat.NAME, "" ) );
109 + addMethodPublic( "String", "getDisplayValueFormat" );
110 + if ( mIsParent ) {
111 + addLine( "throw unavailableMethod();" );
112 + } else {
113 + addLine( "return " + quote( zDisplayValueFormat ) + ";" );
114 + }
115 + addMethodEnd();
116 + }
117 +
118 + private void sInstance() {
119 + addLine( "private static " + mObjectName + "MetaData sInstance = null;" );
120 + addBlankLine();
121 + }
122 +
123 + private void constructor() {
124 + if ( mIsParent ) {
125 + addLine( "@SuppressWarnings({\"unchecked\"})" );
126 + addConstructorProtected( mClassName, "Class<T> pViewObjectClass", "VoAttributeList<T> pChildAttributes" );
127 + addLine( "super( pViewObjectClass, (VoAttributeList<T>) createLocals().augment( pChildAttributes ) );" );
128 + addMethodEnd();
129 + } else {
130 + addConstructorProtected( mClassName );
131 + addLine( "super( " + mObjectName + ".class, createLocals() );" );
132 + addMethodEnd();
133 + }
134 +
135 + addLine( "private static VoAttributeList<" + mObjectName + "> createLocals()" );
136 + addBlockStart();
137 + addLine( "VoAttribute[] zAttributes = //" );
138 + indentStart();
139 + indentStart();
140 + addLine( "{ //" );
141 + indentPlus( 2 );
142 + for ( AttributeProxy zAttribute : getAttributes() ) {
143 + attributeAsParam( zAttribute );
144 + }
145 + indentMinus( 2 );
146 + addLine( "};" );
147 + indentEnd();
148 + indentEnd();
149 + addLine( "return new VoAttributeList<" + mObjectName + ">( zAttributes );" );
150 + addBlockEnd();
151 + }
152 +
153 + private void attributeAsParam( AttributeProxy pAttribute ) {
154 + String zName = pAttribute.getName();
155 + String zTypeExtra = createAttributeTypedCall( pAttribute, "VO", "new SimpleVoAttribute<" + mObjectName + ">( a" + zName, "" );
156 + BoAttribute.AttributeType zType = pAttribute.getBoAttributeType();
157 + Mutability zMutability = pAttribute.getMutability();
158 +
159 + addBlockStart();
160 +
161 + addLine( "@Override" );
162 + addMethodPublic( "String", "getDerivedFromAttributePath" );
163 + addLine( "return " + quote( pAttribute.getDerivedFromAttribute() ) + ";" );
164 + addMethodEnd();
165 +
166 + addLine( "@Override" );
167 + addMethodPublic( "boolean", "isQueryViewAttribute" );
168 + addLine( "return " + pAttribute.isQueryView() + ";" );
169 + addMethodEnd();
170 +
171 + addLine( "@Override" );
172 + addMethodProtected( "Object", "LLgetAttributeValue", mObjectName + " pVO" );
173 + addLine( "return pVO.get" + zName + "();" );
174 + addMethodEnd();
175 +
176 + String zSetBody;
177 + if ( Mutability.RO.equals( zMutability ) && pAttribute.isVirtual() ) {
178 + addLine( "@Override" );
179 + addMethodPublic( "boolean", "isSetable" );
180 + addLine( "return false;" );
181 + addMethodEnd();
182 +
183 + zSetBody = "throw new UnsupportedOperationException( \"'" + zName + "' is a Read Only attribute\" );";
184 + } else {
185 + zSetBody = "pVO.set" + zName + "( TypeConverter.to_" + zType + "( " + zTypeExtra + "pValue ) );";
186 + }
187 +
188 + addLine( "@Override" );
189 + addMethodPublic( "void", "setAttributeValue", mObjectName + " pVO", "Object pValue" );
190 + addLine( zSetBody );
191 + addBlockEnd();
192 +
193 + addBlockEnd( ", //" );
194 + }
195 + }