Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Wrapping character values using SimleAnyType
Wrapping character values using SimleAnyType [message #423340] Mon, 29 September 2008 08:15 Go to next message
Mario Winterer is currently offline Mario WintererFriend
Messages: 136
Registered: July 2009
Senior Member
Hi!

Is it possible to wrap a character value into a SimpleAnyType?
There seems to be no meta data object for data type character in
XMLTypePackage.

At the moment this is what I'm doing:

input: Object value
output: SimpleAnyType that wraps the value

EDataType dataType = null;
Class<?> clazz = EcoreUtil.wrapperClassFor(value.getClass());
if (clazz == Boolean.class) {
dataType = XMLTypePackage.eINSTANCE.getBooleanObject();
} else if (clazz == Character.class) {
dataType = EcorePackage.eINSTANCE.get
} else if (clazz == Byte.class) {
dataType = XMLTypePackage.eINSTANCE.getByteObject();
} else if (clazz == Short.class) {
dataType = XMLTypePackage.eINSTANCE.getShortObject();
} else if (clazz == Integer.class) {
dataType = XMLTypePackage.eINSTANCE.getIntObject();
} else if (clazz == Long.class) {
dataType = XMLTypePackage.eINSTANCE.getLongObject();
} else if (clazz == Float.class) {
dataType = XMLTypePackage.eINSTANCE.getFloatObject();
} else if (clazz == Double.class) {
dataType = XMLTypePackage.eINSTANCE.getDoubleObject();
} else if (clazz == String.class) {
dataType = XMLTypePackage.eINSTANCE.getString();
} else if (clazz == Date.class) {
dataType = XMLTypePackage.eINSTANCE.getDateTime();
} else if (clazz == BigDecimal.class) {
dataType = XMLTypePackage.eINSTANCE.getDecimal();
} else if (clazz == BigInteger.class) {
dataType = XMLTypePackage.eINSTANCE.getInteger();
}

SimpleAnyType simpleType = XMLTypeFactory.eINSTANCE.createSimpleAnyType();
simpleType.setInstanceType(dataType);
simpleType.setValue(value);

return simpleType;
Re: Wrapping character values using SimleAnyType [message #423351 is a reply to message #423340] Mon, 29 September 2008 12:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30804
Registered: July 2009
Senior Member
Mario,

XML Schema doesn't have a character data type. But you could use
EcorePackage.Literals.ECHAR_OBJECT. Note that
XMLTypePackage.Literals.BOOLEAN_OBJECT would be more efficient to access
than the getter methods...

Mario Winterer wrote:
> Hi!
>
> Is it possible to wrap a character value into a SimpleAnyType?
> There seems to be no meta data object for data type character in
> XMLTypePackage.
>
> At the moment this is what I'm doing:
>
> input: Object value
> output: SimpleAnyType that wraps the value
>
> EDataType dataType = null;
> Class<?> clazz = EcoreUtil.wrapperClassFor(value.getClass());
> if (clazz == Boolean.class) {
> dataType = XMLTypePackage.eINSTANCE.getBooleanObject();
> } else if (clazz == Character.class) {
> dataType = EcorePackage.eINSTANCE.get
> } else if (clazz == Byte.class) {
> dataType = XMLTypePackage.eINSTANCE.getByteObject();
> } else if (clazz == Short.class) {
> dataType = XMLTypePackage.eINSTANCE.getShortObject();
> } else if (clazz == Integer.class) {
> dataType = XMLTypePackage.eINSTANCE.getIntObject();
> } else if (clazz == Long.class) {
> dataType = XMLTypePackage.eINSTANCE.getLongObject();
> } else if (clazz == Float.class) {
> dataType = XMLTypePackage.eINSTANCE.getFloatObject();
> } else if (clazz == Double.class) {
> dataType = XMLTypePackage.eINSTANCE.getDoubleObject();
> } else if (clazz == String.class) {
> dataType = XMLTypePackage.eINSTANCE.getString();
> } else if (clazz == Date.class) {
> dataType = XMLTypePackage.eINSTANCE.getDateTime();
> } else if (clazz == BigDecimal.class) {
> dataType = XMLTypePackage.eINSTANCE.getDecimal();
> } else if (clazz == BigInteger.class) {
> dataType = XMLTypePackage.eINSTANCE.getInteger();
> }
>
> SimpleAnyType simpleType =
> XMLTypeFactory.eINSTANCE.createSimpleAnyType();
> simpleType.setInstanceType(dataType);
> simpleType.setValue(value);
>
> return simpleType;
Previous Topic:Programatically refactoring ecore models
Next Topic:How to extract the corresponding XML for an EObject.
Goto Forum:
  


Current Time: Mon Jan 20 12:19:30 GMT 2020

Powered by FUDForum. Page generated in 0.02206 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top