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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
package org.litesoft.generator;
import org.litesoft.aokeyhole.objects.*;
import org.litesoft.aokeyhole.objects.attributes.*;
import org.litesoft.aokeyhole.objects.properties.*;
import org.litesoft.aokeyhole.objects.support.*;
import org.litesoft.bo.*;
import org.litesoft.bo.change.*;
import org.litesoft.codegen.*;
import org.litesoft.core.util.*;
import java.util.*;
public abstract class AbstractVOFileGenerator extends AbstractTypeFileGenerator
{
private class AttributeTuple implements AttributeProxy
{
private AttributeMetaData mOrigAMD;
private String mDerivedFromAttribute;
private AttributeMetaData mDerivedAMD;
public AttributeTuple( AttributeMetaData pOrigAMD, String pDerivedFromAttribute, AttributeMetaData pDerivedAMD )
{
mOrigAMD = pOrigAMD;
mDerivedFromAttribute = pDerivedFromAttribute;
mDerivedAMD = pDerivedAMD;
}
public AttributeTuple( AttributeMetaData pAMD )
{
this( pAMD, null, pAMD );
}
@Override
public String toString()
{
return mOrigAMD.toString();
}
public boolean isInjected()
{
return false;
}
public String getDerivedFromAttribute()
{
return mDerivedFromAttribute;
}
public String getName()
{
return mOrigAMD.getName();
}
public String getColumnName()
{
throw new UnsupportedOperationException( "Column Name for VOs?" );
}
public Mutability getMutability()
{
return convertToMutability( mOrigAMD );
}
public boolean isSysSetOnly()
{
return false;
}
public String getNotes()
{
return mOrigAMD.getNotes();
}
public boolean isVirtual()
{
return mOrigAMD.isVirtual();
}
public Class getSimpleDataType()
{
return extractSimpleDataType( mDerivedAMD );
}
public String[] getValidOptions()
{
if ( mDerivedAMD instanceof AttributeMetaDataValidOptions )
{
String[] zOptions = ((AttributeMetaDataValidOptions) mDerivedAMD).getValidOptions();
return (zOptions != null) ? zOptions : UtilsCommon.EMPTY_STRING_ARRAY;
}
return null;
}
public BoAttribute.AttributeType getBoAttributeType()
{
return getType( mDerivedAMD );
}
public AttributeType getAttributeType()
{
return mDerivedAMD.getAttributeSet().getType();
}
public boolean isRequired()
{
return mOrigAMD.getPropertyManager().get_boolean( PMD_Required.NAME );
}
public boolean isQueryView()
{
return mOrigAMD.getPropertyManager().get_boolean( PMD_QueryView.NAME );
}
public PropertyManager getPropertyManager()
{
return mDerivedAMD.getPropertyManager();
}
public String getToManyFullyQualifiedName()
{
return null;
}
public String getToManyBackReference()
{
return null;
}
public AttributeProxy getToManyBackReferenceAttributeProxy()
{
return null;
}
public String getToOneFullyQualifiedName()
{
return null;
}
public String getToOneBackReference()
{
return null;
}
public AttributeProxy getToOneBackReferenceAttributeProxy()
{
return null;
}
}
protected final DerivedObjectTuple mDerivedFromObject;
private AttributeProxy[] mAttributes = null;
public AbstractVOFileGenerator( ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, DerivedObjectTuple pDerivedFromObject, ObjectRef pObjectRef, String pTypeExtension, ObjectRef pParentObjectRef )
{
super( "View Object", pErrorSinc, pObjectMetaData, pObjectRef, pTypeExtension, pParentObjectRef, pDerivedFromObject.isFromChild() );
mDerivedFromObject = pDerivedFromObject;
}
protected AttributeProxy[] getAttributes()
{
if ( mAttributes == null )
{
List<AttributeMetaData> zAttributes = mObjectMetaData.getSortedAttributes();
mAttributes = new AttributeTuple[zAttributes.size()];
for ( int i = 0; i < zAttributes.size(); i++ )
{
AttributeMetaData zAttribute = zAttributes.get( i );
String zDerivedFromAttribute = getDerivedFromAttributePath( zAttribute );
if ( zDerivedFromAttribute.length() == 0 )
{
mAttributes[i] = new AttributeTuple( zAttribute );
}
else
{
mAttributes[i] = new AttributeTuple( zAttribute, zDerivedFromAttribute, getDerivedFromAttribute( zAttribute, zDerivedFromAttribute ) );
}
}
}
return mAttributes;
}
private String getDerivedFromAttributePath( AttributeMetaData pAttribute )
{
return pAttribute.getPropertyManager().get_String( PMD_DerivedFromAttribute.NAME, "" ).trim();
}
private AttributeMetaData getDerivedFromAttribute( AttributeMetaData pAttribute, String pDerivedFromAttributePath )
{
ObjectMetaData zDerivedFromObject = mDerivedFromObject.getDerivedFromObjectMetaData();
if ( zDerivedFromObject == null )
{
mErrorSinc.addError( "DeriveAttributeButNoDerivedObject",
"Named: " + pDerivedFromAttributePath, pAttribute.toString(), mObjectMetaData.toStringForError() );
}
else
{
AttributeMetaData zDerived = getDerivedAttribute( zDerivedFromObject, UtilsCommon.parseChar( pDerivedFromAttributePath, '.' ) );
if ( zDerived != null )
{
return zDerived;
}
mErrorSinc.addError( "DeriveAttributeFailure", "with path: " +
pDerivedFromAttributePath, zDerivedFromObject.toStringForError(), pAttribute.toString(), mObjectMetaData.toStringForError() );
}
// create a Fake One so no other code fails (in theory as it is not wired into anything)!
return new AttributeMetaDataSimple( new UiRUpSet( 0, A_String.TYPE, new ASet(), new ASet() ), Mode.New, false, false, PropertyMetaData.EMPTY_ARRAY, null, pDerivedFromAttributePath );
}
private AttributeMetaData getDerivedAttribute( ObjectMetaData pObjectMetaData, String[] pAttrNames )
{
int i = 0;
AttributeMetaData zAMD = getAttribute( pObjectMetaData, pAttrNames[i++] );
while ( (zAMD != null) && (i < pAttrNames.length) )
{
if ( zAMD instanceof AttributeMetaDataRelated )
{
String zNextObject = ((AttributeMetaDataRelated) zAMD).getRelatedTo();
if ( zNextObject != null )
{
SystemMetaData zSysMD = getSystemMetaData( pObjectMetaData );
if ( zSysMD != null )
{
pObjectMetaData = zSysMD.getObject( zNextObject );
if ( pObjectMetaData != null )
{
zAMD = getAttribute( pObjectMetaData, pAttrNames[i++] );
continue;
}
}
}
}
return null;
}
return zAMD;
}
}
|