Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity
XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity [message #899277] Tue, 31 July 2012 10:12 Go to next message
Martin Weiss is currently offline Martin WeissFriend
Messages: 9
Registered: July 2012
Junior Member
Hello world,

I use EMF for some kind of technical data editor where i have to support infinite numeric values. XMLTypeFactoryImpl however doesn't support the schema compliant representations of infinite values INF and -INF, it uses Infinity and -Infinity instead: The XML generated by EMF is invalid according to schema rules.

The only solution I found so far is to get the XMLTypePackage from the global package registry and set a new custom XMLTypeFactory for it.

Is this a bug or do I miss something?
Re: XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity [message #899428 is a reply to message #899277] Tue, 31 July 2012 18:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Martin,

Comments below.
On 31/07/2012 12:12 PM, Martin Weiss wrote:
> Hello world,
>
> I use EMF for some kind of technical data editor where i have to
> support infinite numeric values. XMLTypeFactoryImpl however doesn't
> support the schema compliant representations of infinite values INF
> and -INF, it uses Infinity and -Infinity instead: The XML generated by
> EMF is invalid according to schema rules.
Hmmm, yes I fixed this in the XSD models literal conversion but I should
have fixed it in XMLTypeFactoryImpl as well (and I need to be careful
that I accept the old syntax so I don't break clients relying on the old
arguably broken behavior).
>
> The only solution I found so far is to get the XMLTypePackage from the
> global package registry and set a new custom XMLTypeFactory for it.
>
> Is this a bug or do I miss something?
Yes it looks like a bug. Please open a bugzilla.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity [message #899515 is a reply to message #899428] Wed, 01 August 2012 09:16 Go to previous messageGo to next message
Martin Weiss is currently offline Martin WeissFriend
Messages: 9
Registered: July 2012
Junior Member
Hi Ed,

I created a bug report. For anyone interested, here's my workaround. It still allows loading of documents that use the non-compliant representation but of course can't save them. Maybe a factory configuration option would be a way to retain the old behavior?

// ATTENTION: In order to support double or float infinity we have to replace the
// global default XMLTypePackageImpl in the registry with a custom implementation.
XMLTypePackage xmlTypePkg = (XMLTypePackage) EPackage.Registry.INSTANCE.get(XMLTypePackageImpl.eNS_URI);
xmlTypePkg.setEFactoryInstance(new XMLTypeFactoryImpl() {
	@Override
	public Double createDoubleObject(String literal) {
		if ("INF".equals(collapseWhiteSpace(literal))) {
			return Double.POSITIVE_INFINITY;
		}
		if ("-INF".equals(collapseWhiteSpace(literal))) {
			return Double.NEGATIVE_INFINITY;
		}
		return super.createDoubleObject(literal);
	}
	
	@Override
	public Float createFloatObject(String literal) {
		if ("INF".equals(collapseWhiteSpace(literal))) {
			return Float.POSITIVE_INFINITY;
		}
		if ("-INF".equals(collapseWhiteSpace(literal))) {
			return Float.NEGATIVE_INFINITY;
		}
		return super.createFloatObject(literal);
	}
			
	@Override
	public String convertDoubleToString(EDataType eDataType, Object instanceValue) {
		if (Double.valueOf(Double.POSITIVE_INFINITY).equals(instanceValue)) {
			return "INF";
		}
		if (Double.valueOf(Double.NEGATIVE_INFINITY).equals(instanceValue)) {
			return "-INF";
		}
		return super.convertDoubleToString(eDataType, instanceValue);
	}
	
	@Override
	public String convertFloatToString(EDataType eDataType, Object instanceValue) {
		if (Float.valueOf(Float.POSITIVE_INFINITY).equals(instanceValue)) {
			return "INF";
		}
		if (Float.valueOf(Float.NEGATIVE_INFINITY).equals(instanceValue)) {
			return "-INF";
		}
		return super.convertToString(eDataType, instanceValue);
	}
});

Re: XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity [message #899759 is a reply to message #899515] Thu, 02 August 2012 08:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Martin,

This looks good. The four calls to valueOf could be optimized by storing
that value as a static final constant...


On 01/08/2012 11:16 AM, Martin Weiss wrote:
> Hi Ed,
>
> I created a bug report. For anyone interested, here's my workaround.
> It still allows loading of documents that use the non-compliant
> representation but of course can't save them. Maybe a factory
> configuration option would be a way to retain the old behavior?
>
>
> // ATTENTION: In order to support double or float infinity we have to
> replace the
> // global default XMLTypePackageImpl in the registry with a custom
> implementation.
> XMLTypePackage xmlTypePkg = (XMLTypePackage)
> EPackage.Registry.INSTANCE.get(XMLTypePackageImpl.eNS_URI);
> xmlTypePkg.setEFactoryInstance(new XMLTypeFactoryImpl() {
> @Override
> public Double createDoubleObject(String literal) {
> if ("INF".equals(collapseWhiteSpace(literal))) {
> return Double.POSITIVE_INFINITY;
> }
> if ("-INF".equals(collapseWhiteSpace(literal))) {
> return Double.NEGATIVE_INFINITY;
> }
> return super.createDoubleObject(literal);
> }
>
> @Override
> public Float createFloatObject(String literal) {
> if ("INF".equals(collapseWhiteSpace(literal))) {
> return Float.POSITIVE_INFINITY;
> }
> if ("-INF".equals(collapseWhiteSpace(literal))) {
> return Float.NEGATIVE_INFINITY;
> }
> return super.createFloatObject(literal);
> }
>
> @Override
> public String convertDoubleToString(EDataType eDataType, Object
> instanceValue) {
> if
> (Double.valueOf(Double.POSITIVE_INFINITY).equals(instanceValue)) {
> return "INF";
> }
> if
> (Double.valueOf(Double.NEGATIVE_INFINITY).equals(instanceValue)) {
> return "-INF";
> }
> return super.convertDoubleToString(eDataType, instanceValue);
> }
>
> @Override
> public String convertFloatToString(EDataType eDataType, Object
> instanceValue) {
> if
> (Float.valueOf(Float.POSITIVE_INFINITY).equals(instanceValue)) {
> return "INF";
> }
> if
> (Float.valueOf(Float.NEGATIVE_INFINITY).equals(instanceValue)) {
> return "-INF";
> }
> return super.convertToString(eDataType, instanceValue);
> }
> });
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity [message #900359 is a reply to message #899759] Mon, 06 August 2012 15:36 Go to previous messageGo to next message
Martin Weiss is currently offline Martin WeissFriend
Messages: 9
Registered: July 2012
Junior Member
Hi Ed,

Ed Merks wrote on Thu, 02 August 2012 04:44

The four calls to valueOf could be optimized by storing
that value as a static final constant...


great idea, thanks!

I noticed there are more conversion methods in XMLTypeFactory:
String convertFloat(float instanceValue);
String convertDouble(double instanceValue);
String convertFloatObject(Float instanceValue);
String convertDoubleObject(Double instanceValue);

It seems these are never called during loading or saving the model. What are these methods for? Do I have to override them, too?

[Updated on: Mon, 06 August 2012 15:37]

Report message to a moderator

Re: XMLTypeFactoryImpl doesn't support XSD compliant representations of infinity [message #900446 is a reply to message #900359] Tue, 07 August 2012 07:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Martin,

XMLTypeFactory is generated with Data Type Converters set to true, so it
generates a full API for all data types, including the primitives. When
reflection is used, all values are passed around as objects, so
primitives are wrapped. Therefore you won't see these methods used
directly by the framework, only when clients call them directly in their
hand written code.

On 06/08/2012 5:36 PM, Martin Weiss wrote:
> Hi Ed,
>
> Ed Merks wrote on Thu, 02 August 2012 04:44
>> The four calls to valueOf could be optimized by storing that value as
>> a static final constant...
>
>
> great idea, thanks!
>
> I noticed there are more conversion methods in XMLTypeFactory:
>
> String convertFloat(float instanceValue);
> String convertDouble(double instanceValue);
> String convertFloatObject(Float instanceValue);
> String convertDoubleObject(Double instanceValue)
>
> It seems these are never called during loading or saving the model.
> What are these methods for? Do I have to override them, too?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF Code generation problem
Next Topic:[EMF] [CommandStack] Best Practices to use ChangeCommand around UI Dialog
Goto Forum:
  


Current Time: Fri Apr 19 20:45:44 GMT 2024

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

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

Back to the top