001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.providers;
025:
026: import org.eclipse.emf.ecore.EAttribute;
027: import org.eclipse.emf.ecore.EDataType;
028: import org.eclipse.emf.ecore.EEnum;
029: import org.eclipse.emf.ecore.EEnumLiteral;
030:
031: /**
032: * @generated
033: */
034: public abstract class ComponentFlowEditorAbstractParser {
035: /**
036: * @generated
037: */
038: public static Object parseValue(EAttribute feature, Object value)
039: throws IllegalArgumentException {
040: if (value == null) {
041: throw new IllegalArgumentException();
042: }
043: EDataType type = feature.getEAttributeType();
044: Class iClass = type.getInstanceClass();
045: if (Boolean.TYPE.equals(iClass) || Boolean.class.equals(iClass)) {
046: if (value instanceof Boolean) {
047: // ok
048: } else if (value instanceof String) {
049: value = Boolean.valueOf((String) value);
050: } else {
051: throw new IllegalArgumentException(
052: "Value of type Boolean is expected");
053: }
054: } else if (Character.TYPE.equals(iClass)
055: || Character.class.equals(iClass)) {
056: if (value instanceof Character) {
057: // ok
058: } else if (value instanceof String) {
059: String s = (String) value;
060: if (s.length() == 0) {
061: throw new IllegalArgumentException(); //XXX: ?
062: } else {
063: value = new Character(s.charAt(0));
064: }
065: } else {
066: throw new IllegalArgumentException(
067: "Value of type Character is expected");
068: }
069: } else if (Byte.TYPE.equals(iClass)
070: || Byte.class.equals(iClass)) {
071: if (value instanceof Byte) {
072: // ok
073: } else if (value instanceof Number) {
074: value = new Byte(((Number) value).byteValue());
075: } else if (value instanceof String) {
076: String s = (String) value;
077: if (s.length() == 0) {
078: value = null;
079: } else {
080: try {
081: value = Byte.valueOf(s);
082: } catch (NumberFormatException nfe) {
083: throw new IllegalArgumentException(
084: "String value does not convert to Byte value");
085: }
086: }
087: } else {
088: throw new IllegalArgumentException(
089: "Value of type Byte is expected");
090: }
091: } else if (Short.TYPE.equals(iClass)
092: || Short.class.equals(iClass)) {
093: if (value instanceof Short) {
094: // ok
095: } else if (value instanceof Number) {
096: value = new Short(((Number) value).shortValue());
097: } else if (value instanceof String) {
098: String s = (String) value;
099: if (s.length() == 0) {
100: value = null;
101: } else {
102: try {
103: value = Short.valueOf(s);
104: } catch (NumberFormatException nfe) {
105: throw new IllegalArgumentException(
106: "String value does not convert to Short value");
107: }
108: }
109: } else {
110: throw new IllegalArgumentException(
111: "Value of type Short is expected");
112: }
113: } else if (Integer.TYPE.equals(iClass)
114: || Integer.class.equals(iClass)) {
115: if (value instanceof Integer) {
116: // ok
117: } else if (value instanceof Number) {
118: value = new Integer(((Number) value).intValue());
119: } else if (value instanceof String) {
120: String s = (String) value;
121: if (s.length() == 0) {
122: value = null;
123: } else {
124: try {
125: value = Integer.valueOf(s);
126: } catch (NumberFormatException nfe) {
127: throw new IllegalArgumentException(
128: "String value does not convert to Integer value");
129: }
130: }
131: } else {
132: throw new IllegalArgumentException(
133: "Value of type Integer is expected");
134: }
135: } else if (Long.TYPE.equals(iClass)
136: || Long.class.equals(iClass)) {
137: if (value instanceof Long) {
138: // ok
139: } else if (value instanceof Number) {
140: value = new Long(((Number) value).longValue());
141: } else if (value instanceof String) {
142: String s = (String) value;
143: if (s.length() == 0) {
144: value = null;
145: } else {
146: try {
147: value = Long.valueOf(s);
148: } catch (NumberFormatException nfe) {
149: throw new IllegalArgumentException(
150: "String value does not convert to Long value");
151: }
152: }
153: } else {
154: throw new IllegalArgumentException(
155: "Value of type Long is expected");
156: }
157: } else if (Float.TYPE.equals(iClass)
158: || Float.class.equals(iClass)) {
159: if (value instanceof Float) {
160: // ok
161: } else if (value instanceof Number) {
162: value = new Float(((Number) value).floatValue());
163: } else if (value instanceof String) {
164: String s = (String) value;
165: if (s.length() == 0) {
166: value = null;
167: } else {
168: try {
169: value = Float.valueOf(s);
170: } catch (NumberFormatException nfe) {
171: throw new IllegalArgumentException(
172: "String value does not convert to Float value");
173: }
174: }
175: } else {
176: throw new IllegalArgumentException(
177: "Value of type Float is expected");
178: }
179: } else if (Double.TYPE.equals(iClass)
180: || Double.class.equals(iClass)) {
181: if (value instanceof Double) {
182: // ok
183: } else if (value instanceof Number) {
184: value = new Double(((Number) value).doubleValue());
185: } else if (value instanceof String) {
186: String s = (String) value;
187: if (s.length() == 0) {
188: value = null;
189: } else {
190: try {
191: value = Double.valueOf(s);
192: } catch (NumberFormatException nfe) {
193: throw new IllegalArgumentException(
194: "String value does not convert to Double value");
195: }
196: }
197: } else {
198: throw new IllegalArgumentException(
199: "Value of type Double is expected");
200: }
201: } else if (String.class.equals(iClass)) {
202: value = String.valueOf(value);
203: } else if (type instanceof EEnum) {
204: if (value instanceof String) {
205: EEnumLiteral literal = ((EEnum) type)
206: .getEEnumLiteralByLiteral((String) value);
207: if (literal == null) {
208: throw new IllegalArgumentException(
209: "Unknown literal: " + value);
210: } else {
211: value = literal.getInstance();
212: }
213: } else {
214: throw new IllegalArgumentException(
215: "Value of type String is expected");
216: }
217: } else {
218: throw new IllegalArgumentException("Unsupported type");
219: }
220: return value;
221: }
222: }
|