001: package org.andromda.metafacades.uml14;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005:
006: import org.andromda.metafacades.uml.NameMasker;
007: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
008: import org.andromda.metafacades.uml.UMLMetafacadeUtils;
009: import org.andromda.metafacades.uml.UMLProfile;
010: import org.andromda.utils.StringUtilsHelper;
011: import org.apache.commons.lang.StringUtils;
012: import org.omg.uml.behavioralelements.statemachines.Event;
013: import org.omg.uml.foundation.core.Operation;
014: import org.omg.uml.foundation.datatypes.Expression;
015: import org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum;
016:
017: /**
018: * Metaclass facade implementation.
019: */
020: public class ParameterFacadeLogicImpl extends ParameterFacadeLogic {
021: public ParameterFacadeLogicImpl(
022: org.omg.uml.foundation.core.Parameter metaObject,
023: String context) {
024: super (metaObject, context);
025: }
026:
027: /**
028: * Overridden to provide name masking.
029: *
030: * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
031: */
032: protected String handleGetName() {
033: final String nameMask = String
034: .valueOf(this
035: .getConfiguredProperty(UMLMetafacadeProperties.PARAMETER_NAME_MASK));
036: return NameMasker.mask(super .handleGetName(), nameMask);
037: }
038:
039: /**
040: * @see org.andromda.metafacades.uml.ParameterFacade#getGetterName()
041: */
042: protected java.lang.String handleGetGetterName() {
043: return UMLMetafacadeUtils.getGetterPrefix(this .getType())
044: + StringUtilsHelper.capitalize(this .getName());
045: }
046:
047: /**
048: * @see org.andromda.metafacades.uml.ParameterFacade#getSetterName()
049: */
050: protected java.lang.String handleGetSetterName() {
051: return "set" + StringUtilsHelper.capitalize(this .getName());
052: }
053:
054: /**
055: * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
056: */
057: public Object getValidationOwner() {
058: Object owner = this .getOperation();
059:
060: if (owner == null) {
061: owner = this .getEvent();
062: }
063:
064: return owner;
065: }
066:
067: /**
068: * @see org.andromda.metafacades.uml.ParameterFacade#getDefaultValue()
069: */
070: public String handleGetDefaultValue() {
071: final Expression expression = this .metaObject.getDefaultValue();
072: return expression == null ? "" : expression.getBody();
073: }
074:
075: /**
076: * @see org.andromda.metafacades.uml.ParameterFacade#isDefaultValuePresent()
077: */
078: public boolean handleIsDefaultValuePresent() {
079: return StringUtils.isNotBlank(this .getDefaultValue());
080: }
081:
082: /**
083: * @see org.andromda.metafacades.uml.ParameterFacade#getType()
084: */
085: protected Object handleGetType() {
086: return this .metaObject.getType();
087: }
088:
089: /**
090: * @see org.andromda.metafacades.uml.ParameterFacade#isReturn()
091: */
092: public boolean handleIsReturn() {
093: return ParameterDirectionKindEnum.PDK_RETURN
094: .equals(this .metaObject.getKind());
095: }
096:
097: /**
098: * @see org.andromda.metafacades.uml.ParameterFacade#isRequired()
099: */
100: protected boolean handleIsRequired() {
101: return !this .hasStereotype(UMLProfile.STEREOTYPE_NULLABLE);
102: }
103:
104: /**
105: * @see org.andromda.metafacades.uml.ParameterFacade#getOperation()
106: */
107: protected Object handleGetOperation() {
108: Operation parameterOperation = null;
109: final Collection allOperations = UML14MetafacadeUtils
110: .getModel().getCore().getOperation().refAllOfType();
111: for (final Iterator iterator = allOperations.iterator(); iterator
112: .hasNext()
113: && parameterOperation == null;) {
114: final Operation operation = (Operation) iterator.next();
115: if (operation.getParameter().contains(this .metaObject)) {
116: parameterOperation = operation;
117: }
118: }
119: return parameterOperation;
120: }
121:
122: /**
123: * @see org.andromda.metafacades.uml.ParameterFacade#getEvent()
124: */
125: protected Object handleGetEvent() {
126: Event parameterEvent = null;
127: final Collection allEvents = UML14MetafacadeUtils.getModel()
128: .getStateMachines().getEvent().refAllOfType();
129: for (final Iterator iterator = allEvents.iterator(); iterator
130: .hasNext()
131: && parameterEvent == null;) {
132: final Event event = (Event) iterator.next();
133: if (event.getParameter().contains(this .metaObject)) {
134: parameterEvent = event;
135: }
136: }
137: return parameterEvent;
138: }
139:
140: /**
141: * @see org.andromda.metafacades.uml.ParameterFacade#isReadable()
142: */
143: protected boolean handleIsReadable() {
144: return this .isInParameter() || this .isInoutParameter();
145: }
146:
147: /**
148: * @see org.andromda.metafacades.uml.ParameterFacade#isWritable()
149: */
150: protected boolean handleIsWritable() {
151: return this .isOutParameter() || this .isInoutParameter();
152: }
153:
154: /**
155: * @see org.andromda.metafacades.uml.ParameterFacade#isInParameter()
156: */
157: protected boolean handleIsInParameter() {
158: return ParameterDirectionKindEnum.PDK_IN.equals(this .metaObject
159: .getKind());
160: }
161:
162: /**
163: * @see org.andromda.metafacades.uml.ParameterFacade#isOutParameter()
164: */
165: protected boolean handleIsOutParameter() {
166: return ParameterDirectionKindEnum.PDK_OUT
167: .equals(this .metaObject.getKind());
168: }
169:
170: /**
171: * @see org.andromda.metafacades.uml.ParameterFacade#isInoutParameter()
172: */
173: protected boolean handleIsInoutParameter() {
174: return ParameterDirectionKindEnum.PDK_INOUT
175: .equals(this .metaObject.getKind());
176: }
177:
178: /**
179: * Get the UML upper multiplicity
180: * Not implemented for UML1.4
181: */
182: protected int handleGetUpper() {
183: throw new java.lang.UnsupportedOperationException(
184: "'upper' is not a UML1.4 feature");
185: }
186:
187: /**
188: * Get the UML lower multiplicity
189: * Not implemented for UML1.4
190: */
191: protected int handleGetLower() {
192: throw new java.lang.UnsupportedOperationException(
193: "'lower' is not a UML1.4 feature");
194: }
195: }
|