Bug 203257 - [editor] ns prefix renaming does not affect references to that prefix
Summary: [editor] ns prefix renaming does not affect references to that prefix
Status: NEW
Alias: None
Product: WTP Webservices
Classification: WebTools
Component: wst.wsdl (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Keith Chong CLA
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-09-13 09:10 EDT by Mikhail Bolotov CLA
Modified: 2010-07-20 11:36 EDT (History)
3 users (show)

See Also:


Attachments
Prefix was not changed throughout whole wsdl (7.49 KB, application/xml)
2007-09-13 09:10 EDT, Mikhail Bolotov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail Bolotov CLA 2007-09-13 09:10:39 EDT
Created attachment 78305 [details]
Prefix was not changed throughout whole wsdl

Build ID: M20070905-1045

Steps To Reproduce:
1) open a properties tab of any wsdl
2) change the prefix name 

if there were any references to the prefix in the wsdl, they will not have been
changed. 
In attached wsdl, the prefix was changed from "pos" to "posCHANGED" only in the namespace definitions section
Comment 1 Valentin Baciu CLA 2007-09-13 23:28:36 EDT
Hi Mikhail, I believe your scenario is similar to the one reported in bug 194096 so I will mark this bug as a duplicate. Please verify and close if you agree. You can then track the progress on the other bug.

*** This bug has been marked as a duplicate of bug 194096 ***
Comment 2 Mikhail Bolotov CLA 2007-09-17 05:26:57 EDT
closed
Comment 3 Valentin Baciu CLA 2008-04-16 16:22:59 EDT
Reopening. The fix for bug 194096 will only address the target namespace change, not the prefix change. The prefix change is probably best handled in the editor. At least this is how the schema editor seems to work.
Comment 4 Amy Wu CLA 2008-07-22 17:25:26 EDT
There are 2 parts to renaming a prefix.
1. Updating the namespace attribute in the definition
2. Updating the references for the prefix

First off, we don't even have the code to update the references.  And once we do add that code in, the references are still not being updated.  This is because  when the namespace attribute is updated in part 1., all the references are lost.  So when it comes time to actually update the references, the wsdl model does not think there are any.

The fix would be to make sure references are not lost when the namespace attribute is renamed in a definition, and to add in code to update references.
Comment 5 Amy Wu CLA 2008-07-22 17:48:47 EDT
The gorey details:
In W11EditNamespacesCommand#execute, the prefix is updated by removing the old namespace attribute and then adding the new one.

Removing the old attribute will eventually trigger a reconcile on the definition.
For Port, Binding, Message, WSDLElement#reconcileReferences() looks something like this:

QName messageQName = createQName(definition, element.getAttribute(WSDLConstants.MESSAGE_ATTRIBUTE), element);
Message newMessage = messageQName != null ? (Message)definition.getMessage(messageQName) : null;
if (newMessage != getEMessage())
{
  setEMessage(newMessage);
}

The problem here is that messageQName will be null. This is because when trying to create the QName for the current referenced message, it will return null.  It is null because the prefix/namespace attribute has already been deleted, so when it tries to create a new QName by looking up the prefix, it will find that there is none. So QName=null which means newMessage is null.  Which means newMessage != message currently referenced. Which means it will delete the message currently referenced.

So that's how the references are lost.

** So it looks like a fix needs to be made somewhere around here to not lose the existing references.

Once this is fixed, the next step to update the references is actually not that bad according to what is being done XSD's UpdateNamespaceInformationCommand.  What XSD does is it calls schema.updateElement() and that will update all the references magically. I'm assuming it does some magic with resolving the prefix/namespaces.  The same type of call would need to be made in W11EditNamespacesCommand for the definition object.  (See UpdateNamespaceInformationCommand#updateElement() for more details)
Comment 6 Jatinder Singh CLA 2009-03-21 14:13:03 EDT
Hi Amy, I’ve been working on this bug from last few weeks and your detailed information has been a great help. I am very new to the Eclipse code base but its consistent structure has helped me to a great extent in order to understand and find the source code. I have narrowed down the source code and have carried out the debug process several times. Your sentence “Removing the old attribute will eventually trigger a reconcile on the definition” contains a lot of information and I am having troubles absorbing it fully. What exactly are you refereeing to when you say “definition”? And what is the function of reconcileReferences(Boolean) method? I understand that it is responsible for binding the attribute to the correct namespace but I am not sure whether my understanding of this method is correct. If you could go over this method would be really helpful. 

I am looking forward to hearing from you. And please let me know if you have any questions for me.

Jatinder