Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package org.litesoft.generator;

import org.litesoft.aokeyhole.objects.*;
import org.litesoft.aokeyhole.objects.properties.*;
import org.litesoft.bo.*;
import org.litesoft.bo.change.*;
import org.litesoft.codegen.*;
import org.litesoft.util.*;

public class GenerateVOMetaDataGO extends AbstractVOFileGenerator
{
    public GenerateVOMetaDataGO( ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, DerivedObjectTuple pDerivedFromObject, ObjectRef pObjectRef, ObjectRef pParentObjectRef )
    {
        super( pErrorSinc, pObjectMetaData, pDerivedFromObject, pObjectRef, "MetaDataGO", pParentObjectRef );
    }

    @Override
    protected void LLaddImports()
    {
        addImports( //
                    "org.litesoft.bo.*", //
                    "org.litesoft.bo.attributes.*", //
                    "org.litesoft.bo.views.*", //
                    "org.litesoft.core.util.*", //
                    null );
    }

    protected void LLaddClassDefinition()
    {
        String zClassName = mClassName;
        String zExtendsName = getExtends( "AbstractVo" ) + "MetaData";

        if ( mIsParent )
        {
            zClassName += "<T extends " + mObjectName + ">";
            zExtendsName += "<T>";
        }
        else
        {
            zExtendsName += "<" + mObjectName + ">";
        }

        makeClassAbstract();
        addClassDefinition( zClassName, zExtendsName, mObjectName + "Names" );
    }

    @Override
    protected void LLaddClassBody()
    {
        addTopValidOptions( "vo" );
        if ( !mIsParent )
        {
            getInstance();
        }
        createViewObject();
        getDerivedFromRegisteredObjectType();
        createObjectUniqueKey();
        getDisplayValueFormat();
        if ( !mIsParent )
        {
            sInstance();
        }
        constructor();
    }

    private void getInstance()
    {
        addLine( "public static synchronized " + mObjectName + "MetaData getInstance()" );
        addBlockStart();
        addLine( "if ( sInstance == null )" );
        addBlockStart();
        addLine( "sInstance = new " + mObjectName + "MetaData();" );
        addBlockEnd();
        addLine( "return sInstance;" );
        addBlockEnd();
        addBlankLine();
    }

    private void createViewObject()
    {
        if ( mIsParent )
        {
            addMethodPublic( "T", "createViewObject", "boolean pNew", "TransactionSet pTransactionSet" );
            addLine( "throw unavailableMethod();" );
        }
        else
        {
            addMethodPublic( mObjectName, "createViewObject", "boolean pNew", "TransactionSet pTransactionSet" );
            addLine( "return new " + mObjectName + "( pNew, pTransactionSet );" );
        }
        addMethodEnd();
    }

    private void getDerivedFromRegisteredObjectType()
    {
        addMethodPublic( "String", "getDerivedFromRegisteredObjectType" );
        if ( mIsParent )
        {
            addLine( "throw unavailableMethod();" );
        }
        else
        {
            addLine( "return " + quote( mDerivedFromObject.getDerivedFrom() ) + ";" );
        }
        addMethodEnd();
    }

    private void createObjectUniqueKey()
    {
        addMethodPublic( "ObjectUniqueKey", "createObjectUniqueKey", "BoAccessor pBoAccessor" );
        if ( mIsParent )
        {
            addLine( "throw unavailableMethod();" );
        }
        else
        {
            addLine( mObjectName + " zView = (" + mObjectName + ") pBoAccessor;" );
            addLine( "return zView.isNew() ? createNewObjectUniqueKey( pBoAccessor ) : ObjectUniqueKey.createExisting( zView.getID() );" );
        }
        addMethodEnd();
    }

    private void getDisplayValueFormat()
    {
        String zDisplayValueFormat = Utils.noEmpty( mObjectMetaData.getPropertyManager().get_String( PMD_DisplayValueFormat.NAME, "" ) );
        addMethodPublic( "String", "getDisplayValueFormat" );
        if ( mIsParent )
        {
            addLine( "throw unavailableMethod();" );
        }
        else
        {
            addLine( "return " + quote( zDisplayValueFormat ) + ";" );
        }
        addMethodEnd();
    }

    private void sInstance()
    {
        addLine( "private static " + mObjectName + "MetaData sInstance = null;" );
        addBlankLine();
    }

    private void constructor()
    {
        if ( mIsParent )
        {
            addLine( "@SuppressWarnings({\"unchecked\"})" );
            addConstructorProtected( mClassName, "Class<T> pViewObjectClass", "VoAttributeList<T> pChildAttributes" );
            addLine( "super( pViewObjectClass, (VoAttributeList<T>) createLocals().augment( pChildAttributes ) );" );
            addMethodEnd();
        }
        else
        {
            addConstructorProtected( mClassName );
            addLine( "super( " + mObjectName + ".class, createLocals() );" );
            addMethodEnd();
        }

        addLine( "private static VoAttributeList<" + mObjectName + "> createLocals()" );
        addBlockStart();
        addLine( "VoAttribute[] zAttributes = //" );
        indentStart();
        indentStart();
        addLine( "{ //" );
        indentPlus( 2 );
        for ( AttributeProxy zAttribute : getAttributes() )
        {
            attributeAsParam( zAttribute );
        }
        indentMinus( 2 );
        addLine( "};" );
        indentEnd();
        indentEnd();
        addLine( "return new VoAttributeList<" + mObjectName + ">( zAttributes );" );
        addBlockEnd();
    }

    private void attributeAsParam( AttributeProxy pAttribute )
    {
        String zName = pAttribute.getName();
        String zTypeExtra = createAttributeTypedCall( pAttribute, "VO", "new SimpleVoAttribute<" + mObjectName + ">( a" + zName, "" );
        BoAttribute.AttributeType zType = pAttribute.getBoAttributeType();
        Mutability zMutability = pAttribute.getMutability();

        addBlockStart();

        addMethodPublic( "String", "getDerivedFromAttributePath" );
        addLine( "return " + quote( pAttribute.getDerivedFromAttribute() ) + ";" );
        addMethodEnd();

        addMethodPublic( "boolean", "isQueryViewAttribute" );
        addLine( "return " + pAttribute.isQueryView() + ";" );
        addMethodEnd();

        addMethodProtected( "Object", "LLgetAttributeValue", mObjectName + " pVO" );
        addLine( "return pVO.get" + zName + "();" );
        addMethodEnd();

        String zSetBody;
        if ( Mutability.RO.equals( zMutability ) && pAttribute.isVirtual() )
        {
            addLine( "@Override" );
            addMethodPublic( "boolean", "isSetable" );
            addLine( "return false;" );
            addMethodEnd();

            zSetBody = "throw new UnsupportedOperationException( \"'" + zName + "' is a Read Only attribute\" );";
        }
        else
        {
            zSetBody = "pVO.set" + zName + "( TypeConverter.to_" + zType + "( " + zTypeExtra + "pValue ) );";
        }

        addMethodPublic( "void", "setAttributeValue", mObjectName + " pVO", "Object pValue" );
        addLine( zSetBody );
        addBlockEnd();

        addBlockEnd( ", //" );
    }
}

Commits for litesoft/trunk/Java/PoVoGenerator/Generator/src/org/litesoft/generator/GenerateVOMetaDataGO.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000