001: package org.andromda.metafacades.emf.uml2;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.LinkedHashSet;
006:
007: import org.andromda.metafacades.uml.DependencyFacade;
008: import org.andromda.metafacades.uml.Entity;
009: import org.andromda.metafacades.uml.FilteredCollection;
010: import org.andromda.metafacades.uml.ModelElementFacade;
011: import org.andromda.metafacades.uml.Role;
012: import org.andromda.metafacades.uml.Service;
013: import org.andromda.metafacades.uml.ServiceOperation;
014: import org.apache.commons.collections.Closure;
015: import org.apache.commons.collections.CollectionUtils;
016: import org.apache.commons.collections.Predicate;
017: import org.apache.commons.collections.Transformer;
018:
019: /**
020: * MetafacadeLogic implementation for org.andromda.metafacades.uml.Service.
021: *
022: * @see org.andromda.metafacades.uml.Service
023: */
024: public class ServiceLogicImpl extends ServiceLogic {
025: public ServiceLogicImpl(final Object metaObject,
026: final String context) {
027: super (metaObject, context);
028: }
029:
030: /**
031: * @see org.andromda.metafacades.uml.Service#getServiceReferences()
032: */
033: protected java.util.Collection handleGetServiceReferences() {
034: return new FilteredCollection(this .getSourceDependencies()) {
035: public boolean evaluate(final Object object) {
036: ModelElementFacade targetElement = ((DependencyFacade) object)
037: .getTargetElement();
038: return targetElement != null
039: && Service.class.isAssignableFrom(targetElement
040: .getClass());
041: }
042: };
043: }
044:
045: /**
046: * @see org.andromda.metafacades.uml.Service#getEntityReferences()
047: */
048: protected java.util.Collection handleGetEntityReferences() {
049: return new FilteredCollection(this .getSourceDependencies()) {
050: public boolean evaluate(final Object object) {
051: ModelElementFacade targetElement = ((DependencyFacade) object)
052: .getTargetElement();
053: return targetElement != null
054: && Entity.class.isAssignableFrom(targetElement
055: .getClass());
056: }
057: };
058: }
059:
060: /**
061: * @see org.andromda.metafacades.uml.Service.getAllServiceReferences()
062: */
063: public Collection handleGetAllServiceReferences() {
064: final Collection result = new ArrayList();
065:
066: // get references of the service itself
067: result.addAll(this .getServiceReferences());
068:
069: // get references of all super classes
070: CollectionUtils.forAllDo(this .getAllGeneralizations(),
071: new Closure() {
072: public void execute(final Object object) {
073: Service service = (Service) object;
074: result.addAll(service.getServiceReferences());
075: }
076: });
077: return result;
078: }
079:
080: /**
081: * @see org.andromda.metafacades.uml.Service#getRoles()
082: */
083: protected Collection handleGetRoles() {
084: final Collection roles = new ArrayList(this
085: .getTargetDependencies());
086: CollectionUtils.filter(roles, new Predicate() {
087: public boolean evaluate(final Object object) {
088: DependencyFacade dependency = (DependencyFacade) object;
089: return dependency != null
090: && dependency.getSourceElement() instanceof Role;
091: }
092: });
093: CollectionUtils.transform(roles, new Transformer() {
094: public Object transform(final Object object) {
095: return ((DependencyFacade) object).getSourceElement();
096: }
097: });
098:
099: final Collection allRoles = new LinkedHashSet(roles);
100:
101: // add all roles which are generalizations of this one
102: CollectionUtils.forAllDo(roles, new Closure() {
103: public void execute(final Object object) {
104: allRoles
105: .addAll(((Role) object).getAllSpecializations());
106: }
107: });
108: return allRoles;
109: }
110:
111: /**
112: * @see org.andromda.metafacades.uml.Service#getAllRoles()
113: */
114: protected Collection handleGetAllRoles() {
115: final Collection roles = new LinkedHashSet(this .getRoles());
116: CollectionUtils.forAllDo(this .getOperations(), new Closure() {
117: public void execute(final Object object) {
118: if (object instanceof ServiceOperation) {
119: roles
120: .addAll(((ServiceOperation) object)
121: .getRoles());
122: }
123: }
124: });
125: return roles;
126: }
127: }
|