|
Re: EMF Support for xsd:whitespace [message #1065321 is a reply to message #1065314] |
Tue, 25 June 2013 10:17 |
Ed Merks Messages: 33139 Registered: July 2009 |
Senior Member |
|
|
Rob,
The only place it's considered is in
org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EDataType,
String), i.e., when creating a value instance from a literal
representation. E.g., when reading in from XML, the values are
normalized as specified by the white space facet. Another example, when
entering values in the properties view, the same factory methods are
used to convert what's entered by the user to an instance of the type.
If you set the instance values programmatically, none of that occurs.
On 25/06/2013 12:07 PM, Rob Mising name wrote:
> Hi Ed,
>
> I would really appreciate your opinion and assistance with the following.
>
> I have been looking at support for xsd:whitespace
>
> http://www.w3.org/TR/xmlschema-2/#dt-whiteSpace
> http://www.w3schools.com/schema/schema_facets.asp
>
> It looks like EMF persists the existance of xsd:whitespace into the
> eCore, but it doesn't appear to "act on it".
>
> My understanding is that the string retrieved via the "get" methods
> should return the "processed" string, (i.e. the white space
> removed/collapsed) as I would view this as the "XML processor" which
> has the responsibility for performing this action.
>
> Thus allowing something like:
> Object1.getWhitespaceString().equals(Object2.getWhitespaceString())
> To return true, if the strings were only different in terms of
> whitespace.
>
> I have spent some time with the Jet Templates and I believe this may
> be easy to achieve by creating the include file:
> "getGenFeature.pre.insert.javajetinc" and adding the following code
> into it:
>
> <%if (genFeature.getTypeGenDataType() != null) {%>
> <%if
> ("collapse".equals(genFeature.getTypeGenDataType().getWhiteSpace())) {%>
> // Collapse white space
> <%=genFeature.getSafeName()%> =
> <%=genFeature.getSafeName()%>.trim().replaceAll("\\s+", " ");
> <%} else if
> ("replace".equals(genFeature.getTypeGenDataType().getWhiteSpace())) {%>
> // Replace white space
> <%=genFeature.getSafeName()%> =
> <%=genFeature.getSafeName()%>.trim().replaceAll("\\s", " ");
> <%}%>
> <%}%>
>
> I am wondering if it would in fact be better to do this conversion in
> the set method rather than the get?
>
> I would really like to hear your thoughts on all of this
> xsd:whitespace area.
>
> Thanks
>
> Rob
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: EMF Support for xsd:whitespace [message #1065345 is a reply to message #1065332] |
Tue, 25 June 2013 11:25 |
Ed Merks Messages: 33139 Registered: July 2009 |
Senior Member |
|
|
Rob,
There is no other case where we transform the value passed in to a
setter, so calling getX will always yield the value you passed in for
setX. Even in XML Schema, its not as if the spaces are not allowed,
they're just normalized during semantic processing.
I don't foresee any significant framework problems with the template
changes you showed, other the fact you're not testing if the argument is
null. To make it fully general, you'd have to consider the handling of
multi-valued attributes, but probably you don't have that case (and in
XML schema, it's an odd case anyway, given that white space is used to
separate list items)...
On 25/06/2013 12:58 PM, Rob Mising name wrote:
> Hi Ed,
>
> Thanks for the fast reply!
>
> May I ask if there was any particular reason why it wasn't converted
> when the set method was called programatically?
>
> And in your opinion do you think it would be safe for me to do this
> conversion in our templates for the set method (From what you
> highlighted, I believe the set would be the most appropriate place for
> us to perform this).
>
> Thanks
>
> Rob
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03164 seconds