commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: cvs commit: jakarta-commons-sandbox/jelly build.xml
Date Wed, 19 Jun 2002 10:55:56 GMT
In our company we successfully use a XML configuration language used to instantiate beans
(and arbitrary java objects). Maybe this could serve as input (but using a betwixt/digester
reader). This code was designed before SOAP, JDK1.4 XML-Serialization, and originally
took some ideas from Koala (www.inria.fr).

Our team has recently used this XML serialization and reading scheme to migrate
object versions and OODBs (PSEpro form ObjectDesign/ObjectStore).

Please let me know if you would like to see the sources and more/real config code.

The following text is an example of an XML configuration file with embedded comments
describing its syntax.

<!-- XML CONFIGURATION File
  ! $RCSfile: XML_Configuration.html,v $
  !
  ! Specification of a generic java object constructor and configuration language.
  !
  ! Version: $Revision: 1.5 $
  ! Date:    $Date: 2000/05/09 13:42:16 $
  ! Author:  Christoph Reck
  !
  ! Copyright DLR 1999
  !
  !-->

<!--
  ! SYNTAX DESCRIPTION:
  !
  ! <OBJECT      ID="string" NAME="string" CLASS="string" REF="string">
  ! <METHOD      ID="string" NAME="string" CLASS="string" REF="string">
  ! <FIELD       ID="string" NAME="string" CLASS="string" REF="string">
  ! <ARRAY       ID="string" NAME="string" CLASS="string">
  ! <STRING      ID="string" NAME="string" VALUE="string">
  ! <MAP         ID="string" NAME="string">
  ! <CONSTRUCTOR ID="string">
  ! <PACKAGE     ID="string">
  !
  ! COMMENTS:
  !  A STRING appends the contents to the value. The value may contain white spaces.
  !  A MAP permits getting an ordered list of the named entries via getNames().
  !
  ! ATTRIBUTES:
  ! ID="string"     - identifier to access it externally
  ! NAME="string"   - a pretty name used to title the object,
  !                   identify the field (only for field type),
  !                   or the method (only for method type)
  ! CLASS="string"  - dotted.classname in case of complex classes, or
  !                   simple classname in case of base classes (like int)
  ! REF="string"    - ID path of another Object, specified in the
  !                   same XML file. It do not have to be created before
  !                   it is being referenced. This is done automatically.
  ! "string"        - a text, that has to be quoted.
  !
  !
  ! USAGE:
  !
  ! The contents of XML Configuration files following this schema
  ! can be accessed via the static class de.dlr.dfd.dims.ot.control.Configuration
  !
  ! Initilization is done via:
  !   XmlConfigReader.init(parameter)   - Parameter can either be a file name
  !                                       (both absolute or relative), an URL
  !                                       or an InputStream.
  !
  ! After initialization the specific configuration item is retrieved via
  !   Object XmlConfigReader.get(String IDpath)
  ! or any of the other XmlConfigReader.* convenience methods getString(...).
  !
  ! IDpath          - The contents of the configuration file are accessed via
  !                   a string identifier. Items at inner hierarchy levels can
  !                   be accessed by concatenating the IDs in the path with
  !                   dots '.' beginning at the root node (exclusivly).
  !                 - An Object can not be accessed if there is a level
  !                   without ID between itself and the root node.
  !                 - The "PACKAGE" construct can be used to build
  !                   hierachical IDs without having to repeat the path
  !                   for all IDs within that level.
  ! Object          - The retrieved content is the instantiated Object, an
  !                   Array, a Hashtable, or the return value of methods or
  !                   fields.
  !
  ! Defaults        - The default class of ARRAY tags is Object.
  !                 - It is not neccessary to put Strings into an OBJECT tag.
  !
  ! Processing      - Creating an Object only the Constructor, the Method
  !                   and the Field tags, that are direct childs of this Object,
  !                   are processed.
  !                 - Other tags on this child-level are ignored, but can be
  !                   used to hold additional information for the Object (for
  !                   example a Hash, containing the allowed methods of a class,
  !                   or an OBJECT tag, containing just a name), which may be
  !                   accessed via user code, using the XmlConfigReader.get()
  !                   method with "ObjectIDPath.infoID" as parameter String.
  !
  !-->

<!-- EXAMPLES -->

