001: package org.andromda.metafacades.emf.uml2;
002:
003: import org.andromda.metafacades.uml.ClassifierFacade;
004: import org.andromda.metafacades.uml.EnumerationFacade;
005: import org.andromda.metafacades.uml.NameMasker;
006: import org.andromda.metafacades.uml.TypeMappings;
007: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
008: import org.andromda.metafacades.uml.UMLMetafacadeUtils;
009: import org.andromda.metafacades.uml.UMLProfile;
010: import org.apache.commons.lang.BooleanUtils;
011: import org.apache.commons.lang.ObjectUtils;
012: import org.apache.commons.lang.StringUtils;
013: import org.eclipse.uml2.MultiplicityElement;
014:
015: /**
016: * MetafacadeLogic implementation for
017: * org.andromda.metafacades.uml.AttributeFacade.
018: *
019: * @see org.andromda.metafacades.uml.AttributeFacade
020: */
021: public class AttributeFacadeLogicImpl extends AttributeFacadeLogic {
022: public AttributeFacadeLogicImpl(final Attribute metaObject,
023: final String context) {
024: super (metaObject, context);
025: }
026:
027: /**
028: * @see org.andromda.metafacades.uml.AttributeFacade#getGetterName()
029: */
030: protected java.lang.String handleGetGetterName() {
031: return UMLMetafacadeUtils.getGetterPrefix(this .getType())
032: + StringUtils.capitalize(this .getName());
033: }
034:
035: /**
036: * @see org.andromda.metafacades.uml.AttributeFacade#getSetterName()
037: */
038: protected java.lang.String handleGetSetterName() {
039: return "set" + StringUtils.capitalize(this .getName());
040: }
041:
042: /**
043: * @see org.andromda.metafacades.uml.AttributeFacade#isReadOnly()
044: */
045: protected boolean handleIsReadOnly() {
046: return this .metaObject.isReadOnly();
047: }
048:
049: /**
050: * @see org.andromda.metafacades.uml.AttributeFacade#getDefaultValue()
051: */
052: protected java.lang.String handleGetDefaultValue() {
053: String defaultValue = this .metaObject.getDefault();
054: return defaultValue.equals("") ? null : defaultValue;
055: }
056:
057: /**
058: * @see org.andromda.metafacades.uml.AttributeFacade#isStatic()
059: */
060: protected boolean handleIsStatic() {
061: return this .metaObject.isStatic();
062: }
063:
064: /**
065: * @see org.andromda.metafacades.uml.AssociationEndFacade#isMany()
066: */
067: protected boolean handleIsMany() {
068: // Because of MD11.5 (their multiplicity are String), we cannot use
069: // isMultiValued()
070: return this .getUpper() > 1
071: || this .getUpper() == MultiplicityElement.UNLIMITED_UPPER_BOUND;
072: }
073:
074: /**
075: * @see org.andromda.metafacades.uml.AssociationEndFacade#isRequired()
076: */
077: protected boolean handleIsRequired() {
078: return this .getLower() > 0;
079: }
080:
081: /**
082: * @see org.andromda.metafacades.uml.AttributeFacade#isChangeable()
083: */
084: protected boolean handleIsChangeable() {
085: return !this .metaObject.isReadOnly();
086: }
087:
088: /**
089: * @see org.andromda.metafacades.uml.AttributeFacade#isAddOnly()
090: */
091: protected boolean handleIsAddOnly() {
092: // TODO: really nothing to do here ?
093: return false;
094: }
095:
096: /**
097: * @see org.andromda.metafacades.uml.AttributeFacade#isEnumerationLiteral()
098: */
099: protected boolean handleIsEnumerationLiteral() {
100: final ClassifierFacade owner = this .getOwner();
101: return (owner != null) && owner.isEnumeration();
102: }
103:
104: /**
105: * @see org.andromda.metafacades.uml.AttributeFacade#getEnumerationValue()
106: */
107: protected String handleGetEnumerationValue() {
108: String value = null;
109: if (this .isEnumerationLiteral()) {
110: value = this .getDefaultValue();
111: value = (value == null) ? this .getName() : String
112: .valueOf(value);
113: }
114: if (this .getType().isStringType()) {
115: value = "\"" + value + "\"";
116: }
117: return value;
118: }
119:
120: /**
121: * @see org.andromda.metafacades.uml.AttributeFacade#handleIsEnumerationMember()
122: */
123: protected boolean handleIsEnumerationMember() {
124: boolean isMemberVariable = false;
125: final String isMemberVariableAsString = (String) this
126: .findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_ENUMERATION_MEMBER_VARIABLE);
127: if (StringUtils.isNotEmpty(isMemberVariableAsString)
128: && BooleanUtils.toBoolean(isMemberVariableAsString)) {
129: isMemberVariable = true;
130: }
131: return isMemberVariable;
132: }
133:
134: /**
135: * @see org.andromda.metafacades.uml.AttributeFacade#handleGetEnumerationLiteralParameters()
136: */
137: protected String handleGetEnumerationLiteralParameters() {
138: return (String) this
139: .findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_ENUMERATION_LITERAL_PARAMETERS);
140: }
141:
142: /**
143: * @see org.andromda.metafacades.uml.AttributeFacade#handleIsEnumerationLiteralParametersExist()
144: */
145: protected boolean handleIsEnumerationLiteralParametersExist() {
146: boolean parametersExist = false;
147: if (StringUtils.isNotBlank(this
148: .getEnumerationLiteralParameters())) {
149: parametersExist = true;
150: }
151: return parametersExist;
152: }
153:
154: /**
155: * @see org.andromda.metafacades.uml.AttributeFacade#getGetterSetterTypeName()
156: */
157: protected java.lang.String handleGetGetterSetterTypeName() {
158: String name = null;
159: if (this .isMany()) {
160: final TypeMappings mappings = this .getLanguageMappings();
161: name = this .isOrdered() ? mappings
162: .getTo(UMLProfile.LIST_TYPE_NAME) : mappings
163: .getTo(UMLProfile.COLLECTION_TYPE_NAME);
164:
165: // set this attribute's type as a template parameter if required
166: if (BooleanUtils
167: .toBoolean(ObjectUtils
168: .toString(this
169: .getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING)))) {
170: name = name + "<"
171: + this .getType().getFullyQualifiedName() + ">";
172: }
173: }
174: if (name == null && this .getType() != null) {
175: name = this .getType().getFullyQualifiedName();
176: }
177: return name;
178: }
179:
180: /**
181: * @see org.andromda.metafacades.uml.AttributeFacade#isOrdered()
182: */
183: protected boolean handleIsOrdered() {
184: return this .metaObject.isOrdered();
185: }
186:
187: /**
188: * @see org.andromda.metafacades.uml.AttributeFacade#getOwner()
189: */
190: protected java.lang.Object handleGetOwner() {
191: // This is sure for attribute
192: return this .metaObject.getClass_();
193: }
194:
195: /**
196: * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
197: */
198: public Object getValidationOwner() {
199: return this .getOwner();
200: }
201:
202: /**
203: * @see org.andromda.metafacades.uml.AttributeFacade#getType()
204: */
205: protected java.lang.Object handleGetType() {
206: return this .metaObject.getType();
207: }
208:
209: /**
210: * @see org.andromda.metafacades.uml.AttributeFacade#getEnumeration()
211: */
212: protected Object handleGetEnumeration() {
213: return this .isEnumerationLiteral() ? this .getOwner() : null;
214: }
215:
216: protected boolean handleIsDefaultValuePresent() {
217: return !(this .getDefaultValue() == null || this
218: .getDefaultValue().equals(""));
219: }
220:
221: /**
222: * Overridden to provide different handling of the name if this attribute represents a literal.
223: *
224: * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
225: */
226: protected String handleGetName() {
227: final String mask = String
228: .valueOf(this
229: .getConfiguredProperty(this .getOwner() instanceof EnumerationFacade ? UMLMetafacadeProperties.ENUMERATION_LITERAL_NAME_MASK
230: : UMLMetafacadeProperties.CLASSIFIER_PROPERTY_NAME_MASK));
231:
232: return NameMasker.mask(super .handleGetName(), mask);
233: }
234:
235: /* protected boolean handleIsBindingDependenciesPresent()
236: {
237: // TODO: Implement this with Templates.
238: // This method has been overriden. Why ?
239: return false;
240: }
241:
242: protected boolean handleIsTemplateParametersPresent()
243: {
244: // TODO: This method has been overriden. Why ?
245: return false;
246: }
247:
248: protected void handleCopyTaggedValues(final ModelElementFacade element)
249: {
250: // TODO: This method has been overriden. Why ?
251: }
252:
253: protected Object handleGetTemplateParameter(final String parameterName)
254: {
255: // TODO: This method has been overriden. Why ?
256: return null;
257: }
258:
259: protected Collection handleGetTemplateParameters()
260: {
261: // TODO: This method has been overriden. Why ?
262: return null;
263: } */
264:
265: /**
266: * Get the UML upper multiplicity Not implemented for UML1.4
267: */
268: protected int handleGetUpper() {
269: // MD11.5 Exports multiplicity as String
270: return UmlUtilities.parseMultiplicity(this .metaObject
271: .getUpperValue());
272: }
273:
274: /**
275: * Get the UML lower multiplicity Not implemented for UML1.4
276: */
277: protected int handleGetLower() {
278: // MD11.5 Exports multiplicity as String
279: return UmlUtilities.parseMultiplicity(this .metaObject
280: .getLowerValue());
281: }
282:
283: protected Object handleFindTaggedValue(String name,
284: final boolean follow) {
285: name = StringUtils.trimToEmpty(name);
286: Object value = this .findTaggedValue(name);
287: if (follow) {
288: ClassifierFacade type = this .getType();
289: while (value == null && type != null) {
290: value = type.findTaggedValue(name);
291: type = (ClassifierFacade) type.getGeneralization();
292: }
293: }
294: return value;
295: }
296: }
|