Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Invalid names when reverse engineering XML schema(Need to use invalid names)
Invalid names when reverse engineering XML schema [message #1716044] Mon, 30 November 2015 20:08 Go to next message
Humberto Carvalho is currently offline Humberto CarvalhoFriend
Messages: 6
Registered: September 2013
Junior Member
Hello !

I'm looking to reverse engineer the ofbiz entity xml model to an ecore model. The reason for this is that i want to create my own ecore model and later map it to the ofbiz entity model using ATL.

The entity model xml schema is located here:
ofbiz.apache.org/dtds/entitymodel.xsd


I have successfully reverse engineered the model, however I've noticed that it changes the names of some attributes, which are invalid.

For example, the name 'entity-name' is changed to entityName. Additionally, the XML description xml tag stops being a stand alone tag and becomes an attribute of the parent node.

This is demonstrated in the screenshot i've attached, below we have a valid ofbiz entity model, with the correct 'entity-name' attribute inside the entity tag, and also the correct description tag.

Above the editor, we have the generated output from my model to the reverse engineered ecore model via an ATL transformation. Notice it is incorrect because the entity-name tag attribute inside entity has been changed to entityName, and the description xml tag is now an attribute.

How could i fix this ?

Thank you for your time!
Best Regards,
Humberto Carvalho

[Updated on: Mon, 30 November 2015 20:09]

Report message to a moderator

Re: Invalid names when reverse engineering XML schema [message #1716081 is a reply to message #1716044] Tue, 01 December 2015 07:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Humberto,

Comments below.

On 30/11/2015 9:08 PM, Humberto Carvalho wrote:
> Hello !
>
> I'm looking to reverse engineer the ofbiz entity xml model to an ecore model. The reason for this is that i want to create my own ecore model and later map it to the ofbiz entity model using ATL.
>
> The entity model xml schema is located here:
> ofbiz.apache.org/dtds/entitymodel.xsd
>
> I have successfully reverse engineered the model, however I've noticed that it changes the names of some attributes, which are invalid.
>
> For example, the name 'entity-name' is changed to entityName.
The original XML names are recorded as annotations. They can be
accessed, using ExtendedMetaData, e.g.,
ExtendedMetaData.INSTANCE.getName(eStructuralFeature).
> Additionally, the XML description xml tag stops being a stand alone tag and becomes an attribute of the parent node.
Yes, elements and attributes of simple type map to EAttributes.
>
> This is demonstrated in the screenshot i've attached, below we have a valid ofbiz entity model, with the correct 'entity-name' attribute inside the entity tag, and also the correct description tag.
>
> Above the editor, we have the generated output from my model to the reverse engineered ecore model via an ATL transformation. Notice it is incorrect because the entity-name tag attribute inside entity has been changed to entityName, and the description xml tag is now an attribute.
It's using an XMI serialization.
>
> How could i fix this ?
Are you generating a model for this? Even if not, try generating a
model for it and look at the generated XyzResourceFactoryImpl. You'll
want to register a resource factory that creates resources with these
load and save options if you want the serialization to conform to the
original XML Schema.
>
> Thank you for your time!
> Best Regards,
> Humberto Carvalho


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Invalid names when reverse engineering XML schema [message #1716166 is a reply to message #1716081] Tue, 01 December 2015 20:35 Go to previous messageGo to next message
Humberto Carvalho is currently offline Humberto CarvalhoFriend
Messages: 6
Registered: September 2013
Junior Member
Hi Ed Merks, thank you for you reply!

I've generated the model for the OfbizEntity model, and added the following code to the EntityModelResourceFactoryImpl.java

result.getDefaultLoadOptions().put(XMLResource.OPTION_RECORD_ANY_TYPE_NAMESPACE_DECLARATIONS, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_RECORD_ANY_TYPE_NAMESPACE_DECLARATIONS, Boolean.TRUE);


If i generate an instance of this ecore model via the generated editor, the outputted code is correct.

However, the ATL transformation from:

MY_MODEL (named EntityFramework) ----> OFBIZ_ENTITY_MODEL (named EntityModel)

is still incorrect.

Here is the ATL transformation code:

-- @path EntityFramework=/EntityFramework/model/entityFramework.ecore
-- @path EntityModel=/OfbizEntityModel/model/Entitymodel.ecore

module EntityFrameworkToOfbizService;
create OUT : EntityModel from IN : EntityFramework;
rule EFEntity2EMEntity {
	from
		s: EntityFramework!Entity
	to
		t: EntityModel!EntityType(
			entityName <- s.name,
			description  <- s.description,
			packageName <- s.package.name,
			field <- s.atributes
		)
}


Here is the output:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Entitymodel:EntitymodelType xmi:version="2.0" xmlns:xmi="www.omg.org/XMI" xmlns:Entitymodel="ofbiz.apache.org/dtds/entitymodel.xsd">
  <entity description="The memorix TextNote entity." entityName="TextNote">
    <field description="The ID of this note." name="id" type="numeric"/>
    <field description="The date and time when this textnote was created." name="date" type="date-time"/>
    <field description="The notes description." name="description" type="description"/>
    <field description="The latitudinal coordinates  where this note was taken." name="locationLAT" type="floating-point"/>
    <field description="The longitudinal coordinate  where this note was taken." name="locationLON" type="floating-point"/>
    <field description="The text of this TextNote." name="text" type="description"/>
  </entity>
</Entitymodel:EntitymodelType>


I have the same problem as before, the entity-name field is changed to entityName, and the description field becomes an attribute of the parent node.

I've attached the ATL configuration, I've tried to search for an option to use my generated model but came up empty.

Thanks again !
Best Regards,
Humberto Carvalho

[Updated on: Tue, 01 December 2015 20:36]

Report message to a moderator

Re: Invalid names when reverse engineering XML schema [message #1716194 is a reply to message #1716166] Wed, 02 December 2015 06:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Humberto,

Comments below.


On 01/12/2015 9:35 PM, Humberto Carvalho wrote:
> Hi Ed Merks, thank you for you reply!
>
> I've generated the model for the OfbizEntity model, and added the following code to the EntityModelResourceFactoryImpl.java
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_RECORD_ANY_TYPE_NAMESPACE_DECLARATIONS, Boolean.TRUE);
> result.getDefaultSaveOptions().put(XMLResource.OPTION_RECORD_ANY_TYPE_NAMESPACE_DECLARATIONS, Boolean.TRUE);
The resource factory for model generated from an XML Schema generally
looks like this:

public Resource createResource(URI uri) {
XMLResource result = new XyzResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION,
Boolean.TRUE);

result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
Boolean.TRUE);

result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER,
Boolean.TRUE);
return result;
}
>
>
> If i generate an instance of this ecore model via the generated editor, the outputted code is correct.
>
> However, the ATL transformation from:
>
> MY_MODEL (named EntityFramework) ----> OFBIZ_ENTITY_MODEL (named EntityModel)
>
> is still incorrect.
>
> Here is the ATL transformation code:
>
>
> -- @path EntityFramework=/EntityFramework/model/entityFramework.ecore
> -- @path EntityModel=/OfbizEntityModel/model/Entitymodel.ecore
>
> module EntityFrameworkToOfbizService;
> create OUT : EntityModel from IN : EntityFramework;
> rule EFEntity2EMEntity {
> from
> s: EntityFramework!Entity
> to
> t: EntityModel!EntityType(
> entityName <- s.name,
> description <- s.description,
> packageName <- s.package.name,
> field <- s.atributes
> )
> }
>
>
> Here is the output:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Entitymodel:EntitymodelType xmi:version="2.0" xmlns:xmi="www.omg.org/XMI" xmlns:Entitymodel="ofbiz.apache.org/dtds/entitymodel.xsd">
> <entity description="The memorix TextNote entity." entityName="TextNote">
> <field description="The ID of this note." name="id" type="numeric"/>
> <field description="The date and time when this textnote was created." name="date" type="date-time"/>
> <field description="The notes description." name="description" type="description"/>
> <field description="The latitudinal coordinates where this note was taken." name="locationLAT" type="floating-point"/>
> <field description="The longitudinal coordinate where this note was taken." name="locationLON" type="floating-point"/>
> <field description="The text of this TextNote." name="text" type="description"/>
> </entity>
> </Entitymodel:EntitymodelType>
>
>
> I have the same problem as before, the entity-name field is changed to entityName, and the description field becomes an attribute of the parent node.
>
> I've attached the ATL configuration, I've tried to search for an option to use my generated model but come up empty.
I can't help you with ATL, but if you're not getting the right result,
it implies you're not using the right resource factory to create the
result you're saving. It's clear the above is being saved with a
resource created by the default XMIResourceFactoryImpl.
>
> Thanks again !
> Best Regards,
> Humberto Carvalho
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Containment proxies and resolving ELists
Next Topic:Markers for first Resource: Bug?
Goto Forum:
  


Current Time: Fri Apr 19 05:03:07 GMT 2024

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

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

Back to the top