Skip to content

Package: CompositeConditionService

CompositeConditionService

nameinstructionbranchcomplexitylinemethod
CompositeConditionService()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
deactivate()
M: 0 C: 13
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
evaluate(Condition, EObject)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
evaluateChangedValues(Condition, EObject, Map)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getBundleContext()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getConditionServiceManager()
M: 5 C: 24
83%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 6
86%
M: 0 C: 1
100%
getConditionSettings(Condition, EObject)
M: 0 C: 45
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
getDomainModelReferences(Condition)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getTargets(Condition, EObject)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 Christian W. Damus and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.rule;
15:
16: import java.util.Collections;
17: import java.util.LinkedHashSet;
18: import java.util.List;
19: import java.util.Map;
20: import java.util.Set;
21:
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
24: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
25: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
26: import org.eclipse.emf.ecp.view.spi.rule.ConditionService;
27: import org.eclipse.emf.ecp.view.spi.rule.model.Condition;
28: import org.osgi.framework.BundleContext;
29: import org.osgi.framework.FrameworkUtil;
30: import org.osgi.framework.ServiceReference;
31: import org.osgi.service.component.annotations.Deactivate;
32:
33: /**
34: * Partial implementation of a condition service for composite conditions.
35: *
36: * @param <C> the type of condition for which I provide service
37: *
38: * @author Christian W. Damus
39: */
40: abstract class CompositeConditionService<C extends Condition> implements ConditionService<C> {
41:
42:         private ServiceReference<ConditionServiceManager> conditionServiceManagerReference;
43:         private ConditionServiceManager conditionServiceManager;
44:
45:         /**
46:          * Initializes me.
47:          */
48:         protected CompositeConditionService() {
49:                 super();
50:         }
51:
52:         /**
53:          * Deactivates me.
54:          */
55:         @Deactivate
56:         void deactivate() {
57:                 conditionServiceManager = null;
58:•                if (conditionServiceManagerReference != null) {
59:                         getBundleContext().ungetService(conditionServiceManagerReference);
60:                 }
61:         }
62:
63:         private BundleContext getBundleContext() {
64:                 return FrameworkUtil.getBundle(getClass()).getBundleContext();
65:         }
66:
67:         @Override
68:         public Set<UniqueSetting> getConditionSettings(C condition, EObject domainModel) {
69:                 final Set<UniqueSetting> result = new LinkedHashSet<UniqueSetting>();
70:                 final ConditionServiceManager manager = getConditionServiceManager();
71:                 final Iterable<? extends EObject> targets = getTargets(condition, domainModel);
72:
73:•                for (final Condition component : components(condition)) {
74:•                        for (final EObject next : targets) {
75:                                 result.addAll(manager.getConditionSettings(component, next));
76:                         }
77:                 }
78:
79:                 return result;
80:         }
81:
82:         /**
83:          * Obtains the objects on which a {@code condition} is evaluated.
84:          *
85:          * @param condition a composite condition of my type
86:          * @param domainModel the source from which to navigate to obtain the targets for evaluation
87:          * of the {@code condition}
88:          * @return the evaluation targets
89:          */
90:         protected List<? extends EObject> getTargets(C condition, EObject domainModel) {
91:                 return Collections.singletonList(domainModel);
92:         }
93:
94:         /**
95:          * Obtains the nested conditions in a composite {@code condition} of my type.
96:          *
97:          * @param condition the composite condition from which to get components
98:          * @return the {@code condition}'s zero or more nested conditions that are its components
99:          */
100:         protected abstract Iterable<? extends Condition> components(C condition);
101:
102:         @Override
103:         public Set<VDomainModelReference> getDomainModelReferences(C condition) {
104:                 final Set<VDomainModelReference> result = new LinkedHashSet<VDomainModelReference>();
105:                 final ConditionServiceManager manager = getConditionServiceManager();
106:
107:•                for (final Condition next : components(condition)) {
108:                         result.addAll(manager.getDomainModelReferences(next));
109:                 }
110:
111:                 return result;
112:         }
113:
114:         @Override
115:         public boolean evaluate(C condition, EObject domainModel) {
116:                 return condition.evaluate(domainModel);
117:         }
118:
119:         @Override
120:         public boolean evaluateChangedValues(C condition, EObject domainModel, Map<Setting, Object> possibleNewValues) {
121:                 return condition.evaluateChangedValues(domainModel, possibleNewValues);
122:         }
123:
124:         private ConditionServiceManager getConditionServiceManager() {
125:•                if (conditionServiceManager == null) {
126:                         final BundleContext context = getBundleContext();
127:                         conditionServiceManagerReference = context.getServiceReference(ConditionServiceManager.class);
128:•                        if (conditionServiceManagerReference == null) {
129:                                 throw new IllegalStateException("No ConditionServiceManager"); //$NON-NLS-1$
130:                         }
131:                         conditionServiceManager = context.getService(conditionServiceManagerReference);
132:                 }
133:                 return conditionServiceManager;
134:         }
135:
136: }