On 2/19/02 10:43 AM, [EMAIL PROTECTED] wrote:
> Could please outline how to approach this in Castor, if possible
> without adding public constructors and getter/setter methods to every
> class? I'd prefer to restrict the number of public get/set methods to
> only those required by the application rather than exposing
> everything to fit with the marshalling framework. This preference
> could of course be relaxed, but I'd like to minimize the upheaval if
> possible.

This isn't possible in the current Castor version.  A while back I proposed
extensions to the mapping file to allow this:

   http://www.mail-archive.com/[email protected]/msg00984.html

Looking back now, I see that it can be even simpler, so here's a modified
proposal...

--------

One thing that is nice about OJB (a similar project) is the ability of the
mapper to call a "real" constructor on the object, instead of just using the
no-arg constructor and then setting a bunch of properties.

Advantages:

  - Allows you to ensure that the bean's invariants are always maintained
  - Faster (many fewer method calls)
  - Allows the bean to have read-only properties
     --> Fewer bugs!!

I'd suggest adding a constructor-fields attribute to the MAPPING.XML class
element, which lists the fields whose values should be passed into the
constructor instead of through setter methods.  Castor can then deduce an
appropriate constructor based on the types of the constructor-fields.

<class name="MyClass" identity="id" constructor-fields="id date name">
  <field name="id" type="integer">
    ...
  </field>
  <field name="date" type="date">
    ...
  </field>
  <field name="name" type="string">
    ...
  </field>
</class>


This would cause Castor to instantiate the object using a constructor
matching:

    public MyClass(int id, java.util.Date date, String name);

Any other fields not named in the constructor-fields attribute would be set
via the usual setters.

--------

Our soon-to-be-Open-Sourced "Seedling" component framework (a recreation of
the ATG Dynamo "Nucleus" framework) does the same thing to construct and
link high-level application components in a fairly safe and non-intrusive
way.  It works very well.


Todd V. Jonker
Inpath Solutions, LLC
www.inpathsol.com

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to