Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/OldServer/src/org/litesoft/GWT/forms/server/support/TypeHelper.java

Diff revisions: vs.
  @@ -1,16 +1,12 @@
1 1 // This Source Code is in the Public Domain per: http://unlicense.org
2 2 package org.litesoft.GWT.forms.server.support;
3 3
4 - import org.litesoft.commonfoundation.typeutils.*;
5 -
6 - import java.util.*;
7 - import java.util.concurrent.atomic.*;
8 -
9 4 import org.litesoft.GWT.forms.server.*;
10 5 import org.litesoft.GWT.forms.server.support.converters.*;
11 6 import org.litesoft.GWT.forms.server.support.mdconstruction.*;
12 7 import org.litesoft.GWT.forms.server.support.nonpublic.*;
13 8 import org.litesoft.commonfoundation.typeutils.Objects;
9 + import org.litesoft.commonfoundation.typeutils.*;
14 10 import org.litesoft.core.simpletypes.*;
15 11 import org.litesoft.core.simpletypes.currency.*;
16 12 import org.litesoft.core.simpletypes.temporal.*;
  @@ -19,8 +15,10 @@
19 15 import org.litesoft.ui_1_5.*;
20 16 import org.litesoft.ui_1_5.def.*;
21 17
22 - public abstract class TypeHelper implements UI.Hints
23 - {
18 + import java.util.*;
19 + import java.util.concurrent.atomic.*;
20 +
21 + public abstract class TypeHelper implements UI.Hints {
24 22 private AtomicBoolean mDisposed = new AtomicBoolean( false );
25 23 private FSPTypeHelperBackDoor mBackDoor;
26 24 protected ExternalizationInterface mExternalization;
  @@ -39,27 +37,23 @@
39 37 protected TypeHelper( FSPTypeHelperBackDoor pBackDoor, //
40 38 ExternalizationInterface pExternalization, //
41 39 FormAccessControl pAccessControl, //
42 - TypeHelper pParent, String pRelativeType, FormUsage pUsage )
43 - {
40 + TypeHelper pParent, String pRelativeType, FormUsage pUsage ) {
44 41 Objects.assertNotNull( "BackDoor", mBackDoor = pBackDoor );
45 42 mExternalization = pExternalization.addContext( pRelativeType );
46 43 mAccessControl = pAccessControl.addContext( pRelativeType );
47 44 mParent = pParent;
48 45 mRelativeType = pRelativeType;
49 46 mFormUniqueID = pUsage.getUniqueID();
50 - if ( !(mBaseForm = pUsage.isBaseForm()) )
51 - {
47 + if ( !(mBaseForm = pUsage.isBaseForm()) ) {
52 48 mRelToThisSubForm = pUsage.getRelAttributeRef();
53 49 }
54 50 }
55 51
56 - public ExternalizationInterface getExternalization()
57 - {
52 + public ExternalizationInterface getExternalization() {
58 53 return mExternalization;
59 54 }
60 55
61 - public FormMetaData initializeAndCreateFormMetaData( FormUsage pUsage )
62 - {
56 + public FormMetaData initializeAndCreateFormMetaData( FormUsage pUsage ) {
63 57 FormMetaData zFMD = new FormMetaData( pUsage );
64 58
65 59 LLprocess( zFMD, pUsage );
  @@ -70,85 +64,68 @@
70 64 return zFMD;
71 65 }
72 66
73 - public TypeHelper getParent()
74 - {
67 + public TypeHelper getParent() {
75 68 return mParent;
76 69 }
77 70
78 - public String getRelativeType()
79 - {
71 + public String getRelativeType() {
80 72 return mRelativeType;
81 73 }
82 74
83 - public String getRelToThisSubForm()
84 - {
75 + public String getRelToThisSubForm() {
85 76 return mRelToThisSubForm;
86 77 }
87 78
88 - public boolean isBaseForm()
89 - {
79 + public boolean isBaseForm() {
90 80 return mBaseForm;
91 81 }
92 82
93 - public ServicePeerToFormDataProxy getCollectorProxy()
94 - {
83 + public ServicePeerToFormDataProxy getCollectorProxy() {
95 84 return mBackDoor.getCollectorProxy();
96 85 }
97 86
98 - public AMDconverterPair[] getAMDconvertPairs()
99 - {
87 + public AMDconverterPair[] getAMDconvertPairs() {
100 88 return mAMDconvertPairs;
101 89 }
102 90
103 - public Map<String, TypeHelper[]> getRelSubFormRefToTypes()
104 - {
91 + public Map<String, TypeHelper[]> getRelSubFormRefToTypes() {
105 92 return mRelSubFormRefToTypes;
106 93 }
107 94
108 - public Integer getFormUniqueID()
109 - {
95 + public Integer getFormUniqueID() {
110 96 return mFormUniqueID;
111 97 }
112 98
113 - public String resolveError( String pErrorID )
114 - {
99 + public String resolveError( String pErrorID ) {
115 100 return mExternalization.resolveError( pErrorID );
116 101 }
117 102
118 - public final boolean isDisposed()
119 - {
103 + public final boolean isDisposed() {
120 104 return mDisposed.get();
121 105 }
122 106
123 - public final void dispose()
124 - {
107 + public final void dispose() {
125 108 if ( !mDisposed.getAndSet( true ) ) // set true and test for false
126 109 {
127 - try
128 - {
110 + try {
129 111 LLdispose();
130 112 }
131 - catch ( RuntimeException e )
132 - {
113 + catch ( RuntimeException e ) {
133 114 FormServicePeer.LOGGER.error.log( e );
134 115 }
135 116 }
136 117 }
137 118
138 - protected void LLdispose()
139 - {
119 + protected void LLdispose() {
140 120 }
141 121
142 - public AMDconverterPair findAttribute( Integer uniqueId )
143 - {
122 + public AMDconverterPair findAttribute( Integer uniqueId ) {
144 123 return mAMDconvertPairsByAttributeID.get( uniqueId );
145 124 }
146 125
147 - public List<AttributeUpdateFormData> findAttributeUpdateFormDataByName( String pName )
148 - {
126 + public List<AttributeUpdateFormData> findAttributeUpdateFormDataByName( String pName ) {
149 127 List<AttributeUpdateFormData> zLocalList = new ArrayList<AttributeUpdateFormData>();
150 - for ( AMDconverterPair pair : mAMDconvertPairs )
151 - {
128 + for ( AMDconverterPair pair : mAMDconvertPairs ) {
152 129 AttributeMetaData meta = pair.getAttributeMetaData();
153 130 if ( pName.toLowerCase().equals(
154 131 meta.getAttributeReference().toLowerCase() ) ) // todo: Use Case Insensitive Compare
  @@ -160,13 +137,10 @@
160 137 return zLocalList;
161 138 }
162 139
163 - public List<ActionMetaData> findActionUpdateFormDataByName( String pName )
164 - {
140 + public List<ActionMetaData> findActionUpdateFormDataByName( String pName ) {
165 141 List<ActionMetaData> zLocalList = new ArrayList<ActionMetaData>();
166 - for ( ActionMetaData data : mActions )
167 - {
168 - if ( data.getActionID().equals( pName ) )
169 - {
142 + for ( ActionMetaData data : mActions ) {
143 + if ( data.getActionID().equals( pName ) ) {
170 144 zLocalList.add( data );
171 145 }
172 146 }
  @@ -184,18 +158,17 @@
184 158
185 159 public List<String> getAttributeNames() {
186 160 List<String> result = new ArrayList<String>();
187 - for( AMDconverterPair ap : getAMDconvertPairs() ) {
161 + for ( AMDconverterPair ap : getAMDconvertPairs() ) {
188 162 AttributeMetaData meta = ap.getAttributeMetaData();
189 - if( meta != null ) {
190 - result.add(meta.getAttributeReference());
163 + if ( meta != null ) {
164 + result.add( meta.getAttributeReference() );
191 165 }
192 166 }
193 167 return result;
194 168 }
195 169
196 170 public boolean actionRequest( String pActionID, boolean pInputAction,
197 - InstanceHelper pParentInstanceHelper )
198 - {
171 + InstanceHelper pParentInstanceHelper ) {
199 172 return !mBaseForm && "AddRow".equals( pActionID ) && createNewRow( pParentInstanceHelper );
200 173 }
201 174
  @@ -206,23 +179,19 @@
206 179 *
207 180 * @return true if successful
208 181 */
209 - protected boolean createNewRow( InstanceHelper pParentInstanceHelper )
210 - {
182 + protected boolean createNewRow( InstanceHelper pParentInstanceHelper ) {
211 183 return false;
212 184 }
213 185
214 - private void LLprocess( FormMetaData pFMD, FormUsage pUsage )
215 - {
186 + private void LLprocess( FormMetaData pFMD, FormUsage pUsage ) {
216 187 process( pFMD, pUsage.getLabels() );
217 188 process( pFMD, pUsage.getActions() );
218 189 process( pFMD, pUsage.getAttributes() );
219 190 process( pFMD, pUsage.getRelSubForms() );
220 191 }
221 192
222 - protected void process( FormMetaData pFMD, FormUsage[] pRelSubFormUsages )
223 - {
224 - for ( FormUsage usage : pRelSubFormUsages )
225 - {
193 + protected void process( FormMetaData pFMD, FormUsage[] pRelSubFormUsages ) {
194 + for ( FormUsage usage : pRelSubFormUsages ) {
226 195 String zRelAttributeRef = usage.getRelAttributeRef();
227 196 String zRelRootType = determineRelSubFormRootType( zRelAttributeRef );
228 197 TypeHelper typeHelper = mBackDoor.createTypeHelper( mBackDoor, mExternalization, mAccessControl,
  @@ -230,12 +199,9 @@
230 199 mBackDoor.add( typeHelper );
231 200 pFMD.addRelSubForm( typeHelper.initializeAndCreateFormMetaData( usage ) );
232 201 TypeHelper[] zTypeHelpers = mRelSubFormRefToTypes.get( zRelAttributeRef );
233 - if ( zTypeHelpers == null )
234 - {
202 + if ( zTypeHelpers == null ) {
235 203 zTypeHelpers = new TypeHelper[]{typeHelper};
236 - }
237 - else
238 - {
204 + } else {
239 205 TypeHelper[] newHelpers = new TypeHelper[zTypeHelpers.length + 1];
240 206 System.arraycopy( zTypeHelpers, 0, newHelpers, 0, zTypeHelpers.length );
241 207 newHelpers[zTypeHelpers.length] = typeHelper;
  @@ -247,19 +213,15 @@
247 213
248 214 abstract protected String determineRelSubFormRootType( String pRelAttributeRef );
249 215
250 - protected void process( FormMetaData pFMD, LabelUsage[] pUsages )
251 - {
252 - for ( LabelUsage usage : pUsages )
253 - {
216 + protected void process( FormMetaData pFMD, LabelUsage[] pUsages ) {
217 + for ( LabelUsage usage : pUsages ) {
254 218 String zLabelID = usage.getLabelID();
255 219 pFMD.addLabel( new LabelMetaData( usage, resolveLabel( zLabelID ) ) );
256 220 }
257 221 }
258 222
259 - protected void process( FormMetaData pFMD, ActionUsage[] pUsages )
260 - {
261 - for ( ActionUsage usage : pUsages )
262 - {
223 + protected void process( FormMetaData pFMD, ActionUsage[] pUsages ) {
224 + for ( ActionUsage usage : pUsages ) {
263 225 String zExtLabelID = usage.getExtLabelID();
264 226 ActionMetaData actionMetaData = new ActionMetaData( usage, //
265 227 !allowAction( usage.getActionID() ), //
  @@ -268,18 +230,15 @@
268 230 mActions.add( actionMetaData );
269 231 pFMD.addAction( actionMetaData );
270 232 }
271 - if ( !mBaseForm )
272 - {
233 + if ( !mBaseForm ) {
273 234 addSubFormManagementImageAction( pFMD, "AddRow", "AddNew" );
274 235 addSubFormManagementImageAction( pFMD, "RemoveRow", "RemoveThis" );
275 236 }
276 237 }
277 238
278 - private void addSubFormManagementImageAction( FormMetaData pFMD, String pActionID, String pWhat )
279 - {
239 + private void addSubFormManagementImageAction( FormMetaData pFMD, String pActionID, String pWhat ) {
280 240 String zTooltip = resolveActionTooltip( pActionID );
281 - if ( Strings.isNullOrEmpty( zTooltip ) )
282 - {
241 + if ( Strings.isNullOrEmpty( zTooltip ) ) {
283 242 zTooltip = resolveLabel( pWhat + cleanUpRelativeTypeForToolTip( mRelativeType ) );
284 243 }
285 244 pFMD.addAction( new ActionMetaData( pActionID, !allowAction( pActionID ), //
  @@ -287,50 +246,40 @@
287 246 zTooltip ) );
288 247 }
289 248
290 - protected String cleanUpRelativeTypeForToolTip( String pRelativeType )
291 - {
249 + protected String cleanUpRelativeTypeForToolTip( String pRelativeType ) {
292 250 return pRelativeType;
293 251 }
294 252
295 - protected boolean allowAction( String pActionID )
296 - {
253 + protected boolean allowAction( String pActionID ) {
297 254 return mAccessControl.allowAction( pActionID );
298 255 }
299 256
300 - protected String resolveAction( String pActionID )
301 - {
257 + protected String resolveAction( String pActionID ) {
302 258 return mExternalization.resolveAction( pActionID );
303 259 }
304 260
305 - protected String resolveActionTooltip( String pActionID )
306 - {
261 + protected String resolveActionTooltip( String pActionID ) {
307 262 return mExternalization.resolveActionTooltip( pActionID );
308 263 }
309 264
310 - public String resolveLabel( String pLabelID )
311 - {
265 + public String resolveLabel( String pLabelID ) {
312 266 return mExternalization.resolveLabel( pLabelID );
313 267 }
314 268
315 - protected void process( FormMetaData pFMD, AttributeUsage[] pUsages )
316 - {
317 - for ( AttributeUsage usage : pUsages )
318 - {
269 + protected void process( FormMetaData pFMD, AttributeUsage[] pUsages ) {
270 + for ( AttributeUsage usage : pUsages ) {
319 271 process( pFMD, usage, usage.getAttributeReference() );
320 272 }
321 273 }
322 274
323 - protected void process( FormMetaData pFMD, AttributeUsage pUsage, String pReference )
324 - {
275 + protected void process( FormMetaData pFMD, AttributeUsage pUsage, String pReference ) {
325 276 DottedReference.Parts parts = DottedReference.parse( pReference );
326 277 String localReference = parts.getLocalReference();
327 - if ( !validAttributeReference( localReference ) )
328 - {
278 + if ( !validAttributeReference( localReference ) ) {
329 279 throw new IllegalArgumentException(
330 280 this + " does Not Support an Attribute reference of: '" + localReference + "'" );
331 281 }
332 - if ( parts.getRestOfReference() != null )
333 - {
282 + if ( parts.getRestOfReference() != null ) {
334 283 throw new IllegalArgumentException(
335 284 this + " does Not Support dotted references yet like: '" + pReference + "'" );
336 285 }
  @@ -343,8 +292,7 @@
343 292 pFMD.addAttribute( zAMDcvtr.getAttributeMetaData() );
344 293 }
345 294
346 - protected FormAccessControl.Field allowAttribute( String pAttributeLocalReference )
347 - {
295 + protected FormAccessControl.Field allowAttribute( String pAttributeLocalReference ) {
348 296 return mAccessControl.getFieldControl( pAttributeLocalReference );
349 297 }
350 298
  @@ -353,8 +301,7 @@
353 301 abstract protected AMDconverterPair createAttributeMetaData( CreateAMDParams pParams );
354 302
355 303 protected AMDconverterPair createInvalidAttributeRef( CreateAMDParams pParams, String pLabelSuffix,
356 - String pTooltip )
357 - {
304 + String pTooltip ) {
358 305 return createAttributeMetaData( new BadAttributeParamsPlus( pParams, pLabelSuffix, pTooltip ), //
359 306 null, false, // options
360 307 String.class ); // type
  @@ -364,11 +311,9 @@
364 311 // !Global & Not from Usage
365 312 Object[] pValidOptions, //
366 313 boolean pAssumeValidOptions, //
367 - Class pFieldType )
368 - {
314 + Class pFieldType ) {
369 315 FormAttributeMetaDataFactory zAMDFactory = mAMDFactoriesByFieldType.get( pFieldType );
370 - if ( (zAMDFactory == null) && !pFieldType.isEnum() )
371 - {
316 + if ( (zAMDFactory == null) && !pFieldType.isEnum() ) {
372 317 return new AMDconverterPair( SendableUnknownDataTypeConverter.INSTANCE,
373 318 new UnknownDataTypeMetaData( pParams.getUsage() ) );
374 319 }
  @@ -383,30 +328,25 @@
383 328 Object[] pValidOptions, //
384 329 boolean pAssumeValidOptions, //
385 330 FormAttributeMetaDataFactory pAMDFactory, //
386 - FormSendableDataConverter pDataConverter )
387 - {
331 + FormSendableDataConverter pDataConverter ) {
388 332 IntendedUse zIntendedUse = pParams.getUsage().getIntendedUse();
389 - if ( zIntendedUse.isJustData() )
390 - {
333 + if ( zIntendedUse.isJustData() ) {
391 334 FormSendableDataConverter zFormSendableDataConverter = pParams.isHide() ?
392 335 SendableHideDataStringConverter.INSTANCE :
393 336 SendableStringConverter.INSTANCE;
394 337 return new AMDconverterPair( zFormSendableDataConverter, //
395 338 new ViewAsStringMetaData( pParams.getUsage() ) );
396 339 }
397 - if ( pParams.isHide() )
398 - {
340 + if ( pParams.isHide() ) {
399 341 return PasswordFieldFormAMD.INSTANCE.create( pParams );
400 342 }
401 343 String zFormHint = pParams.getHintValue( COMPONENT_FORM );
402 - if ( CF_TEXT_FIELD.equals( zFormHint ) || CF_TEXT_FIELD_RIGHT_ALIGNED.equals( zFormHint ) )
403 - {
344 + if ( CF_TEXT_FIELD.equals( zFormHint ) || CF_TEXT_FIELD_RIGHT_ALIGNED.equals( zFormHint ) ) {
404 345 return TextFieldFormAMD.INSTANCE.create( pParams );
405 346 }
406 347 String[] zHintedValidOptions = parseHintValidOptions( pParams.getHintValue( VALID_OPTIONS ) );
407 348 if ( pAssumeValidOptions || //
408 - Objects.isNotNullOrEmpty( pValidOptions ) || Objects.isNotNullOrEmpty( zHintedValidOptions ) )
409 - {
349 + Objects.isNotNullOrEmpty( pValidOptions ) || Objects.isNotNullOrEmpty( zHintedValidOptions ) ) {
410 350 AbstractSendableKeyValuePairConverter converter = //
411 351 (pDataConverter instanceof AbstractSendableKeyValuePairConverter) ? //
412 352 (AbstractSendableKeyValuePairConverter) pDataConverter :
  @@ -414,11 +354,9 @@
414 354 SimpleKeyValuePair[] zMDoptions =
415 355 converter.createValidOptions( pValidOptions, zHintedValidOptions );
416 356
417 - if ( pParams.getUsage() instanceof InputImageAttributeUsage )
418 - {
357 + if ( pParams.getUsage() instanceof InputImageAttributeUsage ) {
419 358 AttributeMetaData zMetaData;
420 - if ( Objects.isNullOrEmpty( zMDoptions ) )
421 - {
359 + if ( Objects.isNullOrEmpty( zMDoptions ) ) {
422 360 zMetaData = new InputImageMetaData( pParams.getUsage(), //
423 361 pParams.isDisabled(), //
424 362 pParams.getHints(), //
  @@ -426,9 +364,7 @@
426 364 pParams.getFieldTooltip(), //
427 365 pParams.isRequired(), //
428 366 pParams.getErrorTextForRequired() );
429 - }
430 - else
431 - {
367 + } else {
432 368 zMetaData = new InputImageValidOptionsAttributeMetaData( pParams.getUsage(), //
433 369 pParams.isDisabled(), //
434 370 pParams.getFieldLabel(), //
  @@ -440,31 +376,26 @@
440 376 }
441 377 return new AMDconverterPair( converter, zMetaData );
442 378 }
443 - if ( pParams.isEditRequired() && CF_RADIO_GROUP.equals( zFormHint ) )
444 - {
379 + if ( pParams.isEditRequired() && CF_RADIO_GROUP.equals( zFormHint ) ) {
445 380 return RadioGroupFormAMD.INSTANCE.create( pParams, converter, zMDoptions );
446 381 }
447 382 return ComboBoxFormAMD.INSTANCE.create( pParams, converter, zMDoptions );
448 383 }
449 - if ( pAMDFactory == null )
450 - {
384 + if ( pAMDFactory == null ) {
451 385 throw new IllegalStateException( "No Factory & No ValidOptions?" );
452 386 }
453 387 return pAMDFactory.createAttributeMetaData( pParams );
454 388 }
455 389
456 - protected String[] parseHintValidOptions( String pHintValue )
457 - {
390 + protected String[] parseHintValidOptions( String pHintValue ) {
458 391 return Strings.parseOptions( pHintValue );
459 392 }
460 393
461 - public void removeInstanceHelper( String pRowKey )
462 - {
394 + public void removeInstanceHelper( String pRowKey ) {
463 395 mBackDoor.removeInstanceHelper( new FormDataRowKey( getFormUniqueID(), pRowKey ) );
464 396 }
465 397
466 - public InstanceHelper createRelSubInstanceHelper( InstanceHelper pParent, String pRowKey )
467 - {
398 + public InstanceHelper createRelSubInstanceHelper( InstanceHelper pParent, String pRowKey ) {
468 399 InstanceHelper rv = LLcreateRelSubInstanceHelper( pParent, pRowKey );
469 400 mBackDoor.add( rv );
470 401 return rv;
  @@ -473,18 +404,15 @@
473 404 abstract protected InstanceHelper LLcreateRelSubInstanceHelper( InstanceHelper pParent, String pRowKey );
474 405
475 406 public AttributeResourceOptionsResponseData getResourceOptions( String pAttributeReference,
476 - FormSendableDataConverter pDataConverter )
477 - {
407 + FormSendableDataConverter pDataConverter ) {
478 408 return new AttributeResourceOptionsResponseData( ResourceOptionsErrorType.ErrorNotImplemented );
479 409 }
480 410
481 - private static class BadAttributeParamsPlus extends CreateAMDParamsPlus
482 - {
411 + private static class BadAttributeParamsPlus extends CreateAMDParamsPlus {
483 412 private String mLabelSuffix;
484 413 private String mTooltip;
485 414
486 - public BadAttributeParamsPlus( CreateAMDParams pParams, String pLabelSuffix, String pTooltip )
487 - {
415 + public BadAttributeParamsPlus( CreateAMDParams pParams, String pLabelSuffix, String pTooltip ) {
488 416 super( pParams, null, // HintManager
489 417 false, // Required
490 418 true, // Disabled
  @@ -496,13 +424,11 @@
496 424 mTooltip = pTooltip;
497 425 }
498 426
499 - public String getFieldLabel()
500 - {
427 + public String getFieldLabel() {
501 428 return super.getFieldLabel() + mLabelSuffix;
502 429 }
503 430
504 - public String getFieldTooltip()
505 - {
431 + public String getFieldTooltip() {
506 432 return mTooltip;
507 433 }
508 434 }
  @@ -510,13 +436,11 @@
510 436 private static final Map<Class, FormAttributeMetaDataFactory> mAMDFactoriesByFieldType =
511 437 new HashMap<Class, FormAttributeMetaDataFactory>();
512 438
513 - private static void add( Class pClass, FormAttributeMetaDataFactory pFactory )
514 - {
439 + private static void add( Class pClass, FormAttributeMetaDataFactory pFactory ) {
515 440 mAMDFactoriesByFieldType.put( pClass, pFactory );
516 441 }
517 442
518 - static
519 - {
443 + static {
520 444 add( String.class, FormAMDFactory_String.INSTANCE );
521 445
522 446 add( FloatingPointLong.class, FormAMDFactory_SimpleFloatingPointLong.INSTANCE );