Download NetBeans!

20070418 Wednesday April 18, 2007

xwork.xml in MultiView Editor

A simplistic start to creating a multiview editor for the xwork.xml file:

Most of it works, but there are several bugs to fix. An editor such as this only makes sense when (a) all elements/attributes are exposed and (b) no bugs remain. So those are the two things I'm striving for.

Want to create a multiview editor for an XML file too? The principles of getting started are easy. Here are some resources:

  • NetBeans: schema2beans library - User Documentation
  • Toni Epple's blog has some really good resources about getting started with Schema2Beans. His blog is here. He and Vadiraj, who has been very helpful to me over the past few days, are thinking of writing a wizard that will generate all the beans via Schema2Beans, as well as some basic implementation classes from the XML MultiView API. That would be really brilliant to have. Anyone out there want to help them? You can get in touch with them via their blogs.

Writing a multiview editor for XML files is not exactly easy, but it could also be a lot harder than it is. There's a lot to become comfortable with. The most obvious question is: "Where do I start?" Well, you start by generating Java classes from the Schema or DTD to which the XML file conforms. So, you are not really writing a multiview editor for an XML file. You are writing it for a Schema or DTD file. Using the Schema2Beans JAR provided by NetBeans, here, you can use either Java code or Ant scripts to generate your Java classes. These Java classes form the basis of your implementation of the XML Multiview API. In other words, they are the model of your application.

Once you have these classes, of which there could be about 10 (in fact, one class per element in the Schema or DTD), put them in your module. Then go to your DataObject and change its extension class from whatever it is to XmlMultiViewDataObject. This means you'll have to create a dependency on the XML MultiView API. After that, you will have to implement many many many methods, over several classes. The best way to go about this, in my humble opinion, is to (a) get the BookMultiView Sample from my update center (or get it from Vadiraj, because he has fixed an annoying bug in the module) and (b) read these of Vadiraj's blog entries extremely carefully. They introduce you to the sample, as well as to the API as a whole. They're excellent and describe the whole picture on a very technical yet readable level:

With all of the above resources, you'll be off to an excellent start. My own approach is to gradually merge the BookMultiView Sample with my own scenario, bit by bit and piece by piece. What is also helpful is that if you go here in the NetBeans sources...

netbeans-sources\j2ee\ddloaders\src\org\netbeans\modules\j2ee\ddloaders\web

...you will find several other multiview editors, such as the editor used by the web.xml file. You can open the forms in the IDE and then... you can let them "inspire" you. Or just do what I did and copy whatever makes sense to your own scenario.

Apr 18 2007, 07:28:03 AM PDT Permalink