<CONFIGURATION>
   <!-- Instantiate a class without a constructor (see NOTE 2) -->
   <OBJECT ID="HELLO" NAME="greeting message">Hello World!</OBJECT>

   <!-- Catenate String values -->
   <STRING ID="HELLO.AGAIN" VALUE="I say: ">Hello<STRING VALUE=" World " />
     <STRING>Again!</STRING>
   </STRING>

   <!-- Takeover the value of a (public) static constant -->
   <FIELD ID="CENTER" CLASS="javax.swing.SwingConstants" NAME="CENTER">
   </FIELD>

   <!-- Takeover the value from a static method -->
   <METHOD ID="ORB" CLASS="org.omg.CORBA" NAME="init">
   </METHOD>

   <!-- Invoke a static method -->
   <METHOD ID="FALSE" CLASS="java.lang.String" NAME="valueOf">
     <OBJECT CLASS="boolean">0</OBJECT>
   </METHOD>

   <!-- Instantiate a class with constructor values, fields, methods -->
   <OBJECT ID="Rectangle1" CLASS="java.awt.Rectangle">
     <CONSTRUCTOR>
       <OBJECT CLASS="int">1</OBJECT>
       <OBJECT CLASS="int">2</OBJECT>
       <OBJECT CLASS="int">3</OBJECT>
       <OBJECT CLASS="int">4</OBJECT>
     </CONSTRUCTOR>
     <FIELD NAME="witdh">
       <OBJECT CLASS="int">6</OBJECT>
     </FIELD>
     <METHOD NAME="setLocation">
       <OBJECT CLASS="int">7</OBJECT>
       <OBJECT CLASS="int">8</OBJECT>
     </METHOD>
     <OBJECT ID="NAME">The name of the rectangle</OBJECT>
   </OBJECT>

   <!-- Assign a value to a public field refferring an already
        instantiated object (see NOTE 3) -->
   <FIELD REF="Rectangle1" NAME="heigth">
     <OBJECT CLASS="int">9</OBJECT>
   </FIELD>

   <!-- Instantiate a class using fields and methods from another class -->
   <OBJECT ID="Rectangle2" CLASS="java.awt.Rectangle">
     <METHOD NAME="setLocation">
       <METHOD REF="Rectangle1" NAME="getLocation"></METHOD>
     </METHOD>
     <METHOD NAME="setSize">
       <OBJECT CLASS="java.awt.Point">
         <FIELD REF="Rectangle1" NAME="width"/>
         <FIELD REF="Rectangle1" NAME="heigth"/>
       </OBJECT>
     </METHOD>
   </OBJECT>

   <!-- Instantiate an array  -->
   <ARRAY ID="rectangle_array" CLASS="java.awt.Rectangle">
     <OBJECT REF="Rectangle1"/>
     <OBJECT REF="Rectangle2"/>
   </ARRAY>

   <!-- Instantiate a hashtable  -->
   <MAP ID="hashtable">
     <OBJECT CLASS="int" NAME="eins">1</OBJECT>
     <OBJECT CLASS="int" NAME="zwei">2</OBJECT>
   </MAP>

   <!-- Instantiate a Panel with a Gridlayout -->
   <OBJECT ID="Panel" CLASS="java.awt.Panel">
     <OBJECT CLASS="java.awt.GridLayout">
       <OBJECT ID="px" CLASS="int">3</OBJECT>
       <OBJECT ID="py" CLASS="int">6</OBJECT>
     </OBJECT>
   </OBJECT>

   <!-- Create an array with two rectangles, that are referenced -->
   <ARRAY ID="ReferenceArray" CLASS="java.awt.Rectangle">
     <OBJECT REF="Square"></OBJECT>
     <OBJECT REF="Square"></OBJECT>
   </ARRAY>
</CONFIGURATION>



<!-- NOTES:
  !
  ! NOTE1: due to java internals, only objects can be defined.
  !        Reflection-constructors and method-invocations will always
  !        use object[] as parameters, and the class parameter defines
  !        the exact type, e.g. 'int' instead of 'java.lang.Integer'.
  !        As a result of this, an 'int' class will return an 'Integer'.
  !
  ! NOTE2: the default class is 'java.lang.String'.
  !
  ! NOTE3: setting fields should normally be done via set-methods.
  !
  ! NOTE4: due to the use of SUNs XML-parser, a series of blanks is
  !        reduced to a single blank.
  !
  !-->

<!-- END of XML CONFIGURATION File -->


jstrachan@apache.org wrote:
> jstrachan    2002/06/19 03:31:14
> 
>   Modified:    jelly    build.xml
>   Added:       jelly/src/test/org/apache/commons/jelly/xml/betwixt
>                         makeBetwixt.jelly input.xml
>   Log:
>   added a new sample Jelly script to generate bewtixt descriptors from a sample XML bean
language.
>   Moving forward it mght be interesting to investigate using a simple 'BeanML' language
to autogenerate beans, Torque SQL stuff, OJB descriptors etc.
>[snip]
>   Index: input.xml
>   ===================================================================
>   <?xml version="1.0"?>
>   <transactionBean
>     className="org.zenplex.tambora.transaction.PO"
>     primitiveTypes="attributes"
>     rootName="PO">
>   
>     <fields>
>       <field name="id" type="int"/>
>       <field name="name" type="String"/>
>     </fields>
>   </transactionBean>
>[snip]


-- 
:) Christoph Reck


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message