001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.models.modelassistant.metabossmodel.implicitselectors;
016:
017: import java.util.ArrayList;
018: import java.util.Collection;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import javax.jmi.reflect.ConstraintViolationException;
023: import javax.jmi.reflect.RefObject;
024:
025: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
026: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorCardinalityEnum;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputField;
032:
033: /** This class containse helper methods dealing with the Domain Support Servicemodule model element */
034: class TargetEnumerableAttributeSelectorHelper {
035: private ModelAssistantImpl mModelAssistantImpl;
036:
037: TargetEnumerableAttributeSelectorHelper(
038: ModelAssistantImpl pModelAssistantImpl) {
039: mModelAssistantImpl = pModelAssistantImpl;
040:
041: // Add Entity pluralName attribute change listener
042: mModelAssistantImpl
043: .addAttributeChangeListener(
044: Entity.class,
045: "pluralName",
046: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
047: public void onAttributeBeingUpdated(
048: RefObject pModelElementBeingUpdated,
049: String pAttributeName,
050: Object pOldValue, Object pNewValue) {
051: Entity lEntity = (Entity) pModelElementBeingUpdated;
052: HelperContext lHelperContext = new HelperContext(
053: lEntity);
054: TypeTemplate lEnumerableTypeTemplate = lHelperContext
055: .getEnumerableValueFieldTypeTemplate();
056: if (lEnumerableTypeTemplate == null)
057: return; // Context not bound
058: String lOldEntityPluralName = (String) pOldValue;
059: String lNewEntityPluralName = (String) pNewValue;
060: for (Iterator lAttributesIterator = lEntity
061: .getAttributes().iterator(); lAttributesIterator
062: .hasNext();) {
063: Attribute lAttribute = (Attribute) lAttributesIterator;
064: String lAttributeName = lAttribute
065: .getName();
066: if (lAttributeName == null)
067: continue;
068: DataType lAttributeType = lAttribute
069: .getDataType();
070: if (lAttributeType == null) {
071: // Datatype of attribute is unknown - ensure that the selector is absent
072: if (lOldEntityPluralName != null)
073: ensureAbsent(
074: lEntity,
075: lOldEntityPluralName,
076: lAttributeName);
077: if (lNewEntityPluralName != null)
078: ensureAbsent(
079: lEntity,
080: lNewEntityPluralName,
081: lAttributeName);
082: } else {
083: TypeTemplate lTypeTemplate = lAttributeType
084: .getTypetemplate();
085: if (lTypeTemplate == null
086: || lEnumerableTypeTemplate
087: .equals(lTypeTemplate) == false) {
088: // Template is not enumerable template ensure that the selector is absent
089: if (lOldEntityPluralName != null)
090: ensureAbsent(
091: lEntity,
092: lOldEntityPluralName,
093: lAttributeName);
094: if (lNewEntityPluralName != null)
095: ensureAbsent(
096: lEntity,
097: lNewEntityPluralName,
098: lAttributeName);
099: } else {
100: if (lNewEntityPluralName == null) {
101: // Only old value is known - ensure that the element is deleted
102: if (lOldEntityPluralName != null)
103: ensureAbsent(
104: lEntity,
105: lOldEntityPluralName,
106: lAttributeName);
107: } else {
108: // New value is known
109: if (lOldEntityPluralName != null)
110: ensureRenamedPresent(
111: lEntity,
112: lOldEntityPluralName,
113: lNewEntityPluralName,
114: lAttributeType,
115: lAttributeName,
116: lAttributeName);
117: else
118: ensurePresent(
119: lEntity,
120: lNewEntityPluralName,
121: lAttributeType,
122: lAttributeName);
123: }
124: }
125: }
126: }
127: }
128: });
129:
130: // Add Attribute Name attribute change listener
131: mModelAssistantImpl
132: .addAttributeChangeListener(
133: Attribute.class,
134: "Name",
135: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
136: public void onAttributeBeingUpdated(
137: RefObject pModelElementBeingUpdated,
138: String pAttributeName,
139: Object pOldValue, Object pNewValue) {
140: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
141: Entity lEntity = lAttribute.getEntity();
142: if (lEntity == null)
143: return; // Attribute is not associated with entity
144: String lEntityPluralName = lEntity
145: .getPluralName();
146: if (lEntityPluralName == null)
147: return; // Plural name is not defined yet
148: String lOldAttributeName = (String) pOldValue;
149: String lNewAttributeName = (String) pNewValue;
150:
151: HelperContext lHelperContext = new HelperContext(
152: lEntity);
153: DataType lAttributeType = lAttribute
154: .getDataType();
155: if (lAttributeType == null) {
156: // Datatype of attribute is unknown - ensure that the selector is absent
157: if (lOldAttributeName != null)
158: ensureAbsent(lEntity,
159: lEntityPluralName,
160: lOldAttributeName);
161: if (lNewAttributeName != null)
162: ensureAbsent(lEntity,
163: lEntityPluralName,
164: lNewAttributeName);
165: } else {
166: TypeTemplate lEnumerableTypeTemplate = lHelperContext
167: .getEnumerableValueFieldTypeTemplate();
168: if (lEnumerableTypeTemplate == null)
169: return; // Context not bound
170: TypeTemplate lTypeTemplate = lAttributeType
171: .getTypetemplate();
172: if (lTypeTemplate == null
173: || lEnumerableTypeTemplate
174: .equals(lTypeTemplate) == false) {
175: // Template is not enumerable template ensure that the selector is absent
176: if (lOldAttributeName != null)
177: ensureAbsent(lEntity,
178: lEntityPluralName,
179: lOldAttributeName);
180: if (lNewAttributeName != null)
181: ensureAbsent(lEntity,
182: lEntityPluralName,
183: lNewAttributeName);
184: } else {
185: if (lNewAttributeName == null) {
186: // Only old value is known - ensure that the element is deleted
187: if (lOldAttributeName != null)
188: ensureAbsent(
189: lEntity,
190: lEntityPluralName,
191: lOldAttributeName);
192: } else {
193: // New value is known
194: if (lOldAttributeName != null)
195: ensureRenamedPresent(
196: lEntity,
197: lEntityPluralName,
198: lEntityPluralName,
199: lAttributeType,
200: lOldAttributeName,
201: lNewAttributeName);
202: else
203: ensurePresent(
204: lEntity,
205: lEntityPluralName,
206: lAttributeType,
207: lNewAttributeName);
208: }
209: }
210: }
211: }
212: });
213: // Add Attribute dataType reference change listener
214: mModelAssistantImpl
215: .addReferenceChangeListener(
216: Attribute.class,
217: "dataType",
218: new ModelAssistantImpl.ModelElementReferenceChangeListener() {
219: public void onReferenceBeingUpdated(
220: RefObject pModelElementBeingUpdated,
221: String pReferenceName,
222: RefObject pReferencedModelElementToRemove,
223: RefObject pReferencedModelElementToAdd) {
224: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
225: String lAttributeName = lAttribute
226: .getName();
227: if (lAttributeName == null)
228: return; // Attribute does not have a name
229: Entity lEntity = lAttribute.getEntity();
230: if (lEntity == null)
231: return; // Attribute is not associated with entity
232: String lEntityPluralName = lEntity
233: .getPluralName();
234: if (lEntityPluralName == null)
235: return; // Plural name is not defined yet
236: // We are only interested in the future DataType
237: // if it is not given - just remove the selectors
238: if (pReferencedModelElementToAdd != null) {
239: DataType lDataTypeToAdd = (DataType) pReferencedModelElementToAdd;
240: HelperContext lHelperContext = new HelperContext(
241: lEntity);
242: TypeTemplate lEnumerableTypeTemplate = lHelperContext
243: .getEnumerableValueFieldTypeTemplate();
244: if (lEnumerableTypeTemplate == null)
245: return; // Context not bound
246: TypeTemplate lTypeTemplate = lDataTypeToAdd
247: .getTypetemplate();
248: if (lTypeTemplate != null
249: && lEnumerableTypeTemplate
250: .equals(lTypeTemplate))
251: ensurePresent(lEntity,
252: lEntityPluralName,
253: lDataTypeToAdd,
254: lAttributeName);
255: else
256: ensureAbsent(lEntity,
257: lEntityPluralName,
258: lAttributeName);
259: } else
260: ensureAbsent(lEntity,
261: lEntityPluralName,
262: lAttributeName);
263: }
264: });
265: // Add Attribute entity reference change listener
266: mModelAssistantImpl
267: .addReferenceChangeListener(
268: Attribute.class,
269: "entity",
270: new ModelAssistantImpl.ModelElementReferenceChangeListener() {
271: public void onReferenceBeingUpdated(
272: RefObject pModelElementBeingUpdated,
273: String pReferenceName,
274: RefObject pReferencedModelElementToRemove,
275: RefObject pReferencedModelElementToAdd) {
276: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
277: DataType lAttributeType = lAttribute
278: .getDataType();
279: if (lAttributeType == null)
280: return; // Attribute does not have type
281: String lAttributeName = lAttribute
282: .getName();
283: if (lAttributeName == null)
284: return; // Attribute does not have a name
285: // Ensure that the selector is absent for the entity this attribute is being removed from
286: if (pReferencedModelElementToRemove != null) {
287: Entity lEntity = (Entity) pReferencedModelElementToRemove;
288: String lEntityPluralName = lEntity
289: .getPluralName();
290: if (lEntityPluralName != null)
291: ensureAbsent(lEntity,
292: lEntityPluralName,
293: lAttributeName);
294: }
295: // Ensure that the selector is absent or present for the entity this attribute is being added to
296: if (pReferencedModelElementToAdd != null) {
297: Entity lEntity = (Entity) pReferencedModelElementToAdd;
298: String lEntityPluralName = lEntity
299: .getPluralName();
300: if (lEntityPluralName == null)
301: return; // Plural name is not defined yet
302: HelperContext lHelperContext = new HelperContext(
303: lEntity);
304: TypeTemplate lEnumerableTypeTemplate = lHelperContext
305: .getEnumerableValueFieldTypeTemplate();
306: if (lEnumerableTypeTemplate == null)
307: return; // Context not bound
308: TypeTemplate lTypeTemplate = lAttributeType
309: .getTypetemplate();
310: if (lTypeTemplate != null
311: && lEnumerableTypeTemplate
312: .equals(lTypeTemplate))
313: ensurePresent(lEntity,
314: lEntityPluralName,
315: lAttributeType,
316: lAttributeName);
317: else
318: ensureAbsent(lEntity,
319: lEntityPluralName,
320: lAttributeName);
321: }
322: }
323: });
324:
325: // Add DataType typetemplate reference change listener
326: mModelAssistantImpl
327: .addReferenceChangeListener(
328: DataType.class,
329: "typetemplate",
330: new ModelAssistantImpl.ModelElementReferenceChangeListener() {
331: public void onReferenceBeingUpdated(
332: RefObject pModelElementBeingUpdated,
333: String pReferenceName,
334: RefObject pReferencedModelElementToRemove,
335: RefObject pReferencedModelElementToAdd) {
336: DataType lDataType = (DataType) pModelElementBeingUpdated;
337: TypeTemplate lEnumerableTypeTemplate = null;
338: for (Iterator lAttributesIterator = lDataType
339: .getEntityAttributesOfType()
340: .iterator(); lAttributesIterator
341: .hasNext();) {
342: Attribute lAttribute = (Attribute) lAttributesIterator
343: .next();
344: String lAttributeName = lAttribute
345: .getName();
346: if (lAttributeName == null)
347: continue; // Attribute does not have a name
348: Entity lEntity = lAttribute
349: .getEntity();
350: if (lEntity == null)
351: continue; // Attribute is not bound to the entity yet
352: String lEntityPluralName = lEntity
353: .getPluralName();
354: if (lEntityPluralName == null)
355: continue; // Plural name is not defined yet
356: // Obtain the enumerable typetemplate first time around
357: if (lEnumerableTypeTemplate == null) {
358: HelperContext lHelperContext = new HelperContext(
359: lEntity);
360: if ((lEnumerableTypeTemplate = lHelperContext
361: .getEnumerableValueFieldTypeTemplate()) == null)
362: continue; // Context not bound
363: }
364: TypeTemplate lNewTypeTemplate = (TypeTemplate) pReferencedModelElementToAdd;
365: if (lNewTypeTemplate != null
366: && lNewTypeTemplate
367: .equals(lEnumerableTypeTemplate))
368: ensurePresent(lEntity,
369: lEntityPluralName,
370: lDataType,
371: lAttributeName);
372: else
373: ensureAbsent(lEntity,
374: lEntityPluralName,
375: lAttributeName);
376: }
377: }
378: });
379: }
380:
381: // This helper verifies constraints
382: void verifyConstraints(Collection pViolations, Entity pEntity,
383: Collection pUnclaimedSelectors) {
384: HelperContext pHelperContext = new HelperContext(pEntity);
385: TypeTemplate lEnumerableTypeTemplate = pHelperContext
386: .getEnumerableValueFieldTypeTemplate();
387: if (lEnumerableTypeTemplate == null)
388: return; // Context not bound
389: for (Iterator lAttributesIterator = pEntity.getAttributes()
390: .iterator(); lAttributesIterator.hasNext();) {
391: Attribute lAttribute = (Attribute) lAttributesIterator
392: .next();
393: DataType lAttributeType = lAttribute.getDataType();
394: if (lAttributeType == null)
395: continue;
396: TypeTemplate lTypetemplate = lAttributeType
397: .getTypetemplate();
398: // TODO: Review how decision is made to generate selector or not. At the moment it is based on the particular template
399: if (lTypetemplate != null
400: && lTypetemplate.equals(lEnumerableTypeTemplate)) {
401: // Work on single value selector
402: String lExpectedEnumerableAttributeSingleValueSelectorName = StylesheetImpl
403: .getEnumerableAttributeSingleValueSelectorName(
404: pEntity.getPluralName(), lAttribute
405: .getName());
406: Selector lEnumerableAttributeSingleValueSelector = pEntity
407: .findSelector(lExpectedEnumerableAttributeSingleValueSelectorName);
408: if (lEnumerableAttributeSingleValueSelector != null) {
409: // Remove this selector from the list of unprocessed ones
410: if (pUnclaimedSelectors != null)
411: pUnclaimedSelectors
412: .remove(lEnumerableAttributeSingleValueSelector);
413: } else
414: pViolations
415: .add(new ConstraintViolationException(
416: pEntity,
417: pEntity.refMetaObject(),
418: "The Entity must have the Single Value Selector for each Attribute with Enumerable data type. Missing '"
419: + lExpectedEnumerableAttributeSingleValueSelectorName
420: + "' selector."));
421:
422: // Work on plural value selector
423: String lExpectedEnumerableAttributePluralValueSelectorName = StylesheetImpl
424: .getEnumerableAttributePluralValueSelectorName(
425: pEntity.getPluralName(), lAttribute
426: .getName());
427: Selector lEnumerableAttributePluralValueSelector = pEntity
428: .findSelector(lExpectedEnumerableAttributePluralValueSelectorName);
429: if (lEnumerableAttributePluralValueSelector != null) {
430: // Remove this selector from the list of unprocessed ones
431: if (pUnclaimedSelectors != null)
432: pUnclaimedSelectors
433: .remove(lEnumerableAttributePluralValueSelector);
434: } else
435: pViolations
436: .add(new ConstraintViolationException(
437: pEntity,
438: pEntity.refMetaObject(),
439: "The Entity must have the Plural Value Selector for each Attribute with Enumerable data type. Missing '"
440: + lExpectedEnumerableAttributePluralValueSelectorName
441: + "' selector."));
442: }
443: }
444: }
445:
446: // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
447: void rectifyModel(Entity pEntity, Collection pUnclaimedSelectors) {
448: String lEntityPluralName = pEntity.getPluralName();
449: if (lEntityPluralName == null)
450: return; // Will not be able to do anything
451: HelperContext lHelperContext = new HelperContext(pEntity);
452: TypeTemplate lEnumerableTypeTemplate = lHelperContext
453: .getEnumerableValueFieldTypeTemplate();
454: if (lEnumerableTypeTemplate == null)
455: return; // Context not bound
456: for (Iterator lAttributesIterator = pEntity.getAttributes()
457: .iterator(); lAttributesIterator.hasNext();) {
458: Attribute lAttribute = (Attribute) lAttributesIterator
459: .next();
460: DataType lAttributeDataType = lAttribute.getDataType();
461: if (lAttributeDataType == null)
462: continue;
463: String lAttributeName = lAttribute.getName();
464: if (lAttributeName == null)
465: continue;
466: // Claim selectors which we are managing
467: String lSingleValueSelectorName = StylesheetImpl
468: .getEnumerableAttributeSingleValueSelectorName(
469: lEntityPluralName, lAttributeName);
470: Selector lSingleValueSelector = pEntity
471: .findSelector(lSingleValueSelectorName);
472: if (lSingleValueSelector != null)
473: pUnclaimedSelectors.remove(lSingleValueSelector);
474:
475: String lPluralValueSelectorName = StylesheetImpl
476: .getEnumerableAttributePluralValueSelectorName(
477: lEntityPluralName, lAttributeName);
478: Selector lPluralValueSelector = pEntity
479: .findSelector(lPluralValueSelectorName);
480: if (lPluralValueSelector != null)
481: pUnclaimedSelectors.remove(lPluralValueSelector);
482:
483: TypeTemplate lTypeTemplate = lAttributeDataType
484: .getTypetemplate();
485: if (lTypeTemplate == null
486: || lEnumerableTypeTemplate.equals(lTypeTemplate) == false)
487: ensureAbsent(pEntity, lEntityPluralName, lAttributeName);
488: else
489: ensurePresent(pEntity, lEntityPluralName,
490: lAttributeDataType, lAttributeName);
491: }
492: }
493:
494: // This helper renames and ensures that the element is present
495: void ensureRenamedPresent(Entity pEntity,
496: String pOldEntityPluralName, String pNewEntityPluralName,
497: DataType pAttributeDataType, String pOldAttributeName,
498: String pNewAttributeName) {
499: // Note that this method only deals with renaming and than calls the ensure present method
500:
501: // Work on single value selector attribute
502: String lOldSingleValueSelectorName = StylesheetImpl
503: .getEnumerableAttributeSingleValueSelectorName(
504: pOldEntityPluralName, pOldAttributeName);
505: Selector lOldSingleValueSelector = pEntity
506: .findSelector(lOldSingleValueSelectorName);
507: String lNewSingleValueSelectorName = StylesheetImpl
508: .getEnumerableAttributeSingleValueSelectorName(
509: pNewEntityPluralName, pNewAttributeName);
510: Selector lNewSingleValueSelector = pEntity
511: .findSelector(lNewSingleValueSelectorName);
512: // Be relaxed here - allow for all sorts of mishaps
513: if (lOldSingleValueSelector != null) {
514: if (lNewSingleValueSelector != null) {
515: // New and old structures are present - just delete the old one
516: lOldSingleValueSelector.refDelete();
517: } else {
518: // Old structure is present - new one is not - rename
519: lOldSingleValueSelector
520: .setName(lNewSingleValueSelectorName);
521: }
522: }
523:
524: // Work on plural value selector attribute
525: String lOldPluralValueSelectorName = StylesheetImpl
526: .getEnumerableAttributePluralValueSelectorName(
527: pOldEntityPluralName, pOldAttributeName);
528: Selector lOldPluralValueSelector = pEntity
529: .findSelector(lOldPluralValueSelectorName);
530: String lNewPluralValueSelectorName = StylesheetImpl
531: .getEnumerableAttributePluralValueSelectorName(
532: pNewEntityPluralName, pNewAttributeName);
533: Selector lNewPluralValueSelector = pEntity
534: .findSelector(lNewPluralValueSelectorName);
535: // Be relaxed here - allow for all sorts of mishaps
536: if (lOldPluralValueSelector != null) {
537: if (lNewPluralValueSelector != null) {
538: // New and old structures are present - just delete the old one
539: lOldPluralValueSelector.refDelete();
540: } else {
541: // Old structure is present - new one is not - rename
542: lOldPluralValueSelector
543: .setName(lNewPluralValueSelectorName);
544: }
545: }
546: // Call the ensure present bit
547: ensurePresent(pEntity, pNewEntityPluralName,
548: pAttributeDataType, pNewAttributeName);
549: }
550:
551: // This helper ensures that the element is present
552: void ensurePresent(Entity pEntity, String pEntityPluralName,
553: DataType pAttributeDataType, String pAttributeName) {
554: // Work on single value selector attribute
555: String lSingleValueSelectorName = StylesheetImpl
556: .getEnumerableAttributeSingleValueSelectorName(
557: pEntityPluralName, pAttributeName);
558: Selector lSingleValueSelector = pEntity
559: .findSelector(lSingleValueSelectorName);
560: if (lSingleValueSelector == null) {
561: lSingleValueSelector = mModelAssistantImpl.mSelectorClass
562: .createSelector();
563: lSingleValueSelector.setEntity(pEntity);
564: lSingleValueSelector.setName(lSingleValueSelectorName);
565: }
566: lSingleValueSelector.setDescription(StylesheetImpl
567: .getEnumerableAttributeSingleValueSelectorDescription(
568: pEntityPluralName, pAttributeName));
569: lSingleValueSelector.setImplicit(true);
570: lSingleValueSelector
571: .setOwnerIdentifier(ModelAssistantImpl.ASSISTANT_IDENTIFIER);
572: lSingleValueSelector
573: .setCardinality(SelectorCardinalityEnum.ZERO_TO_MANY);
574: lSingleValueSelector
575: .setTextOfSqlSelect("${EntAttribute."
576: + pAttributeName
577: + "} = ${Inputs."
578: + StylesheetImpl
579: .getEnumerableAttributeSingleValueSelectorInputFieldName()
580: + "}");
581: // Work on input fields
582: {
583: Collection lInputFields = lSingleValueSelector
584: .getInputFields();
585: // Keep a list of unprocessed fields to be deleted at the end
586: List lUnprocessedInputFields = new ArrayList();
587: lUnprocessedInputFields.addAll(lInputFields);
588: {
589: String lInputFieldName = StylesheetImpl
590: .getEnumerableAttributeSingleValueSelectorInputFieldName();
591: SelectorInputField lInputField = lSingleValueSelector
592: .findInputField(lInputFieldName);
593: if (lInputField == null) {
594: lInputField = mModelAssistantImpl.mSelectorInputFieldClass
595: .createSelectorInputField();
596: lInputField.setName(lInputFieldName);
597: lInputFields.add(lInputField);
598: } else {
599: // Remove this input field from the list of unprocessed ones, so it is not deleted
600: lUnprocessedInputFields.remove(lInputField);
601: }
602: lInputField
603: .setDescription(StylesheetImpl
604: .getEnumerableAttributeSingleValueSelectorInputFieldDescription());
605: lInputField.setDataType(pAttributeDataType);
606: lInputField.setArray(false);
607: }
608: // Delete all unprocessed input fields
609: for (Iterator lUnprocessedInputFieldsIterator = lUnprocessedInputFields
610: .iterator(); lUnprocessedInputFieldsIterator
611: .hasNext();) {
612: SelectorInputField lInputField = (SelectorInputField) lUnprocessedInputFieldsIterator
613: .next();
614: lInputField.refDelete();
615: }
616: }
617:
618: // Work on plural value selector attribute
619: String lPluralValueSelectorName = StylesheetImpl
620: .getEnumerableAttributePluralValueSelectorName(
621: pEntityPluralName, pAttributeName);
622: Selector lPluralValueSelector = pEntity
623: .findSelector(lPluralValueSelectorName);
624: if (lPluralValueSelector == null) {
625: lPluralValueSelector = mModelAssistantImpl.mSelectorClass
626: .createSelector();
627: lPluralValueSelector.setEntity(pEntity);
628: lPluralValueSelector.setName(lPluralValueSelectorName);
629: }
630: lPluralValueSelector.setDescription(StylesheetImpl
631: .getEnumerableAttributePluralValueSelectorDescription(
632: pEntityPluralName, pAttributeName));
633: lPluralValueSelector.setImplicit(true);
634: lPluralValueSelector
635: .setOwnerIdentifier(ModelAssistantImpl.ASSISTANT_IDENTIFIER);
636: lPluralValueSelector
637: .setCardinality(SelectorCardinalityEnum.ZERO_TO_MANY);
638: lPluralValueSelector
639: .setTextOfSqlSelect("${EntAttribute."
640: + pAttributeName
641: + "} IN (${Inputs."
642: + StylesheetImpl
643: .getEnumerableAttributePluralValueSelectorInputFieldName()
644: + "})");
645: // Work on input fields
646: {
647: Collection lInputFields = lPluralValueSelector
648: .getInputFields();
649: // Keep a list of unprocessed fields to be deleted at the end
650: List lUnprocessedInputFields = new ArrayList();
651: lUnprocessedInputFields.addAll(lInputFields);
652: {
653: String lInputFieldName = StylesheetImpl
654: .getEnumerableAttributePluralValueSelectorInputFieldName();
655: SelectorInputField lInputField = lPluralValueSelector
656: .findInputField(lInputFieldName);
657: if (lInputField == null) {
658: lInputField = mModelAssistantImpl.mSelectorInputFieldClass
659: .createSelectorInputField();
660: lInputField.setName(lInputFieldName);
661: lInputFields.add(lInputField);
662: } else {
663: // Remove this input field from the list of unprocessed ones, so it is not deleted
664: lUnprocessedInputFields.remove(lInputField);
665: }
666: lInputField
667: .setDescription(StylesheetImpl
668: .getEnumerableAttributePluralValueSelectorInputFieldDescription());
669: lInputField.setDataType(pAttributeDataType);
670: lInputField.setArray(true);
671: }
672: // Delete all unprocessed input fields
673: for (Iterator lUnprocessedInputFieldsIterator = lUnprocessedInputFields
674: .iterator(); lUnprocessedInputFieldsIterator
675: .hasNext();) {
676: SelectorInputField lInputField = (SelectorInputField) lUnprocessedInputFieldsIterator
677: .next();
678: lInputField.refDelete();
679: }
680: }
681: }
682:
683: // This helper makes sure that the single and plural value selectors are absent in the details structure
684: void ensureAbsent(Entity pEntity, String pEntityPluralName,
685: String pAttributeName) {
686: // Work on single value selector attribute
687: String lSingleValueSelectorName = StylesheetImpl
688: .getEnumerableAttributeSingleValueSelectorName(
689: pEntityPluralName, pAttributeName);
690: Selector lSingleValueSelector = pEntity
691: .findSelector(lSingleValueSelectorName);
692: if (lSingleValueSelector != null)
693: lSingleValueSelector.refDelete();
694: // Work on plural value selector attribute
695: String lPluralValueSelectorName = StylesheetImpl
696: .getEnumerableAttributePluralValueSelectorName(
697: pEntityPluralName, pAttributeName);
698: Selector lPluralValueSelector = pEntity
699: .findSelector(lPluralValueSelectorName);
700: if (lPluralValueSelector != null)
701: lPluralValueSelector.refDelete();
702: }
703: }
|