Skip to content

Package: EStructuralFeatureValueConverter

EStructuralFeatureValueConverter

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: * mathias - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.common.converter;
15:
16: import org.eclipse.emf.ecore.EObject;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18:
19: /**
20: * @author Mathias Schaefer <mschaefer@eclipsesource.com>
21: * @since 1.11
22: *
23: */
24: public interface EStructuralFeatureValueConverter {
25:
26:         /** Conversion direction. */
27:         enum Direction {
28:                 /**
29:                  * Conversion from model value to string literal.
30:                  */
31:                 MODEL_TO_LITERAL,
32:
33:                 /**
34:                  * Conversion from string literal to model value.
35:                  */
36:                 LITERAL_TO_MODEL,
37:         }
38:
39:         /**
40:          * Constant value to mark a converter implementation not applicable
41:          * for the given EObject/EStructuralFeature combination.
42:          */
43:         double NOT_APPLICABLE = -1d;
44:
45:         /**
46:          * Check whether this converter instance is applicable for the given feature.
47:          *
48:          * @param eObject (optional)
49:          * @param feature the target feature
50:          * @param value the value
51:          * @param direction the direction
52:          * @return rank of converter (higher value means higher priority)
53:          */
54:         double isApplicable(EObject eObject, EStructuralFeature feature, Object value, Direction direction);
55:
56:         /**
57:          * Convert string literal to model value instance.
58:          *
59:          * @param eObject (optional, only required for EReferences)
60:          * @param feature the target feature
61:          * @param literal the string literal
62:          * @return converted value
63:          */
64:         Object convertToModelValue(EObject eObject, EStructuralFeature feature, String literal);
65:
66:         /**
67:          * Convert model value instance to string literal.
68:          *
69:          * @param eObject (optional)
70:          * @param feature the source feature
71:          * @param instance the source value object
72:          * @return converted value (commonly a string literal)
73:          */
74:         Object convertToLiteral(EObject eObject, EStructuralFeature feature, Object instance);
75:
76: }