My apologies to Matthias, I gave him a bogus answer (referencing the
newInstance on
the Object class rather than the newInstance(Object o) method on Field
handler.
I would think that what he is doing should work....    I'm also interested
in the solution
to his problem.

Is there a simple, self contained example of using a FieldHandler somewhere
in the castor source directory ?
or online somewhere ?

thanks to whoever can help.

    Chris





----- Original Message -----
From: "Keith Visco" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 16, 2002 12:14 PM
Subject: Re: [castor-dev] NotConstructable Exception and FieldHandler


>
> You can also create a "valueOf" method that takes a string value and
> returns the proper enumeration instance, which is how Castor deals with
> unmarshalling type-safe enumerations:
>
> public static [object-type] valueOf(String enumValue) {
>
> }
>
> --Keith
>
> -------- Original Message --------
>    Subject: Re: [castor-dev] NotConstructable Exception and FieldHandler
>       Date: Mon, 16 Dec 2002 11:55:54 -0800
>       From: "Chris Bedford" <[EMAIL PROTECTED]>
>   Reply-To: [EMAIL PROTECTED]
>         To: [EMAIL PROTECTED]
> References: <[EMAIL PROTECTED]>
>
> Hi, Matthias: I'm no Castor expert,but I can tell you that
> Class.newInstance() requires a no argument constructor be available on
> theClass whose instance you are trying to construct. From the
> Javadocs-> ****************
>
> public Object newInstance()
>                    throws InstantiationException,
>                           IllegalAccessException
>
> Creates a new instance of the class represented by this Class object.
> The class is instantiatied as if by a new expression with an empty
> argument list. The class is initialized if it has not already been
> initialized. ****************  As a workaround you could create a
> pass-through proxy that for CoordinateFormatEnum that knows how to
> constructan instance of a CoordinateFormatEnum.   This proxy would
> implement all methods of CoordinateFormatEnum and justdelegate the calls
> to the embedded CoordinateFormatEnum instance. That's one way...   maybe
> the Castor guys can suggest a better one..   I'd be interested in
> finding out as well since I find creationof these proxies to be a
> hassle.. but they get the job done. thanks    Chris
>
>      ----- Original Message -----
>      From: Matthias David
>      To: [EMAIL PROTECTED]
>      Sent: Monday, December 16, 2002 1:39 AM
>      Subject: [castor-dev] NotConstructable Exception and
>      FieldHandler
>       Hi,
>
>      I have written a FieldHandler for a class
>      (CoordinateFormatEnum) that has no public constructor. When
>      Unmarshalling I get the following exception:
>
>      Nested error: org.exolab.castor.mapping.MappingException: The
>      Java class CoordinateFormatEnum is not constructable -- it
>      does not contain a default public constructor)
>
>      The problem is that the class CoordinateFormatEnum is a
>      tool-generated class, so I have no chance to make the
>      constructor public. So How can this problem be solved? I
>      thought that the Unmarshaller does not need to call the
>      constructor of the class since the FieldHandler is responsible
>      for that, e.g. using the method "newInstance".
>
>      Here's the handler's code:
>
>      public class CoordinateFormatEnumFieldHandler implements
>      FieldHandler {
>
>          public Object getValue(Object object)
>                  throws IllegalStateException {
>              return ((Coordinates)object).getFormat().getValue();
>          }
>
>          public void setValue(Object object, Object value)
>                  throws IllegalStateException,
>      IllegalArgumentException {
>
>
((Coordinates)object).setFormat(CoordinateFormatEnum.fromString((String)valu
e));
>
>          }
>
>          public void resetValue(Object object)
>                  throws IllegalStateException,
>      IllegalArgumentException {
>          }
>
>          public void checkValidity(Object object)
>                  throws ValidityException, IllegalStateException {
>          }
>
>          public Object newInstance(Object parent)
>                  throws IllegalStateException {
>              return CoordinateFormatEnum.Mercator;
>          }
>      }
>
>      And here's the mapping:
>
>          <class name="com.Coordinates" access="shared">
>              <description>Default mapping for
>      Coordinates</description>
>              <map-to xml="Coordinates"/>
>              <field name="format" type="com.CoordinateFormatEnum"
>      handler="com.CoordinateFormatEnumFieldHandler">
>                  <bind-xml name="Format" node="attribute"/>
>              </field>
>          </class>
>
>      Any clues for that?
>
>      Thanks,
>       Matthias.
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>

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

Reply via email to