You need the xml interface only in the topmost objet, diplomaticstatus, and you have to declare it in the list of classes that the parser recognizes (in FileInput.java or ScenarioFiles.java or both, I don't know exactly which one is used - should check it when I have some time).Originally posted by vovansim
So, I guess I wil describe the data structure first. There is a class called DiplomaticStatuses. It contains all of the diplomatic statuses for the game. Inside, it has a setStatus() method, that takes in two civilizations, and a StatusStrength object. Now, status strength itself is an abstract class. But the acceptable values for the value to pass in are the children of the class, static classes: War, Peace, and Alliance.
Sooo, I suppose the XML should then look like this (on an example of delenda scenario):
??Code:<diplomaticstatuses> <status> <civilization>Rome</civilization> <civilization>Carthage</civilization> <diplomaticstrength> <war /> </diplomaticstrength> </status> </diplomaticstatuses>
Given that I include the xml interface and the appropriate static function in classes DiplomaticStatuses, and all of the subclasses of DiplomaticStrength. Is that how it is supposed to work, or am I missing something?
So you don't need it in DiplomaticStatus subclasses (you can look at ElementArchetype/ElementCost in the military moel for an example: ElementCost is an object inside ElementArchetype but has no getXML() method, everything is done by reflexion).
To get your example working, you need the getXML method declared for diplomaticstatus class, and a public setStatus method, which takes a Status object as an input, and nothing else (again, you can look at ElementArchetype.setCost method).
The Status object needs a setCivilization (or addCivilization) method (both set and add are OK, add would be better here since you add several). Note hte method names needed can be in any case as the parser doesn't worry about setCost or setcost or setcosT (though setCost is better IMO) for instance.
Instead of a
I'd suggest only a <war /> tag, with the corresponding setWar() method (as an example, you have the militia tag in ElementArchetype). That forces you to have several setWar, setPeace... methods. You can bypass that by using
and having a single setDiplomaticStrength(String) method instead.
That's about how it works: getXML() for root tags, then reflexion only. In order for reflexion to work, you need public no-arg constructors in the classes that will be created by the parser, and either setXXX public methods or (but I don't like that) public data members XXX.