This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 104228 - OpenCookie inaccessible from XMLDataObject
Summary: OpenCookie inaccessible from XMLDataObject
Status: NEW
Alias: None
Product: xml
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: issues@xml
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-18 00:15 UTC by jalex000
Modified: 2007-07-16 22:46 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Test case for cookies available in XMLDataObjects (3.05 KB, text/plain)
2007-06-20 16:02 UTC, jalex000
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jalex000 2007-05-18 00:15:11 UTC
I found that I cannot open an XML file in the XML editor programmatically its
OpenCookie, i.e. using the following pattern:

DataObject xmlDo = DataObject.find(someFileObject);
OpenCookie oc = (OpenCookie)xmlDo.getCookie(OpenCookie.class);
oc.open();

This fails because oc is always null. The source of the problem appears to be in
the constructor for org.openide.loaders.XMLDataObject, specifically the call to
the deprecated createEditorCookie() inside the CookieSet.Factory constructor
that contains the OpenCookie. Since the XML loader actually constructs a
org.netbeans.modules.xml.core.XMLDataObject, which overrides
createEditorCookie(), simply returning null, createCookie() will also always
return null for the cookies it's supposed to construct. The solution is to
rewrite the factory to avoid using createEditorCookie(), but the correct change
is not obvious to me.

I've worked around the problem by using EditCookie instead, which appears to
work fine, but there's a whole lot of example code out there that uses only
OpenCookie.

I have not explicitly checked whether this problem still exists in 6.0, but
looking at affected files in the latest CVS, it looks to me like the relevant
code is essentially the same, so I believe this bug is still there.
Comment 1 Jaroslav Tulach 2007-06-19 10:23:10 UTC
#104228: Testing the XMLDataObject has OpenCookie


IDE:-------------------------------------------------
IDE: [19.6.07 11:20] Committing "XMLDataObjectTest.java" started
Checking in XMLDataObjectTest.java;
/cvs/openide/loaders/test/unit/src/org/openide/loaders/XMLDataObjectTest.java,v  <--  XMLDataObjectTest.java
new revision: 1.5; previous revision: 1.4
Comment 2 jalex000 2007-06-19 20:35:54 UTC
My use case still does not work in 6.0M9, and comparing it with your unit tests, I found that you actually get different
cookies in the XMLDataObject depending on whether the file is in the system filesystem or on a real disk-based
filesystem. Concretely (assuming /path/to/file.xml exists):

      FileObject fo = FileUtil.toFileObject(new File("/path/to/file.xml"));
      DataObject xmlDo = DataObject.find();

Then xmlDo has an EditCookie, but no OpenCookie. If, instead, as in your test, the FileObject is stored somewhere in the
system filesystem, just the opposite is true: the DataObject has an OpenCookie, but no EditCookie! I don't have time at
the moment to track this further, but this difference isn't expected, is it?
Comment 3 Jaroslav Tulach 2007-06-20 08:47:51 UTC
The data object in my test is on regular local file system. Maybe, we are talking about different XMLDataObject? What 
is your xmlDo.getClass()?
Comment 4 jalex000 2007-06-20 16:02:15 UTC
Created attachment 44074 [details]
Test case for cookies available in XMLDataObjects
Comment 5 jalex000 2007-06-20 16:10:30 UTC
You're right - I'd forgotten that I never tracked down what TestUtilHid.createLocalFileSystem() did. Sorry about the
misinformation.

I've attached the test code I've been using. Invoke the static method OpenCookieTest.foo() to try. The output under
either NetBeans 5.5 or 6.0M9 is:
Did NOT find open cookie
Found edit cookie
class org.netbeans.modules.xml.core.XMLDataObject
Found open cookie
Did NOT find edit cookie
class org.openide.loaders.XMLDataObject

... so I'm getting an org.netbeans.modules.xml.core.XMLDataObject. The critical difference seems to be the origin of the
FileObject. If it's obtained via FileUtil.toFileObject(), I get an org.netbeans.modules.xml.core.XMLDataObject, with the
cookie content shown above. If it originates via FileUtil.createData(), as in your test case, regardless of whether the
underlying filesystem, I get a org.openide.loaders.XMLDataObject, which as shown has an OpenCookie, but no EditCookie.
Indeed, if I uncomment the code at the end of my setup() method, obtaining a new FileObject for the same file from
FileUtil.toFileObject(), I get another org.netbeans.modules.xml.core.XMLDataObject.
Comment 6 Jaroslav Tulach 2007-06-20 16:51:34 UTC
So basically the problem is with the non-openide implementation of XMLDataObject.
Comment 7 Jaroslav Tulach 2007-06-20 16:52:39 UTC
I guess the org.netbeans.modules.xml.core.XMLDataObject could be modified to have OpenCookie.
Comment 8 jalex000 2007-06-20 17:17:41 UTC
I would say that there's a pretty compelling argument to be made that the cookie set of
org.netbeans.modules.xml.core.XMLDataObject ought to be a superset of org.openide.loaders.XMLDataObject. It looks like
that is the intent anyway, but the lazy instantiation code is not quite working right. See my comments on this in the
original bug report.
Comment 9 _ rkubacki 2007-06-24 18:52:59 UTC
It is possible that the original intent was to use OpenCookie to open specialized editor (tree structure editor in the
past) and EditCookie for text editors. The implementation of opencookie was plugged into dataobject from additional modules.

Maybe consulting other XMLDO subclasses can help to find proper way how to deal with this. I am afraid that if there are
some subclasses in the IDE it would be too risky to make changes here at this moment.
Comment 10 Samaresh Panda 2007-07-16 22:46:09 UTC
I would like to revisit this post 6.0.