tags:

views:

244

answers:

1

I asked this in spring forums but got no answer, and I just discovered stackoverflow, so Ill try here.

I am using spring 2.0.5. In my app I need to let the user add/modify/delete (via the UI) beans that are described in the applicationContext.xml file. The beans that are to be edited are all of the same class (like a db table crud editor really, but faster do develop and easier to evolve regarding the code).

I have been searching the web and forums and cannot find any existing code. I guess my need is quite usual, does somebody know some code I can leverage?

If not, is there at least a way to get the xml (as a string) element from a java bean?

thanks in advance.

A: 

The Spring IDE plugin for Eclipse has tools for editing the application context, and the source code is available, so that might be one place to start.

I don't believe there's a way to get the XML bean definition from, for example, a BeanFactory object. Remember that a given bean might not even have an XML definition; it might be autowired, for example.

Another approach might be to use a library such as Dom4J to parse and manipulate the XML of the applicationContext.xml file. You could easily get a particular bean definition by doing, for example,

document.selectSingleNode("//bean/beans[name='beanNameIWantToEdit']")

Then you could change properties, etc., on that node. You can also get the full XML text of that node by doing node.asXML().

JacobM
ok, thanks! I had thought about springide, but I had hoped something more concise for the purpose I described (it is quite simple really, and i have already implemented but not in an elegant way as I would have liked). I really find this usage of the spring definition files is quite flexible and has many advantages to use instead of a table (when having a handful of rows only sure), easy to backup, easy to edit by hand by support if needed, easy to evolve...
raticulin