Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » question about default namespaces
question about default namespaces [message #1011867] Wed, 20 February 2013 11:52 Go to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hi all,

I'm seeing some unexpected behavior in the XMLHelperImpl#recordPrefixToURIMapping() and XMLHandler#recordNamespacesSchemaLocations() methods. These are called by the SAX XML parser during endDocument() processing to collect all namespace declarations found in the document; recordNamespacesSchemaLocations() attaches all namespaces found by the XMLHelper to the xmlnsPrefixMap feature in DocumentRoot.

So if I have a model with NS URI, for example, "http://org.eclipse.example/model", and try to parse an externally generated document (i.e. not created by the EMF serializer) like this:

<root>
  <item xmlns="http://org.eclipse.example/external" .../>
</root>


the default NS declaration ("http://org.eclipse.example/external") is added to the DocumentRoot namespace map as the default for the entire document and the <root> element can no longer be resolved. The fix is to explicitly add a namespace declaration to the <root>, like so:

<root xmlns="http://org.eclipse.example/model">
  <item xmlns="http://org.eclipse.example/external" .../>
</root>


My question: is there some other way around this so that I don't have to modify these externally generated documents?

Thanks!
Bob
Re: question about default namespaces [message #1011877 is a reply to message #1011867] Wed, 20 February 2013 12:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Robert,

The two examples you show, i.e.,

<root>
<item xmlns="http://org.eclipse.example/external" .../>
</root>

and

<root xmlns="http://org.eclipse.example/model">
<item xmlns="http://org.eclipse.example/external" .../>
</root>

can't both conform to the same schema. What are you doing special so
that the first instance is even recognized at all?


On 20/02/2013 12:52 PM, Robert Brodt wrote:
> Hi all,
>
> I'm seeing some unexpected behavior in the
> XMLHelperImpl#recordPrefixToURIMapping() and
> XMLHandler#recordNamespacesSchemaLocations() methods. These are called
> by the SAX XML parser during endDocument() processing to collect all
> namespace declarations found in the document;
> recordNamespacesSchemaLocations() attaches all namespaces found by the
> XMLHelper to the xmlnsPrefixMap feature in DocumentRoot.
>
> So if I have a model with NS URI, for example,
> "http://org.eclipse.example/model", and try to parse an externally
> generated document (i.e. not created by the EMF serializer) like this:
>
>
> <root>
> <item xmlns="http://org.eclipse.example/external" .../>
> </root>
>
>
> the default NS declaration ("http://org.eclipse.example/external") is
> added to the DocumentRoot namespace map as the default for the entire
> document and the <root> element can no longer be resolved. The fix is
> to explicitly add a namespace declaration to the <root>, like so:
>
>
> <root xmlns="http://org.eclipse.example/model">
> <item xmlns="http://org.eclipse.example/external" .../>
> </root>
>
>
> My question: is there some other way around this so that I don't have
> to modify these externally generated documents?
>
> Thanks!
> Bob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: question about default namespaces [message #1011961 is a reply to message #1011877] Wed, 20 February 2013 15:44 Go to previous messageGo to next message
Gary Brown is currently offline Gary BrownFriend
Messages: 3
Registered: December 2009
Junior Member
Hi Ed

Probably better to look at some actual XML fragments to clarify the problem. We have a BPMN2 process model in the following form:

<bpmn2:definitions xmlns:bpmn2="..." ... targetNamespace="http://www.eclipse.org/Purchasing/Store">
	....
    <bpmn2:itemDefinition xmlns="http://www.eclipse.org/schema/store" id="ITEMBuyRequest" structureRef="BuyRequest"/>
    <bpmn2:message xmlns="http://www.eclipse.org/Purchasing/Store" id="IDBuyRequest" itemRef="ITEMBuyRequest" name="BuyRequest"/>
    ....
    <bpmn2:itemDefinition xmlns="http://www.eclipse.org/schema/logistics" id="ITEMDeliveryRequest" structureRef="DeliveryRequest"/>
    <bpmn2:message xmlns="http://www.eclipse.org/Purchasing/Store" id="IDDeliveryRequest" itemRef="ITEMDeliveryRequest" name="DeliveryRequest"/>
	....
    <bpmn2:process name="Store">
		....
        <bpmn2:task xmlns="http://www.eclipse.org/Purchasing/Store" messageRef="IDBuyRequest" />


If we first look at the bpmn2:task at the bottom, it has a QName 'messageRef' which references the first bpmn2:message, which in turn references the bpmn2:itemRef via another QName. These QNames obtain their namespace from the default namespace defined on the elements.

The problem is that when the BPMN2 editor saves the model after a minor change (e.g. moving one of the nodes), it appears to move the default namespaces to the top level 'definitions' element. As there are multiple default namespaces defined in the various child nodes, it creates more than one declaration (although it doesn't appear to create a declaration for all of the default namespaces), but does not then apply the generated prefix to the appropriate QNames.

For example,

<bpmn2:definitions xmlns:_1="http://www.eclipse.org/Purchasing/Store" xmlns:bpmn2="...." xmlns="http://www.eclipse.org/schema/store" targetNamespace="http://www.eclipse.org/Purchasing/Store">
  ....
  <bpmn2:itemDefinition id="ITEMBuyRequest" structureRef="BuyRequest"/>
  <bpmn2:message id="IDBuyRequest" itemRef="ITEMBuyRequest" name="BuyRequest"/>
  ....
  <bpmn2:itemDefinition id="ITEMDeliveryRequest" structureRef="DeliveryRequest"/>
  <bpmn2:message id="IDDeliveryRequest" itemRef="ITEMDeliveryRequest" name="DeliveryRequest"/>
  ....
  <bpmn2:process id="id-0f89c798-4c95-457d-a77a-30c24f0433f6" name="Store">
	....
    <bpmn2:receiveTask messageRef="IDBuyRequest" .... />


So the bpmn2:receiveTask is now referencing the message IDBuyRequest in a different namespace, as the default namespace is now different - it should have applied the _1 prefix.

The ITEMDeliveryRequest itemDefinition has a structureRef QName which again has the wrong namespace, as it was previously '.../schema/logistics', but this namespace is no longer defined. Well it is defined in the full document, as a pre-existing namespace declaration, but there is no _2 prefix created for this namespace. Either way, the attribute has not been updated to use an appropriate prefix.

Hope this clarifies the strange issue we are seeing.

Regards
Gary
Re: question about default namespaces [message #1011982 is a reply to message #1011961] Wed, 20 February 2013 16:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Gary,

Comments below.

On 20/02/2013 4:44 PM, Gary Brown wrote:
> Hi Ed
>
> Probably better to look at some actual XML fragments to clarify the
> problem. We have a BPMN2 process model in the following form:
>
>
> <bpmn2:definitions xmlns:bpmn2="..." ...
> targetNamespace="http://www.eclipse.org/Purchasing/Store">
> ....
> <bpmn2:itemDefinition xmlns="http://www.eclipse.org/schema/store"
> id="ITEMBuyRequest" structureRef="BuyRequest"/>
> <bpmn2:message xmlns="http://www.eclipse.org/Purchasing/Store"
> id="IDBuyRequest" itemRef="ITEMBuyRequest" name="BuyRequest"/>
> ....
> <bpmn2:itemDefinition
> xmlns="http://www.eclipse.org/schema/logistics"
> id="ITEMDeliveryRequest" structureRef="DeliveryRequest"/>
> <bpmn2:message xmlns="http://www.eclipse.org/Purchasing/Store"
> id="IDDeliveryRequest" itemRef="ITEMDeliveryRequest"
> name="DeliveryRequest"/>
> ....
> <bpmn2:process name="Store">
> ....
> <bpmn2:task xmlns="http://www.eclipse.org/Purchasing/Store"
> messageRef="IDBuyRequest" />
>
>
> If we first look at the bpmn2:task at the bottom, it has a QName
> 'messageRef' which references the first bpmn2:message, which in turn
> references the bpmn2:itemRef via another QName. These QNames obtain
> their namespace from the default namespace defined on the elements.
>
> The problem is that when the BPMN2 editor saves the model after a
> minor change (e.g. moving one of the nodes), it appears to move the
> default namespaces to the top level 'definitions' element. As there
> are multiple default namespaces defined in the various child nodes, it
> creates more than one declaration (although it doesn't appear to
> create a declaration for all of the default namespaces), but does not
> then apply the generated prefix to the appropriate QNames.
Handling QNames is quite tricky. Are you using XMLTypePackage's QName
data type? Or values created by
org.eclipse.emf.ecore.xml.type.XMLTypeFactory.createQName(String)? So
that things like
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.updateQNamePrefix(EFactory,
EDataType, Object, boolean) kick in...
>
> For example,
>
>
> <bpmn2:definitions xmlns:_1="http://www.eclipse.org/Purchasing/Store"
> xmlns:bpmn2="...." xmlns="http://www.eclipse.org/schema/store"
> targetNamespace="http://www.eclipse.org/Purchasing/Store">
> ....
> <bpmn2:itemDefinition id="ITEMBuyRequest" structureRef="BuyRequest"/>
> <bpmn2:message id="IDBuyRequest" itemRef="ITEMBuyRequest"
> name="BuyRequest"/>
> ....
> <bpmn2:itemDefinition id="ITEMDeliveryRequest"
> structureRef="DeliveryRequest"/>
> <bpmn2:message id="IDDeliveryRequest" itemRef="ITEMDeliveryRequest"
> name="DeliveryRequest"/>
> ....
> <bpmn2:process id="id-0f89c798-4c95-457d-a77a-30c24f0433f6"
> name="Store">
> ....
> <bpmn2:receiveTask messageRef="IDBuyRequest" .... />
>
>
> So the bpmn2:receiveTask is now referencing the message IDBuyRequest
> in a different namespace, as the default namespace is now different -
> it should have applied the _1 prefix.
>
> The ITEMDeliveryRequest itemDefinition has a structureRef QName which
> again has the wrong namespace, as it was previously
> '.../schema/logistics', but this namespace is no longer defined. Well
> it is defined in the full document, as a pre-existing namespace
> declaration, but there is no _2 prefix created for this namespace.
> Either way, the attribute has not been updated to use an appropriate
> prefix.
>
> Hope this clarifies the strange issue we are seeing.
Somewhat, but it's a nasty issue in general to manage these things.
Models don't generally capture the prefixes on particular node; only the
document root keeps all the prefixes.
>
> Regards
> Gary


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: question about default namespaces [message #1012862 is a reply to message #1011982] Fri, 22 February 2013 10:57 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hmm, I thought I posted a follow-on to this thread, guess it was lost.
Anyway, I just wanted to get some more details about how and where to use XMLTypeUtil.createQName() - are there examples somewhere?
Thanks!
Re: question about default namespaces [message #1012901 is a reply to message #1012862] Fri, 22 February 2013 12:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Robert,

You didn't answer my questions. :-P

To give advice I need to understand how you are representing these
QNames in the model. If you use the QName EDataType from XMLType.ecore
and if you used XMLTypeFactory.eINSTANCE.createQName to create instances
manually, then the serializer and deserializer would perhaps to their
job automatically. Without some background, it's hard to given specific
advice.


On 22/02/2013 11:57 AM, Robert Brodt wrote:
> Hmm, I thought I posted a follow-on to this thread, guess it was lost.
> Anyway, I just wanted to get some more details about how and where to
> use XMLTypeUtil.createQName() - are there examples somewhere?
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO/Teneo] How to create HibernateStore programatically? / org.hibernate.MappingException: Could no
Next Topic:EMF development enviroment for Juno?
Goto Forum:
  


Current Time: Fri Apr 19 11:07:19 GMT 2024

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

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

Back to the top