As the information system becomes more and more complex, it is increasingly difficult to maintain a
single repository that has the definitions of all the business objects that are valid within the scope of
your project.
In our case, we have to maintain Object Definitions in the following environments:
On projects with large repositories this situation can quickly become a nightmare, especially when a change occurs in some business object. It is for that very reason that a single repository is nearly compulsory. Therefore we decided to build a source generator that is capable of taking a business object from any of the previous environnements and generating the object description in the othere two environnements.
To sum it up, the sourcegenerator is capable of:
Comming up next ....
Comming up next ....
Today there are many ways to represent a Data Bean, starting from the simple source code going to the TIB/Repository passing by a Castor XML mapping file.
Raccoon too has it's representation of a Data Bean, it's called a RaccoonBean that has certain properties. Anyway this RaccoonBean has a unique representation in the xml world that is very simple to use. This XML representation can be used to generate either:
<container name="Test XML String"> <raccoonBean name="raccoon.test.RaccoonBean"> <field name="name" type="java.lang.String" /> <field name="friends" type="java.util.Vector" colType="java.lang.String"/> <field name="family" type="java.util.HashMap" colType="java.lang.String"/> <field name="elements" type="java.util.ArrayList" colType="raccoon.test.RaccoonField"/> </raccoonBean> <raccoonBean name="raccoon.test.RaccoonField"> <field name="name" type="java.lang.String" /> <field name="age" type="int" /> </raccoonBean> </container>
This XML Source file can be used to generate
This section briefly explains how to use the Source Generator between a Raccoon JavaBean and a Castor XML mapping file. For more information related to Castor XML please visit the Intalio site: Castor XML
Today Castor XML has become an invaluable tool on daily basis, this is certainly the case for Raccoon.
As for us, whenever we use Castor XML we have already designed and usually implemented our java
beans, what annoys us the most is the mapping file that we have to write for all our beans.
We therefore decided to include into Raccoon a service for our favorite XML mapping tool that will:
Usually when using Castor the developper has his java bean already specified and not a
Castor Mapping File. Well it's our case anyway :o)
Getting the mapping file for castor is very easy as you can see for yourself hereafter.
import raccoon.core.exceptions.ComponentException; import raccoon.core.exceptions.RaccoonException; import raccoon.tools.generator.SrcFactory; public class SampleApp { public static void main(String args[]) { try { SrcFactory sourceGen = new SrcFactory(); sourceGen.setPropertyFileName("raccoon"); sourceGen.start(); String marshalled = sourceGen.classToCastor(Team.class); System.out.println("Castor XML Mapping File is:\n" + marshalled); } catch (RaccoonException re) { re.printStackTrace(); } } }
Where Team
is a valid java bean containing getters, setters and adders.
The result obtained in our sample case can be viewed by clicking on the link:
The following elements found in the file raccoon.tools.generator.generator.properties
can
now be customized:
castor.dtd
castor.bind-xml
.
Accepted values are upper
or lower
, default value is lower
upper
is set then the xml element will be
bind-xml="PropertyName"
. If lower
is set then the xml element will be
bind-xml="propertyName"
.
castor.mapping.type
Accepted values are attribute
or element
, default value is
element
.attribute
is set then the xml element will be
node="attribute"
. If element
is set then the xml element will be
node="element"
.
Using the previous Castor Mapping file to generate the source code can be done quite easily, a sample application is given hereafter:
import raccoon.core.exceptions.ComponentException; import raccoon.core.exceptions.RaccoonException; import raccoon.tools.generator.SrcFactory; public static void main(String args[]) { try { SrcFactory sourceGen = new SrcFactory(); sourceGen.setPropertyFileName("raccoon"); sourceGen.start(); String result[] = sourceGen.castorToSource("mapping.xml"); System.out.println("Final Source is"); for (int i=0;i<result.length;i++) { System.out.println(result[i]); } } catch (RaccoonException re) { re.printStackTrace(); } }
Where mapping.xml
is a valid Castor XML mapping file.
The result obtained in our sample case can be viewed by clicking on one of the following links:
Eventually the reader may prefer viewing the associated javadoc: