blob: 8ee5523d07f90c1e4b1c3af2e87672c784cb0e32 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*****************************************************************************
* Copyright (c) 2013 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Remi Schnekenburger (CEA LIST) - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.extendedtypes.applystereotypeactionconfiguration;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.infra.extendedtypes.Activator;
import org.eclipse.papyrus.infra.extendedtypes.emf.converter.ConverterNotfoundException;
import org.eclipse.papyrus.infra.extendedtypes.emf.converter.ConverterRegistry;
import org.eclipse.papyrus.uml.tools.extendedtypes.applystereotypeactionconfiguration.util.ApplyStereotypeActionConfigurationSwitch;
import org.eclipse.uml2.uml.Feature;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.ValueSpecification;
/**
* Utility class to get values from a {@link FeatureValue}
*/
public class StereotypeFeatureValueUtils {
protected StereotypeFeatureValueUtils() {
// no instanciation, helper class
}
/**
* Returns the value to set for a given feature of a given element
* @param elementToConfigure eobject for which feature is set. This must not be <code>null</code>
* @param feature {@link EStructuralFeature} to set. This must not be <code>null</code>
* @param valueModel configuration of the value, stored in the model
* @return the real value that will be set to the object or <code>null</code> if none could be computed
*/
public static Object getValue(final EObject elementToConfigure, final Stereotype stereotype, final EStructuralFeature feature, final FeatureValue featureValue) {
Object result = new ApplyStereotypeActionConfigurationSwitch<Object>() {
/**
* {@inheritDoc}
*/
@Override
public Object caseConstantValue(ConstantValue object) {
ValueSpecification valueSpecification = object.getValueInstance();
if(valueSpecification==null) {
return null;
}
try {
return ConverterRegistry.getSingleton().convert(feature.getEType().getInstanceClass(), valueSpecification);
} catch (ConverterNotfoundException e) {
Activator.log.error("Impossible to convert "+valueSpecification+ " to fit feature type :"+feature, e);
}
return super.caseConstantValue(object);
}
/**
* {@inheritDoc}
*/
@Override
public Object caseQueryExecutionValue(QueryExecutionValue object) {
throw new UnsupportedOperationException("Query execution values resolution has not been implemented yet");
};
/**
* {@inheritDoc}
*/
@Override
public Object caseDynamicValue(DynamicValue object) {
throw new UnsupportedOperationException("Dynamic values resolution has not been implemented yet");
};
/**
* {@inheritDoc}
*/
@Override
public Object caseListValue(ListValue object) {
// resolve one by one all features in the values list of this listvalue
List<Object> results = new ArrayList<Object>();
for(FeatureValue value : object.getValues()) {
Object singleResult = getValue(elementToConfigure, stereotype, feature, value);
results.add(singleResult);
}
return results;
};
}.doSwitch(featureValue);
return result;
}
}
|