Savable read/write Code Generator

Hi all,



I’ve been working on a CodeGenerator plugin for Netbeans/jMonkeyEngine that will generate the read and write method bodies of classes that wish to implement the Savable interface.



I’ve started a repository for it here: https://github.com/airbaggins/jme-savable-generator



I don’t know about you, but I find maintenance of these methods very tedious.



Hopefully someone else finds this useful.

5 Likes

Cool, but why not keep it directly in the contribution repository so that people can install it in the SDK? :slight_smile: If you want to add it there, PM me with your googlecode details.

That’s a very good idea. Nice work

Well, I got a similar problem also a while ago. How would I maintain the code for that and, at the same time, generate a XML schema from a class? And also be able to load from a XML file into a new instance, without the need to write a lot of code?

I ended up using JAXB for saving my entities, so that way I can generate a XML Schema from it’s classes and load a XML into an instance (the important part is: without writing additional code, just using attributes and methods from the class, to avoid duplicated work in the development phase)

I added this to the contributions update center by downloading the nbm from the downloads when its updated.

Hm, it doesn’t do anything for a control I created… Any special requirement for the fields?

@normen What type is the control? Most types that are savable should be captured. Is it a custom class/interface field? Does it inherit/extend Savable?



@shirkit My main motivation was to make it work with jME’s BinaryExporter. Why do you particularly want to use a non-Savable XML format? What does it give you that jME’s exporters don’t?

I know it works with xml, but it doesn’t allow me to generate a xml schema from that, something I needfor development phase, since I keep changing the classes.



I have my entities classes , that describes general things, like a character. One xml file Ihave describes this character class with some components, that describes a swordsman. Given the need to process that character class, generate a schema for it and it’s possible components, I decided to go with JAXB since it was already done.

@airbaggins: Its extending AbstractControl.

@shirkit: this serialization system works with xml too and you can attach any savable to a spatial and save it along with it.

@normen: Can you just paste the field here? And the declaration line of the class it is?

public class MyClass extends AbstractControl, just create a control with the template in the SDK.

Then I have a private float and a String with getter/setter.

If you implement Savable, i.e.



[java]public class MyClass extends AbstractControl implements Savable { … }[/java]



it should visit that file and add the read/write methods for you as well.



A slight limitation at the moment is that you need to say “implements Savable” first.

I see. Heres the code that recognizes control classes in the SDK for adding custom controls, maybe it helps:

https://code.google.com/p/jmonkeyengine/source/browse/trunk/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/NewCustomControlVisualPanel1.java

I’m curious what you’re using the schema for…

@shirkit said:
I know it works with xml, but it doesn't allow me to generate a xml schema from that, something I needfor development phase, since I keep changing the classes.

I have my entities classes , that describes general things, like a character. One xml file Ihave describes this character class with some components, that describes a swordsman. Given the need to process that character class, generate a schema for it and it's possible components, I decided to go with JAXB since it was already done.

That sounds like you would be better served with a database (if needed based on xml files).

The schema is for defining the types of units in the game.



Oops the schema is used to define types of units in the game. That way I can set limits to things, and units can’t violate that.



Also, the idea is that anyone can create a new unit (future releases) just like the Warcraft 3 map editor.

@airbaggins Is this plugin still under development?

I just tried it and didn’t manage to have it to work.



I tried with an existing class, added the implements Savable, then did insert code/generate read write…and nothing happened with no error.

same with a new class file.

Yeah @airbaggins, I also can’t get it to work though the code looks pretty good and extensive, I bet adding support for generic “implements Savable” wouldn’t be hard to add.