Skip to content

Package: AndConditionService

AndConditionService

nameinstructionbranchcomplexitylinemethod
AndConditionService()
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%
activate(BundleContext)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
deactivate(BundleContext)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
evaluate(AndCondition, EObject)
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
evaluateChangedValues(AndCondition, EObject, Map)
M: 2 C: 7
78%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
getConditionServiceManager()
M: 5 C: 23
82%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 6
86%
M: 0 C: 1
100%
getConditionSettings(AndCondition, EObject)
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%
getConditionType()
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%
getDomainModelReferences(AndCondition)
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 EclipseSource Muenchen GmbH 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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.rule;
15:
16: import java.util.HashSet;
17: import java.util.LinkedHashSet;
18: import java.util.Map;
19: import java.util.Set;
20:
21: import org.eclipse.emf.ecore.EClass;
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.AndCondition;
28: import org.eclipse.emf.ecp.view.spi.rule.model.Condition;
29: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
30: import org.osgi.framework.BundleContext;
31: import org.osgi.framework.ServiceReference;
32: import org.osgi.service.component.annotations.Activate;
33: import org.osgi.service.component.annotations.Component;
34: import org.osgi.service.component.annotations.Deactivate;
35:
36: /** {@link ConditionService} for conditions of type {@link AndCondition}. */
37: @Component
38: public class AndConditionService implements ConditionService<AndCondition> {
39:
40:         private BundleContext bundleContext;
41:         private ServiceReference<ConditionServiceManager> conditionServiceManagerReference;
42:         private ConditionServiceManager conditionServiceManager;
43:
44:         @Override
45:         public EClass getConditionType() {
46:                 return RulePackage.eINSTANCE.getAndCondition();
47:         }
48:
49:         @Override
50:         public Set<UniqueSetting> getConditionSettings(AndCondition condition, EObject domainModel) {
51:                 final Set<UniqueSetting> registeredSettings = new LinkedHashSet<UniqueSetting>();
52:                 final ConditionServiceManager conditionService = getConditionServiceManager();
53:•                for (final Condition cond : condition.getConditions()) {
54:                         registeredSettings.addAll(conditionService.getConditionSettings(cond, domainModel));
55:                 }
56:                 return registeredSettings;
57:         }
58:
59:         @Override
60:         public boolean evaluate(AndCondition condition, EObject domainModel) {
61:•                if (condition == null) {
62:                         return false;
63:                 }
64:                 return condition.evaluate(domainModel);
65:         }
66:
67:         @Override
68:         public boolean evaluateChangedValues(AndCondition condition, EObject domainModel,
69:                 Map<Setting, Object> possibleNewValues) {
70:•                if (condition == null) {
71:                         return false;
72:                 }
73:                 return condition.evaluateChangedValues(domainModel, possibleNewValues);
74:         }
75:
76:         @Override
77:         public Set<VDomainModelReference> getDomainModelReferences(AndCondition condition) {
78:                 final Set<VDomainModelReference> references = new HashSet<VDomainModelReference>();
79:                 final ConditionServiceManager conditionService = getConditionServiceManager();
80:•                for (final Condition cond : condition.getConditions()) {
81:                         references.addAll(conditionService.getDomainModelReferences(cond));
82:                 }
83:                 return references;
84:         }
85:
86:         /**
87:          * Called by the framework when the component gets activated.
88:          *
89:          * @param bundleContext The {@link BundleContext}
90:          */
91:         @Activate
92:         protected void activate(BundleContext bundleContext) {
93:                 this.bundleContext = bundleContext;
94:         }
95:
96:         /**
97:          * Called by the framework when the component gets deactivated.
98:          *
99:          * @param bundleContext The {@link BundleContext}
100:          */
101:         @Deactivate
102:         protected void deactivate(BundleContext bundleContext) {
103:•                if (conditionServiceManagerReference != null) {
104:                         bundleContext.ungetService(conditionServiceManagerReference);
105:                         conditionServiceManager = null;
106:                 }
107:         }
108:
109:         private ConditionServiceManager getConditionServiceManager() {
110:•                if (conditionServiceManager == null) {
111:                         conditionServiceManagerReference = bundleContext
112:                                 .getServiceReference(ConditionServiceManager.class);
113:•                        if (conditionServiceManagerReference == null) {
114:                                 throw new IllegalStateException("No ConditionServiceManager available!"); //$NON-NLS-1$
115:                         }
116:                         conditionServiceManager = bundleContext.getService(conditionServiceManagerReference);
117:                 }
118:                 return conditionServiceManager;
119:         }
120:
121: }