Skip to content

Package: DynamicEcoreFactory

DynamicEcoreFactory

nameinstructionbranchcomplexitylinemethod
DynamicEcoreFactory()
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%
basicCreate(EClass)
M: 4 C: 16
80%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
booleanValueOf(String)
M: 5 C: 12
71%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 4
80%
M: 0 C: 1
100%
convertBytesToHexString(byte[], int)
M: 51 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
convertEBigDecimalToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEBigIntegerToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEBooleanObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEBooleanToString(EDataType, Object)
M: 2 C: 5
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
convertEByteArrayToString(EDataType, Object)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
convertEByteObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEByteToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertECharToString(EDataType, Object)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
convertECharacterObjectToString(EDataType, Object)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
convertEDateToString(EDataType, Object)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
convertEDoubleObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEDoubleToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEFloatObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEFloatToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEIntToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEIntegerObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEJavaClassToString(EDataType, Object)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEJavaObjectToString(EDataType, Object)
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%
convertELongObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertELongToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEShortObjectToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEShortToString(EDataType, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertEStringToString(EDataType, Object)
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%
convertToString(EDataType, Object)
M: 105 C: 110
51%
M: 21 C: 25
54%
M: 21 C: 3
13%
M: 21 C: 27
56%
M: 0 C: 1
100%
createEBigDecimalFromString(EDataType, String)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEBigIntegerFromString(EDataType, String)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEBooleanFromString(EDataType, String)
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
createEBooleanObjectFromString(EDataType, String)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEByteArrayFromString(EDataType, String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEByteFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEByteObjectFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createECharFromString(EDataType, String)
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
createECharacterObjectFromString(EDataType, String)
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
createEDateFromString(EDataType, String)
M: 28 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
createEDoubleFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEDoubleObjectFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEFloatFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEFloatObjectFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEIntFromString(EDataType, String)
M: 2 C: 5
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
createEIntegerObjectFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEJavaClassFromString(EDataType, String)
M: 61 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 21 C: 0
0%
M: 1 C: 0
0%
createEJavaObjectFromString(EDataType, String)
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%
createELongFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createELongObjectFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEShortFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEShortObjectFromString(EDataType, String)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createEStringFromString(EDataType, String)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createFromString(EDataType, String)
M: 100 C: 115
53%
M: 20 C: 26
57%
M: 20 C: 4
17%
M: 20 C: 28
58%
M: 0 C: 1
100%
hexCharToByte(char)
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
hexStringToByteArray(String)
M: 65 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 68
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2022 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: * jfaltermeier - initial API and implementation
13: * lkoehler - Override basicCreate to create non-dynamic EObjects
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.edapt;
16:
17: import java.math.BigDecimal;
18: import java.math.BigInteger;
19: import java.text.ParseException;
20: import java.util.Date;
21:
22: import org.eclipse.emf.common.util.WrappedException;
23: import org.eclipse.emf.ecore.EClass;
24: import org.eclipse.emf.ecore.EDataType;
25: import org.eclipse.emf.ecore.EObject;
26: import org.eclipse.emf.ecore.EcoreFactory;
27: import org.eclipse.emf.ecore.impl.BasicEObjectImpl;
28: import org.eclipse.emf.ecore.impl.EFactoryImpl;
29:
30: /**
31: * {@link org.eclipse.emf.ecore.EFactory EFactory} implementation for creating objects for the custom data types of the
32: * {@link org.eclipse.emf.ecore.EcoreFactory EcoreFactory}.
33: *
34: * Since edapt uses dynamic EMF the {@link org.eclipse.emf.ecore.EcoreFactory EcoreFactory} is not used when loading a
35: * model, we need a custom implementation. Moreover the switch should be based on the data type names, since the ids
36: * might differ as well.
37: *
38: * @author jfaltermeier
39: *
40: */
41: public class DynamicEcoreFactory extends EFactoryImpl {
42:
43:         private static final String E_BIG_DECIMAL = "EBigDecimal";//$NON-NLS-1$
44:         private static final String E_BIG_INTEGER = "EBigInteger";//$NON-NLS-1$
45:         private static final String E_BOOLEAN = "EBoolean";//$NON-NLS-1$
46:         private static final String E_BOOLEAN_OBJECT = "EBooleanObject";//$NON-NLS-1$
47:         private static final String E_BYTE = "EByte";//$NON-NLS-1$
48:         private static final String E_BYTE_ARRAY = "EByteArray";//$NON-NLS-1$
49:         private static final String E_BYTE_OBJECT = "EByteObject";//$NON-NLS-1$
50:         private static final String E_CHAR = "EChar";//$NON-NLS-1$
51:         private static final String E_CHARACTER_OBJECT = "ECharacterObject";//$NON-NLS-1$
52:         private static final String E_DATE = "EDate";//$NON-NLS-1$
53:         private static final String E_DOUBLE = "EDouble";//$NON-NLS-1$
54:         private static final String E_DOUBLE_OBJECT = "EDoubleObject";//$NON-NLS-1$
55:         private static final String E_FLOAT = "EFloat";//$NON-NLS-1$
56:         private static final String E_FLOAT_OBJECT = "EFloatObject";//$NON-NLS-1$
57:         private static final String E_INT = "EInt";//$NON-NLS-1$
58:         private static final String E_INTEGER_OBJECT = "EIntegerObject";//$NON-NLS-1$
59:         private static final String E_JAVA_CLASS = "EJavaClass";//$NON-NLS-1$
60:         private static final String E_JAVA_OBJECT = "EJavaObject";//$NON-NLS-1$
61:         private static final String E_LONG = "ELong";//$NON-NLS-1$
62:         private static final String E_LONG_OBJECT = "ELongObject";//$NON-NLS-1$
63:         private static final String E_SHORT = "EShort";//$NON-NLS-1$
64:         private static final String E_SHORT_OBJECT = "EShortObject";//$NON-NLS-1$
65:         private static final String E_STRING = "EString";//$NON-NLS-1$
66:
67:         /**
68:          *
69:          * {@inheritDoc}
70:          *
71:          * @see org.eclipse.emf.ecore.impl.EFactoryImpl#createFromString(org.eclipse.emf.ecore.EDataType, java.lang.String)
72:          */
73:         // BEGIN COMPLEX CODE
74:         @Override
75:         public Object createFromString(EDataType eDataType, String initialValue) {
76:                 final String id = eDataType.getName();
77:
78:•                if (E_BIG_DECIMAL.equals(id)) {
79:                         return createEBigDecimalFromString(eDataType, initialValue);
80:•                } else if (E_BIG_INTEGER.equals(id)) {
81:                         return createEBigIntegerFromString(eDataType, initialValue);
82:•                } else if (E_BOOLEAN.equals(id)) {
83:                         return createEBooleanFromString(eDataType, initialValue);
84:•                } else if (E_BOOLEAN_OBJECT.equals(id)) {
85:                         return createEBooleanObjectFromString(eDataType, initialValue);
86:•                } else if (E_BYTE.equals(id)) {
87:                         return createEByteFromString(eDataType, initialValue);
88:•                } else if (E_BYTE_ARRAY.equals(id)) {
89:                         return createEByteArrayFromString(eDataType, initialValue);
90:•                } else if (E_BYTE_OBJECT.equals(id)) {
91:                         return createEByteObjectFromString(eDataType, initialValue);
92:•                } else if (E_CHAR.equals(id)) {
93:                         return createECharFromString(eDataType, initialValue);
94:•                } else if (E_CHARACTER_OBJECT.equals(id)) {
95:                         return createECharacterObjectFromString(eDataType, initialValue);
96:•                } else if (E_DATE.equals(id)) {
97:                         return createEDateFromString(eDataType, initialValue);
98:•                } else if (E_DOUBLE.equals(id)) {
99:                         return createEDoubleFromString(eDataType, initialValue);
100:•                } else if (E_DOUBLE_OBJECT.equals(id)) {
101:                         return createEDoubleObjectFromString(eDataType, initialValue);
102:•                } else if (E_FLOAT.equals(id)) {
103:                         return createEFloatFromString(eDataType, initialValue);
104:•                } else if (E_FLOAT_OBJECT.equals(id)) {
105:                         return createEFloatObjectFromString(eDataType, initialValue);
106:•                } else if (E_INT.equals(id)) {
107:                         return createEIntFromString(eDataType, initialValue);
108:•                } else if (E_INTEGER_OBJECT.equals(id)) {
109:                         return createEIntegerObjectFromString(eDataType, initialValue);
110:•                } else if (E_JAVA_CLASS.equals(id)) {
111:                         return createEJavaClassFromString(eDataType, initialValue);
112:•                } else if (E_JAVA_OBJECT.equals(id)) {
113:                         return createEJavaObjectFromString(eDataType, initialValue);
114:•                } else if (E_LONG.equals(id)) {
115:                         return createELongFromString(eDataType, initialValue);
116:•                } else if (E_LONG_OBJECT.equals(id)) {
117:                         return createELongObjectFromString(eDataType, initialValue);
118:•                } else if (E_SHORT.equals(id)) {
119:                         return createEShortFromString(eDataType, initialValue);
120:•                } else if (E_SHORT_OBJECT.equals(id)) {
121:                         return createEShortObjectFromString(eDataType, initialValue);
122:•                } else if (E_STRING.equals(id)) {
123:                         return createEStringFromString(eDataType, initialValue);
124:                 }
125:                 return super.createFromString(eDataType, initialValue);
126:         }
127:
128:         // END COMPLEX CODE
129:
130:         @Override
131:         protected EObject basicCreate(EClass eClass) {
132:•                if (eClass.getInstanceClassName() == "java.util.Map$Entry") { //$NON-NLS-1$
133:                         return super.basicCreate(eClass);
134:                 }
135:                 // Create real objects instead of dynamic EObjects (like EFactory) because references to meta objects (e.g.
136:                 // EStructuralFeatures) can break the migration when they are dynamic EObjects.
137:                 final EObject eObject = EcoreFactory.eINSTANCE.create(eClass);
138:                 // Explicitly set the EClass because it is not set by default. When it is not set, .eClass() calls on the
139:                 // EObject fall back to the EClass in the registered Ecore EPackage. However, the migration might not use the
140:                 // registered EPackage. Thus, the EClass is set here.
141:                 BasicEObjectImpl.class.cast(eObject).eSetClass(eClass);
142:                 return eObject;
143:         }
144:
145:         private Boolean booleanValueOf(String initialValue) {
146:•                if ("true".equalsIgnoreCase(initialValue)) { //$NON-NLS-1$
147:                         return Boolean.TRUE;
148:•                } else if ("false".equalsIgnoreCase(initialValue)) { //$NON-NLS-1$
149:                         return Boolean.FALSE;
150:                 } else {
151:                         throw new IllegalArgumentException("Expecting true or false"); //$NON-NLS-1$
152:                 }
153:         }
154:
155:         private Boolean createEBooleanObjectFromString(EDataType metaObject,
156:                 String initialValue) {
157:•                return initialValue == null ? null : booleanValueOf(initialValue);
158:         }
159:
160:         private Character createECharacterObjectFromString(EDataType metaObject,
161:                 String initialValue) {
162:•                if (initialValue == null) {
163:                         return null;
164:                 }
165:
166:                 char charValue = 0;
167:                 try {
168:                         charValue = (char) Integer.parseInt(initialValue);
169:                 } catch (final NumberFormatException e) {
170:                         final char[] carray = initialValue.toCharArray();
171:                         charValue = carray[0];
172:                 }
173:                 return charValue;
174:         }
175:
176:         private Date createEDateFromString(EDataType eDataType, String initialValue) {
177:•                if (initialValue == null) {
178:                         return null;
179:                 }
180:
181:                 Exception exception = null;
182:•                for (int i = 0; i < EDATE_FORMATS.length; ++i) {
183:                         try {
184:                                 return EDATE_FORMATS[i].parse(initialValue);
185:                         } catch (final ParseException parseException) {
186:                                 exception = parseException;
187:                         }
188:                 }
189:                 throw new WrappedException(exception);
190:         }
191:
192:         private Double createEDoubleObjectFromString(EDataType metaObject,
193:                 String initialValue) {
194:•                return initialValue == null ? null : Double.valueOf(initialValue);
195:         }
196:
197:         private Float createEFloatObjectFromString(EDataType metaObject,
198:                 String initialValue) {
199:•                return initialValue == null ? null : Float.valueOf(initialValue);
200:         }
201:
202:         private Integer createEIntegerObjectFromString(EDataType metaObject,
203:                 String initialValue) {
204:•                return initialValue == null ? null : Integer.valueOf(initialValue);
205:         }
206:
207:         private BigDecimal createEBigDecimalFromString(EDataType eDataType,
208:                 String initialValue) {
209:•                return initialValue == null ? null : new BigDecimal(initialValue);
210:         }
211:
212:         private BigInteger createEBigIntegerFromString(EDataType eDataType,
213:                 String initialValue) {
214:•                return initialValue == null ? null : new BigInteger(initialValue);
215:         }
216:
217:         private String createEStringFromString(EDataType metaObject,
218:                 String initialValue) {
219:                 return initialValue;
220:         }
221:
222:         private Integer createEIntFromString(EDataType metaObject,
223:                 String initialValue) {
224:•                return initialValue == null ? null : Integer.valueOf(initialValue);
225:         }
226:
227:         private Boolean createEBooleanFromString(EDataType metaObject,
228:                 String initialValue) {
229:•                return initialValue == null ? null : booleanValueOf(initialValue);
230:         }
231:
232:         private Byte createEByteObjectFromString(EDataType metaObject,
233:                 String initialValue) {
234:•                return initialValue == null ? null : Byte.valueOf(initialValue);
235:         }
236:
237:         private Float createEFloatFromString(EDataType metaObject,
238:                 String initialValue) {
239:•                return initialValue == null ? null : Float.valueOf(initialValue);
240:         }
241:
242:         private Character createECharFromString(EDataType metaObject,
243:                 String initialValue) {
244:•                if (initialValue == null) {
245:                         return null;
246:                 }
247:                 char charValue = 0;
248:                 try {
249:                         charValue = (char) Integer.parseInt(initialValue);
250:                 } catch (final NumberFormatException e) {
251:                         final char[] carray = initialValue.toCharArray();
252:                         charValue = carray[0];
253:                 }
254:                 return charValue;
255:         }
256:
257:         private Long createELongFromString(EDataType metaObject, String initialValue) {
258:•                return initialValue == null ? null : Long.valueOf(initialValue);
259:         }
260:
261:         private Double createEDoubleFromString(EDataType metaObject,
262:                 String initialValue) {
263:•                return initialValue == null ? null : Double.valueOf(initialValue);
264:         }
265:
266:         private Byte createEByteFromString(EDataType metaObject, String initialValue) {
267:•                return initialValue == null ? null : Byte.valueOf(initialValue);
268:         }
269:
270:         private Short createEShortFromString(EDataType metaObject,
271:                 String initialValue) {
272:•                return initialValue == null ? null : Short.valueOf(initialValue);
273:         }
274:
275:         private Class<?> createEJavaClassFromString(EDataType metaObject,
276:                 String initialValue) {
277:                 try {
278:•                        if (initialValue == null) {
279:                                 return null;
280:•                        } else if ("boolean".equals(initialValue)) { //$NON-NLS-1$
281:                                 return boolean.class;
282:•                        } else if ("byte".equals(initialValue)) { //$NON-NLS-1$
283:                                 return byte.class;
284:•                        } else if ("char".equals(initialValue)) { //$NON-NLS-1$
285:                                 return char.class;
286:•                        } else if ("double".equals(initialValue)) { //$NON-NLS-1$
287:                                 return double.class;
288:•                        } else if ("float".equals(initialValue)) { //$NON-NLS-1$
289:                                 return float.class;
290:•                        } else if ("int".equals(initialValue)) { //$NON-NLS-1$
291:                                 return int.class;
292:•                        } else if ("long".equals(initialValue)) { //$NON-NLS-1$
293:                                 return long.class;
294:•                        } else if ("short".equals(initialValue)) { //$NON-NLS-1$
295:                                 return short.class;
296:                         } else {
297:                                 return Class.forName(initialValue);
298:                         }
299:                 } catch (final ClassNotFoundException e) {
300:                         throw new WrappedException(e);
301:                 }
302:         }
303:
304:         private Object createEJavaObjectFromString(EDataType eDataType,
305:                 String initialValue) {
306:                 return createFromString(initialValue);
307:         }
308:
309:         private Long createELongObjectFromString(EDataType metaObject,
310:                 String initialValue) {
311:•                return initialValue == null ? null : Long.valueOf(initialValue);
312:         }
313:
314:         private Short createEShortObjectFromString(EDataType metaObject,
315:                 String initialValue) {
316:•                return initialValue == null ? null : Short.valueOf(initialValue);
317:         }
318:
319:         private byte[] createEByteArrayFromString(EDataType eDataType,
320:                 String initialValue) {
321:                 return hexStringToByteArray(initialValue);
322:         }
323:
324:         private byte[] hexStringToByteArray(String initialValue) {
325:•                if (initialValue == null) {
326:                         return null;
327:                 }
328:
329:                 final int size = initialValue.length();
330:                 int limit = (size + 1) / 2;
331:                 final byte[] result = new byte[limit];
332:•                if (size % 2 != 0) {
333:                         result[--limit] = hexCharToByte(initialValue.charAt(size - 1));
334:                 }
335:
336:•                for (int i = 0, j = 0; i < limit; ++i) {
337:                         final byte high = hexCharToByte(initialValue.charAt(j++));
338:                         final byte low = hexCharToByte(initialValue.charAt(j++));
339:                         result[i] = (byte) (high << 4 | low);
340:                 }
341:                 return result;
342:         }
343:
344:         // BEGIN COMPLEX CODE
345:         private byte hexCharToByte(char character) {
346:•                switch (character) {
347:                 case '0':
348:                 case '1':
349:                 case '2':
350:                 case '3':
351:                 case '4':
352:                 case '5':
353:                 case '6':
354:                 case '7':
355:                 case '8':
356:                 case '9': {
357:                         return (byte) (character - '0');
358:                 }
359:                 case 'a':
360:                 case 'b':
361:                 case 'c':
362:                 case 'd':
363:                 case 'e':
364:                 case 'f': {
365:                         return (byte) (character - 'a' + 10);
366:                 }
367:                 case 'A':
368:                 case 'B':
369:                 case 'C':
370:                 case 'D':
371:                 case 'E':
372:                 case 'F': {
373:                         return (byte) (character - 'A' + 10);
374:                 }
375:                 default: {
376:                         throw new NumberFormatException("Invalid hexadecimal"); //$NON-NLS-1$
377:                 }
378:                 }
379:         }
380:
381:         // END COMPLEX CODE
382:
383:         // BEGIN COMPLEX CODE
384:         @Override
385:         public String convertToString(EDataType eDataType, Object instanceValue) {
386:
387:                 final String id = eDataType.getName();
388:
389:•                if (E_BIG_DECIMAL.equals(id)) {
390:                         return convertEBigDecimalToString(eDataType, instanceValue);
391:•                } else if (E_BIG_INTEGER.equals(id)) {
392:                         return convertEBigIntegerToString(eDataType, instanceValue);
393:•                } else if (E_BOOLEAN.equals(id)) {
394:                         return convertEBooleanToString(eDataType, instanceValue);
395:•                } else if (E_BOOLEAN_OBJECT.equals(id)) {
396:                         return convertEBooleanObjectToString(eDataType, instanceValue);
397:•                } else if (E_BYTE.equals(id)) {
398:                         return convertEByteToString(eDataType, instanceValue);
399:•                } else if (E_BYTE_ARRAY.equals(id)) {
400:                         return convertEByteArrayToString(eDataType, instanceValue);
401:•                } else if (E_BYTE_OBJECT.equals(id)) {
402:                         return convertEByteObjectToString(eDataType, instanceValue);
403:•                } else if (E_CHAR.equals(id)) {
404:                         return convertECharToString(eDataType, instanceValue);
405:•                } else if (E_CHARACTER_OBJECT.equals(id)) {
406:                         return convertECharacterObjectToString(eDataType, instanceValue);
407:•                } else if (E_DATE.equals(id)) {
408:                         return convertEDateToString(eDataType, instanceValue);
409:•                } else if (E_DOUBLE.equals(id)) {
410:                         return convertEDoubleToString(eDataType, instanceValue);
411:•                } else if (E_DOUBLE_OBJECT.equals(id)) {
412:                         return convertEDoubleObjectToString(eDataType, instanceValue);
413:•                } else if (E_FLOAT.equals(id)) {
414:                         return convertEFloatToString(eDataType, instanceValue);
415:•                } else if (E_FLOAT_OBJECT.equals(id)) {
416:                         return convertEFloatObjectToString(eDataType, instanceValue);
417:•                } else if (E_INT.equals(id)) {
418:                         return convertEIntToString(eDataType, instanceValue);
419:•                } else if (E_INTEGER_OBJECT.equals(id)) {
420:                         return convertEIntegerObjectToString(eDataType, instanceValue);
421:•                } else if (E_JAVA_CLASS.equals(id)) {
422:                         return convertEJavaClassToString(eDataType, instanceValue);
423:•                } else if (E_JAVA_OBJECT.equals(id)) {
424:                         return convertEJavaObjectToString(eDataType, instanceValue);
425:•                } else if (E_LONG.equals(id)) {
426:                         return convertELongToString(eDataType, instanceValue);
427:•                } else if (E_LONG_OBJECT.equals(id)) {
428:                         return convertELongObjectToString(eDataType, instanceValue);
429:•                } else if (E_SHORT.equals(id)) {
430:                         return convertEShortToString(eDataType, instanceValue);
431:•                } else if (E_SHORT_OBJECT.equals(id)) {
432:                         return convertEShortObjectToString(eDataType, instanceValue);
433:•                } else if (E_STRING.equals(id)) {
434:                         return convertEStringToString(eDataType, instanceValue);
435:                 }
436:                 return super.convertToString(eDataType, instanceValue);
437:         }
438:
439:         // END COMPLEX CODE
440:
441:         private String convertEBooleanObjectToString(EDataType metaObject, Object instanceValue) {
442:•                return instanceValue == null ? null : instanceValue.toString();
443:         }
444:
445:         private String convertECharacterObjectToString(EDataType metaObject, Object instanceValue) {
446:•                if (instanceValue instanceof Character) {
447:                         return Integer.toString((Character) instanceValue);
448:                 }
449:
450:•                return instanceValue == null ? null : instanceValue.toString();
451:         }
452:
453:         private String convertEDateToString(EDataType eDataType, Object instanceValue) {
454:•                if (instanceValue == null) {
455:                         return null;
456:                 }
457:
458:                 return EDATE_FORMATS[0].format((Date) instanceValue);
459:
460:         }
461:
462:         private String convertEDoubleObjectToString(EDataType metaObject, Object instanceValue) {
463:•                return instanceValue == null ? null : instanceValue.toString();
464:         }
465:
466:         private String convertEFloatObjectToString(EDataType metaObject, Object instanceValue) {
467:•                return instanceValue == null ? null : instanceValue.toString();
468:         }
469:
470:         private String convertEIntegerObjectToString(EDataType metaObject, Object instanceValue) {
471:•                return instanceValue == null ? null : instanceValue.toString();
472:         }
473:
474:         private String convertEBigDecimalToString(EDataType eDataType, Object instanceValue) {
475:•                return instanceValue == null ? null : instanceValue.toString();
476:         }
477:
478:         private String convertEBigIntegerToString(EDataType eDataType, Object instanceValue) {
479:•                return instanceValue == null ? null : instanceValue.toString();
480:         }
481:
482:         private String convertEStringToString(EDataType metaObject, Object instanceValue) {
483:                 return (String) instanceValue;
484:         }
485:
486:         private String convertEIntToString(EDataType metaObject, Object instanceValue) {
487:•                return instanceValue == null ? null : instanceValue.toString();
488:         }
489:
490:         private String convertEBooleanToString(EDataType metaObject, Object instanceValue) {
491:•                return instanceValue == null ? null : instanceValue.toString();
492:         }
493:
494:         private String convertEByteObjectToString(EDataType metaObject, Object instanceValue) {
495:•                return instanceValue == null ? null : instanceValue.toString();
496:         }
497:
498:         private String convertEFloatToString(EDataType metaObject, Object instanceValue) {
499:•                return instanceValue == null ? null : instanceValue.toString();
500:         }
501:
502:         private String convertECharToString(EDataType metaObject, Object instanceValue) {
503:•                if (instanceValue instanceof Character) {
504:                         return Integer.toString((Character) instanceValue);
505:                 }
506:
507:•                return instanceValue == null ? null : instanceValue.toString();
508:         }
509:
510:         private String convertELongToString(EDataType metaObject, Object instanceValue) {
511:•                return instanceValue == null ? null : instanceValue.toString();
512:         }
513:
514:         private String convertEDoubleToString(EDataType metaObject, Object instanceValue) {
515:•                return instanceValue == null ? null : instanceValue.toString();
516:         }
517:
518:         private String convertEByteToString(EDataType metaObject, Object instanceValue) {
519:•                return instanceValue == null ? null : instanceValue.toString();
520:         }
521:
522:         private String convertEByteArrayToString(EDataType eDataType, Object instanceValue) {
523:•                if (instanceValue == null) {
524:                         return null;
525:                 }
526:                 final byte[] bytes = (byte[]) instanceValue;
527:                 return convertBytesToHexString(bytes, bytes.length);
528:
529:         }
530:
531:         private String convertEShortToString(EDataType metaObject, Object instanceValue) {
532:•                return instanceValue == null ? null : instanceValue.toString();
533:         }
534:
535:         private String convertEJavaClassToString(EDataType metaObject, Object instanceValue) {
536:•                return instanceValue == null ? "" : ((Class<?>) instanceValue).getName(); //$NON-NLS-1$
537:         }
538:
539:         private String convertEJavaObjectToString(EDataType eDataType, Object instanceValue) {
540:                 return convertToString(instanceValue);
541:         }
542:
543:         private String convertELongObjectToString(EDataType metaObject, Object instanceValue) {
544:•                return instanceValue == null ? null : instanceValue.toString();
545:         }
546:
547:         private String convertEShortObjectToString(EDataType metaObject, Object instanceValue) {
548:•                return instanceValue == null ? null : instanceValue.toString();
549:         }
550:
551:         private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
552:                 'E', 'F' };
553:
554:         private String convertBytesToHexString(byte[] bytes, int count) {
555:•                if (bytes == null) {
556:                         return null;
557:                 }
558:                 final char[] result = new char[2 * count];
559:•                for (int i = 0, j = 0; i < count; ++i) {
560:                         final int high = bytes[i] >> 4 & 0xF;
561:                         final int low = bytes[i] & 0xF;
562:                         result[j++] = HEX_DIGITS[high];
563:                         result[j++] = HEX_DIGITS[low];
564:                 }
565:                 return new String(result);
566:
567:         }
568:
569: }