001: package org.andromda.metafacades.emf.uml2;
002:
003: import org.andromda.metafacades.uml.ClassifierFacade;
004: import org.andromda.metafacades.uml.NameMasker;
005: import org.andromda.metafacades.uml.TypeMappings;
006: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
007: import org.andromda.metafacades.uml.UMLMetafacadeUtils;
008: import org.andromda.metafacades.uml.UMLProfile;
009: import org.andromda.utils.StringUtilsHelper;
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.AggregationKind;
014: import org.eclipse.uml2.MultiplicityElement;
015:
016: /**
017: * MetafacadeLogic implementation for
018: * org.andromda.metafacades.uml.AssociationEndFacade.
019: *
020: * @see org.andromda.metafacades.uml.AssociationEndFacade
021: */
022: public class AssociationEndFacadeLogicImpl extends
023: AssociationEndFacadeLogic {
024: public AssociationEndFacadeLogicImpl(
025: final AssociationEnd metaObject, final String context) {
026: super (metaObject, context);
027: }
028:
029: /**
030: * @see org.andromda.metafacades.uml.AssociationEndFacade#isOne2One()
031: */
032: protected boolean handleIsOne2One() {
033: return !this .isMany() && !this .getOtherEnd().isMany();
034: }
035:
036: /**
037: * @see org.andromda.metafacades.uml.AssociationEndFacade#isOne2Many()
038: */
039: protected boolean handleIsOne2Many() {
040: return !this .isMany() && this .getOtherEnd().isMany();
041: }
042:
043: /**
044: * @see org.andromda.metafacades.uml.AssociationEndFacade#isMany2One()
045: */
046: protected boolean handleIsMany2One() {
047: return this .isMany() && !this .getOtherEnd().isMany();
048: }
049:
050: /**
051: * @see org.andromda.metafacades.uml.AssociationEndFacade#isMany2Many()
052: */
053: protected boolean handleIsMany2Many() {
054: return this .isMany() && this .getOtherEnd().isMany();
055: }
056:
057: /**
058: * @see org.andromda.metafacades.uml.AssociationEndFacade#isAggregation()
059: */
060: protected boolean handleIsAggregation() {
061: return UmlUtilities.getOppositeAssociationEnd(this .metaObject)
062: .getAggregation()
063: .equals(AggregationKind.SHARED_LITERAL);
064: }
065:
066: /**
067: * @see org.andromda.metafacades.uml.AssociationEndFacade#isComposition()
068: */
069: protected boolean handleIsComposition() {
070: return UmlUtilities.getOppositeAssociationEnd(this .metaObject)
071: .getAggregation().equals(
072: AggregationKind.COMPOSITE_LITERAL);
073: }
074:
075: /**
076: * @see org.andromda.metafacades.uml.AssociationEndFacade#isOrdered()
077: */
078: protected boolean handleIsOrdered() {
079: return this .metaObject.isOrdered();
080: }
081:
082: /**
083: * @see org.andromda.metafacades.uml.AssociationEndFacade#isReadOnly()
084: */
085: protected boolean handleIsReadOnly() {
086: return this .metaObject.isReadOnly();
087: }
088:
089: /**
090: * @see org.andromda.metafacades.uml.AssociationEndFacade#isNavigable()
091: */
092: protected boolean handleIsNavigable() {
093: return this .metaObject.isNavigable();
094: }
095:
096: /**
097: * @see org.andromda.metafacades.uml14.ModelElementFacadeLogic#handleGetName()
098: */
099: protected String handleGetName() {
100: String name = super .handleGetName();
101:
102: // if name is empty, then get the name from the type
103: if (StringUtils.isEmpty(name)) {
104: final ClassifierFacade type = this .getType();
105: if (type != null) {
106: name = StringUtils.uncapitalize(StringUtils
107: .trimToEmpty(type.getName()));
108: }
109: if (this .isMany() && this .isPluralizeAssociationEndNames()) {
110: name = StringUtilsHelper.pluralize(name);
111: }
112: }
113: final String nameMask = String
114: .valueOf(this
115: .getConfiguredProperty(UMLMetafacadeProperties.CLASSIFIER_PROPERTY_NAME_MASK));
116: return NameMasker.mask(name, nameMask);
117: }
118:
119: /**
120: * Indicates whether or not we should pluralize association end names.
121: *
122: * @return true/false
123: */
124: private boolean isPluralizeAssociationEndNames() {
125: final Object value = this
126: .getConfiguredProperty(UMLMetafacadeProperties.PLURALIZE_ASSOCIATION_END_NAMES);
127: return value != null
128: && Boolean.valueOf(String.valueOf(value))
129: .booleanValue();
130: }
131:
132: /**
133: * @see org.andromda.metafacades.uml.AssociationEndFacade#getGetterName()
134: */
135: protected java.lang.String handleGetGetterName() {
136: return UMLMetafacadeUtils.getGetterPrefix(this .getType())
137: + StringUtils.capitalize(this .getName());
138: }
139:
140: /**
141: * @see org.andromda.metafacades.uml.AssociationEndFacade#getSetterName()
142: */
143: protected java.lang.String handleGetSetterName() {
144: return "set" + StringUtils.capitalize(this .getName());
145: }
146:
147: /**
148: * @see org.andromda.metafacades.uml.AssociationEndFacade#getGetterSetterTypeName()
149: */
150: protected java.lang.String handleGetGetterSetterTypeName() {
151: String name = null;
152: if (this .isMany()) {
153: final TypeMappings mappings = this .getLanguageMappings();
154: if (mappings != null) {
155: name = mappings
156: .getTo(this .isOrdered() ? UMLProfile.LIST_TYPE_NAME
157: : UMLProfile.COLLECTION_TYPE_NAME);
158: }
159:
160: // set this association end's type as a template parameter if
161: // required
162: if (this .getType() != null
163: && BooleanUtils
164: .toBoolean(ObjectUtils
165: .toString(this
166: .getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING)))) {
167: name = name + "<"
168: + this .getType().getFullyQualifiedName() + ">";
169: }
170: }
171: if (name == null && this .getType() != null) {
172: name = this .getType().getFullyQualifiedName();
173: }
174: return name;
175: }
176:
177: /**
178: * @see org.andromda.metafacades.uml.AssociationEndFacade#isMany()
179: */
180: protected boolean handleIsMany() {
181: // Because of MD11.5 (their multiplicity are String), we cannot use
182: // isMultiValued()
183: return this .getUpper() > 1
184: || this .getUpper() == MultiplicityElement.UNLIMITED_UPPER_BOUND;
185: }
186:
187: /**
188: * @see org.andromda.metafacades.uml.AssociationEndFacade#isRequired()
189: */
190: protected boolean handleIsRequired() {
191: return (this .getLower() > 0);
192: }
193:
194: /**
195: * @see org.andromda.metafacades.uml.AssociationEndFacade#isChild()
196: */
197: protected boolean handleIsChild() {
198: return this .getOtherEnd() != null
199: && this .getOtherEnd().isComposition();
200: }
201:
202: /**
203: * @see org.andromda.metafacades.uml.AssociationEndFacade#getOtherEnd()
204: */
205: protected java.lang.Object handleGetOtherEnd() {
206: return UmlUtilities.getOppositeAssociationEnd(this .metaObject);
207: }
208:
209: /**
210: * @see org.andromda.metafacades.uml.AssociationEndFacade#getAssociation()
211: */
212: protected java.lang.Object handleGetAssociation() {
213: return this .metaObject.getAssociation();
214: }
215:
216: /**
217: * @see org.andromda.metafacades.uml.AssociationEndFacade#getType()
218: */
219: protected java.lang.Object handleGetType() {
220: // In uml1.4 facade, it returns getParticipant
221: return this .metaObject.getType();
222: }
223:
224: /**
225: * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
226: */
227: public Object getValidationOwner() {
228: return this .getType();
229: }
230:
231: /**
232: * Get the UML upper multiplicity Not implemented for UML1.4
233: */
234: protected int handleGetUpper() {
235: // MD11.5 Exports multiplicity as String
236: return UmlUtilities.parseMultiplicity(this .metaObject
237: .getUpperValue());
238: }
239:
240: /**
241: * Get the UML lower multiplicity Not implemented for UML1.4
242: */
243: protected int handleGetLower() {
244: // MD11.5 Exports multiplicity as String
245: return UmlUtilities.parseMultiplicity(this.metaObject
246: .getLowerValue());
247: }
248: }
|