001: package org.andromda.metafacades.uml14;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006: import java.util.LinkedHashSet;
007:
008: import org.andromda.metafacades.uml.AttributeFacade;
009: import org.andromda.metafacades.uml.ClassifierFacade;
010: import org.andromda.metafacades.uml.EventFacade;
011: import org.andromda.metafacades.uml.FrontEndAction;
012: import org.andromda.metafacades.uml.FrontEndControllerOperation;
013: import org.andromda.metafacades.uml.FrontEndEvent;
014: import org.andromda.metafacades.uml.FrontEndForward;
015: import org.andromda.metafacades.uml.ModelElementFacade;
016: import org.andromda.metafacades.uml.TransitionFacade;
017: import org.andromda.metafacades.uml.UMLProfile;
018: import org.apache.commons.collections.CollectionUtils;
019: import org.apache.commons.collections.Predicate;
020: import org.apache.commons.collections.Transformer;
021: import org.apache.commons.lang.ObjectUtils;
022: import org.apache.commons.lang.StringUtils;
023:
024: /**
025: * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndParameter.
026: *
027: * @see org.andromda.metafacades.uml.FrontEndParameter
028: */
029: public class FrontEndParameterLogicImpl extends FrontEndParameterLogic {
030: public FrontEndParameterLogicImpl(Object metaObject, String context) {
031: super (metaObject, context);
032: }
033:
034: /**
035: * @see org.andromda.metafacades.uml.FrontEndParameter#isControllerOperationArgument()
036: */
037: protected boolean handleIsControllerOperationArgument() {
038: return this .getControllerOperation() != null;
039: }
040:
041: /**
042: * @see org.andromda.metafacades.uml.FrontEndParameter#getControllerOperation()
043: */
044: protected Object handleGetControllerOperation() {
045: return this .getOperation();
046: }
047:
048: /**
049: * @see org.andromda.metafacades.uml.FrontEndParameter#isContainedInFrontEndUseCase()
050: */
051: protected boolean handleIsContainedInFrontEndUseCase() {
052: return this .getEvent() instanceof FrontEndEvent
053: || this .getOperation() instanceof FrontEndControllerOperation;
054: }
055:
056: /**
057: * @see org.andromda.metafacades.uml.FrontEndParameter#getView()
058: */
059: protected Object handleGetView() {
060: Object view = null;
061: final EventFacade event = this .getEvent();
062: if (event != null) {
063: final TransitionFacade transition = event.getTransition();
064: if (transition instanceof FrontEndAction) {
065: final FrontEndAction action = (FrontEndAction) transition;
066: view = action.getInput();
067: } else if (transition instanceof FrontEndForward) {
068: final FrontEndForward forward = (FrontEndForward) transition;
069: if (forward.isEnteringView()) {
070: view = forward.getTarget();
071: }
072: }
073: }
074: return view;
075: }
076:
077: /**
078: * @see org.andromda.metafacades.uml.FrontEndParameter#isActionParameter()
079: */
080: protected boolean handleIsActionParameter() {
081: final FrontEndAction action = this .getAction();
082: return action != null
083: && action.getParameters().contains(this .THIS());
084: }
085:
086: /**
087: * @see org.andromda.metafacades.uml.FrontEndParameter#getAction()
088: */
089: protected Object handleGetAction() {
090: Object actionObject = null;
091: final EventFacade event = this .getEvent();
092: if (event != null) {
093: final TransitionFacade transition = event.getTransition();
094: if (transition instanceof FrontEndAction) {
095: actionObject = transition;
096: }
097: }
098: return actionObject;
099: }
100:
101: /**
102: * @see org.andromda.metafacades.uml.FrontEndParameter#isTable()
103: */
104: protected boolean handleIsTable() {
105: boolean isTable = false;
106: final ClassifierFacade type = this .getType();
107: if (type != null) {
108: isTable = type.isCollectionType() || type.isArrayType();
109: if (isTable) {
110: final String tableTaggedValue = ObjectUtils
111: .toString(this
112: .findTaggedValue(UMLProfile.TAGGEDVALUE_PRESENTATION_IS_TABLE));
113: isTable = StringUtils.isNotBlank(tableTaggedValue) ? Boolean
114: .valueOf(tableTaggedValue.trim())
115: .booleanValue()
116: : true;
117: if (!isTable) {
118: isTable = !this .getTableColumnNames().isEmpty();
119: }
120: }
121: }
122: return isTable;
123: }
124:
125: /**
126: * @see org.andromda.metafacades.uml.FrontEndParameter#getTableColumnNames()
127: */
128: protected Collection handleGetTableColumnNames() {
129: final Collection tableColumnNames = new LinkedHashSet();
130: final Collection taggedValues = this
131: .findTaggedValues(UMLProfile.TAGGEDVALUE_PRESENTATION_TABLE_COLUMNS);
132: if (!taggedValues.isEmpty()) {
133: for (final Iterator iterator = taggedValues.iterator(); iterator
134: .hasNext();) {
135: final String taggedValue = StringUtils
136: .trimToNull(String.valueOf(iterator.next()));
137: if (taggedValue != null) {
138: final String[] properties = taggedValue
139: .split("[,\\s]+");
140: for (int ctr = 0; ctr < properties.length; ctr++) {
141: final String property = properties[ctr];
142: tableColumnNames.add(property);
143: }
144: }
145: }
146: }
147: // - if we have no table column names explicitly defined, use the table attribute names.
148: if (tableColumnNames.isEmpty()) {
149: tableColumnNames.addAll(this .getTableAttributeNames());
150: }
151: return tableColumnNames;
152: }
153:
154: /**
155: * @see org.andromda.metafacades.uml.FrontEndParameter#getTableColumns()
156: */
157: protected Collection handleGetTableColumns() {
158: final Collection tableColumns = new ArrayList(this
159: .getNonArrayAttributes());
160: final Collection tableColumnNames = this .getTableColumnNames();
161: CollectionUtils.filter(tableColumns, new Predicate() {
162: public boolean evaluate(final Object object) {
163: final ModelElementFacade attribute = (ModelElementFacade) object;
164: final String attributeName = attribute.getName();
165: return attributeName != null
166: && tableColumnNames.contains(attributeName);
167: }
168: });
169: return tableColumns;
170: }
171:
172: /**
173: * Gets all attributes for an array type that has a corresponding non-array
174: * type.
175: * @return the collection of attributes.
176: */
177: private Collection getNonArrayAttributes() {
178: final Collection nonArrayAttributes = new ArrayList();
179: final ClassifierFacade type = this .getType();
180: if (type != null && type.isArrayType()) {
181: final ClassifierFacade nonArrayType = type.getNonArray();
182: if (nonArrayType != null) {
183: nonArrayAttributes.addAll(nonArrayType
184: .getAttributes(true));
185: }
186: }
187: return nonArrayAttributes;
188: }
189:
190: /**
191: * @see org.andromda.metafacades.uml.FrontEndParameter#getTableAttributeNames()
192: */
193: protected Collection handleGetTableAttributeNames() {
194: final Collection tableAttributeNames = new ArrayList(this
195: .getNonArrayAttributes());
196: CollectionUtils.transform(tableAttributeNames,
197: new Transformer() {
198: public Object transform(final Object object) {
199: return ((AttributeFacade) object).getName();
200: }
201: });
202: return tableAttributeNames;
203: }
204: }
|