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