001: package org.andromda.metafacades.uml14;
002:
003: import org.andromda.metafacades.uml.AttributeFacade;
004: import org.andromda.metafacades.uml.ClassifierFacade;
005: import org.andromda.metafacades.uml.NameMasker;
006: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
007: import org.apache.commons.collections.CollectionUtils;
008: import org.apache.commons.collections.Predicate;
009: import org.apache.commons.lang.BooleanUtils;
010: import org.apache.commons.lang.StringUtils;
011:
012: import java.util.Collection;
013:
014: /**
015: * MetafacadeLogic implementation for org.andromda.metafacades.uml.EnumerationFacade.
016: *
017: * @see org.andromda.metafacades.uml.EnumerationFacade
018: */
019: public class EnumerationFacadeLogicImpl extends EnumerationFacadeLogic {
020:
021: public EnumerationFacadeLogicImpl(
022: org.omg.uml.foundation.core.Classifier 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.ENUMERATION_NAME_MASK));
036: return NameMasker.mask(super .handleGetName(), nameMask);
037: }
038:
039: /**
040: * @see org.andromda.metafacades.uml.EnumerationFacade#getLiterals()
041: */
042: protected java.util.Collection handleGetLiterals() {
043: Collection literals = this .getAttributes();
044: CollectionUtils.filter(literals, new Predicate() {
045: public boolean evaluate(Object object) {
046: boolean isLiteral = true;
047: final AttributeFacade attribute = (AttributeFacade) object;
048: if (attribute.isEnumerationMember()) {
049: isLiteral = false;
050: }
051: return isLiteral;
052: }
053: });
054: return literals;
055: }
056:
057: /**
058: * @see org.andromda.metafacades.uml.EnumerationFacade#getMemberVariables()
059: */
060: protected java.util.Collection handleGetMemberVariables() {
061: Collection variables = super .getAttributes();
062: CollectionUtils.filter(variables, new Predicate() {
063: public boolean evaluate(Object object) {
064: boolean isMember = false;
065: final AttributeFacade attribute = (AttributeFacade) object;
066: if (attribute.isEnumerationMember()) {
067: isMember = true;
068: }
069: return isMember;
070: }
071: });
072: return variables;
073: }
074:
075: /**
076: * @see org.andromda.metafacades.uml.EnumerationFacade#getFromOperationSignature()
077: */
078: protected String handleGetFromOperationSignature() {
079: final StringBuffer signature = new StringBuffer(this
080: .getFromOperationName());
081: final ClassifierFacade type = this .getLiteralType();
082: if (type != null) {
083: signature.append('(');
084: signature.append(type.getFullyQualifiedName());
085: signature.append(" value)");
086: }
087: return signature.toString();
088: }
089:
090: /**
091: * @see org.andromda.metafacades.uml.EnumerationFacade#isTypeSafe()
092: */
093: protected boolean handleIsTypeSafe() {
094: return BooleanUtils
095: .toBoolean(String
096: .valueOf(this
097: .getConfiguredProperty(UMLMetafacadeProperties.TYPE_SAFE_ENUMS_ENABLED)));
098: }
099:
100: /**
101: * @see org.andromda.metafacades.uml.EnumerationFacade#getFromOperationName()
102: */
103: protected String handleGetFromOperationName() {
104: final StringBuffer name = new StringBuffer("from");
105: final ClassifierFacade type = this .getLiteralType();
106: if (type != null) {
107: name.append(StringUtils.capitalize(type.getName()));
108: }
109: return name.toString();
110: }
111:
112: /**
113: * @see org.andromda.metafacades.uml.EnumerationFacade#getLiteralType()
114: */
115: protected Object handleGetLiteralType() {
116: Object type = null;
117: final Collection literals = this .getLiterals();
118: if (literals != null && !literals.isEmpty()) {
119: type = ((AttributeFacade) literals.iterator().next())
120: .getType();
121: }
122: return type;
123: }
124: }
|