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