Skip to content

Package: FactoryComponentProductionContext

FactoryComponentProductionContext

nameinstructionbranchcomplexitylinemethod
FactoryComponentProductionContext(IProductionContext, ProjectBundleSession, FactoryComponent, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
FactoryComponentProductionContext(ProjectBundleSession, FactoryComponent, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getContract(Object, Collection, String, String)
M: 96 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getInputValue(Object, Class)
M: 48 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getInputValueType(Object)
M: 42 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getOutputValue(Object, Class)
M: 48 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getOutputValueType(Object)
M: 42 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
isSetAtRuntime(Object)
M: 27 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
setOutputValue(Object, Object)
M: 117 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: * Copyright (c) 2009-2010 Thales Corporate Services S.A.S.
3: * This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v2.0
5: * which accompanies this distribution, and is available at
6: * https://www.eclipse.org/legal/epl-v2.0
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Thales Corporate Services S.A.S - initial API and implementation
12: */
13: package org.eclipse.egf.producer.internal.context;
14:
15: import java.util.Collection;
16:
17: import org.eclipse.egf.common.helper.ClassHelper;
18: import org.eclipse.egf.common.helper.EMFHelper;
19: import org.eclipse.egf.core.producer.InvocationException;
20: import org.eclipse.egf.core.producer.context.IProductionContext;
21: import org.eclipse.egf.core.producer.l10n.CoreProducerMessages;
22: import org.eclipse.egf.core.session.ProjectBundleSession;
23: import org.eclipse.egf.model.fcore.Contract;
24: import org.eclipse.egf.model.fcore.FactoryComponent;
25: import org.eclipse.egf.model.fcore.FactoryComponentContract;
26: import org.eclipse.egf.model.fcore.Invocation;
27: import org.eclipse.egf.model.fcore.InvocationContract;
28: import org.eclipse.egf.producer.context.IFactoryComponentProductionContext;
29: import org.eclipse.osgi.util.NLS;
30:
31: /**
32: * @author Xavier Maysonnave
33: *
34: */
35: public class FactoryComponentProductionContext extends ActivityProductionContext<FactoryComponent> implements IFactoryComponentProductionContext {
36:
37: public FactoryComponentProductionContext(ProjectBundleSession projectBundleSession, FactoryComponent element, String name) {
38: super(projectBundleSession, element, name);
39: }
40:
41: public FactoryComponentProductionContext(IProductionContext<Invocation, InvocationContract> parent, ProjectBundleSession projectBundleSession, FactoryComponent element, String name) {
42: super(parent, projectBundleSession, element, name);
43: }
44:
45: @Override
46: public boolean isSetAtRuntime(Object key) throws InvocationException {
47: // It could be a String in this context
48:• if (key != null && key instanceof String) {
49: return super.isSetAtRuntime(key);
50: }
51: // Locate a Contract
52: Contract contract = getContract(key, getInputValueKeys(), getName(), __inputMode);
53: // Looking for a Parent Input Contract set at runtime
54:• if (getParent() != null) {
55: return getParent().isSetAtRuntime(contract);
56: }
57: return false;
58: }
59:
60: @Override
61: public Class<?> getInputValueType(Object key) throws InvocationException {
62: // It could be a String in this context
63:• if (key != null && key instanceof String) {
64: return super.getInputValueType(key);
65: }
66: // Locate a Contract
67: Contract contract = getContract(key, getInputValueKeys(), getName(), __inputMode);
68: Class<?> valueType = null;
69: // Looking for Parent Value Type if available
70:• if (getParent() != null) {
71: valueType = getParent().getInputValueType(contract);
72: }
73: // Looking for local Value Type if necessary
74:• if (valueType == null) {
75: Data inputData = _inputDatas.get(contract);
76:• if (inputData != null) {
77: valueType = inputData.getType();
78: }
79: }
80: return valueType;
81: }
82:
83: @Override
84: public <R> R getInputValue(Object key, Class<R> clazz) throws InvocationException {
85: // It could be a String in this context
86:• if (key != null && key instanceof String) {
87: return super.getInputValue(key, clazz);
88: }
89: // Locate an Contract
90: Contract contract = getContract(key, getInputValueKeys(), getName(), __inputMode);
91: R value = null;
92: // Looking for Parent Value if available
93:• if (getParent() != null) {
94: value = getParent().getInputValue(contract, clazz);
95: }
96: // Looking for a local value if necessary
97:• if (value == null) {
98: Data inputData = _inputDatas.get(contract);
99:• if (inputData != null) {
100: value = getValue(contract, clazz, inputData, __inputMode);
101: }
102: }
103: return value;
104: }
105:
106: @Override
107: public Class<?> getOutputValueType(Object key) throws InvocationException {
108: // It could be a String in this context
109:• if (key != null && key instanceof String) {
110: return super.getOutputValueType(key);
111: }
112: // Locate an Contract
113: Contract contract = getContract(key, getOutputValueKeys(), getName(), __outputMode);
114: Class<?> valueType = null;
115: // Looking for Parent Value Type if available
116:• if (getParent() != null) {
117: valueType = getParent().getOutputValueType(contract);
118: }
119: // Looking for a local Value Type if necessary
120:• if (valueType == null) {
121: Data outputData = _outputDatas.get(contract);
122:• if (outputData != null) {
123: valueType = outputData.getType();
124: }
125: }
126: return valueType;
127: }
128:
129: @Override
130: public <R> R getOutputValue(Object key, Class<R> clazz) throws InvocationException {
131: // It could be a String in this context
132:• if (key != null && key instanceof String) {
133: return super.getOutputValue(key, clazz);
134: }
135: // Locate an Contract
136: Contract contract = getContract(key, getOutputValueKeys(), getName(), __outputMode);
137: R value = null;
138: // Looking for Parent Value if available
139:• if (getParent() != null) {
140: value = getParent().getOutputValue(contract, clazz);
141: }
142: // Looking for a local value if necessary
143:• if (value == null) {
144: Data outputData = _outputDatas.get(contract);
145:• if (outputData != null) {
146: value = getValue(contract, clazz, outputData, __outputMode);
147: }
148: }
149: return value;
150: }
151:
152: @Override
153: public void setOutputValue(Object key, Object value) throws InvocationException {
154: // It could be a String in this context
155:• if (key != null && key instanceof String) {
156: super.setOutputValue(key, value);
157: }
158: // Locate an Contract
159: Contract contract = getContract(key, getOutputValueKeys(), getName(), __outputMode);
160: // Propagate Value to parent if necessary
161:• if (getParent() != null) {
162: getParent().setOutputValue(contract, value);
163: }
164: // Fetch available output data
165: Data outputData = _outputDatas.get(contract);
166:• if (outputData == null) {
167: throw new InvocationException(NLS.bind(CoreProducerMessages.ProductionContext_unknown_key, new Object[] {
168: __outputMode, EMFHelper.getText(key), getName()
169: }));
170: }
171: // null value is a valid value
172:• if (value != null && (ClassHelper.isSubClass(value.getClass(), outputData.getType()) == false || outputData.getType().isInstance(value) == false)) {
173: throw new InvocationException(NLS.bind(CoreProducerMessages.ProductionContext_wrong_type, new Object[] {
174: outputData.getType().getName(), __outputMode, EMFHelper.getText(key), value.getClass().getName(), getName()
175: }));
176: }
177: // Set ouptut value
178: outputData.setValue(value);
179: // Set input value if it exists
180: Data inputData = _inputDatas.get(key);
181:• if (inputData != null) {
182: inputData.setValue(value);
183: }
184: }
185:
186: private static Contract getContract(Object key, Collection<Contract> keys, String name, String mode) throws InvocationException {
187: // Usual Tests
188:• if (key == null) {
189: throw new InvocationException(NLS.bind(CoreProducerMessages.ProductionContext_null_key, mode, name));
190: }
191:• if (key instanceof InvocationContract == false) {
192: throw new InvocationException(NLS.bind(CoreProducerMessages.ProductionContext_wrong_type, new Object[] {
193: InvocationContract.class.getName(), mode, EMFHelper.getText(key), key.getClass().getName(), name
194: }));
195: }
196: // Locate Contract
197: Contract contract = null;
198:• for (Contract innerContract : keys) {
199:• if (innerContract instanceof FactoryComponentContract == false) {
200: continue;
201: }
202:• if (((FactoryComponentContract) innerContract).getInvocationContracts().contains(key)) {
203: contract = innerContract;
204: break;
205: }
206: }
207: // Contract should be known at this stage
208:• if (contract == null) {
209: throw new InvocationException(NLS.bind(CoreProducerMessages.ProductionContext_unknown_key, new Object[] {
210: mode, EMFHelper.getText(key), name
211: }));
212: }
213: // Return
214: return contract;
215: }
216:
217: }