Bryan,

Take a look at using a GeneralizdFieldHandler instead.

http://castor.codehaus.org/xml-fieldhandlers.html

--Keith

Bryan LaPlante wrote:
I need some real help here. I am looking at the FieldHandler and I see that
I can create an instance of the ServerEvent class using the newInstance
method of FieldHandler. The problem is that the interface that declares a
ServerEvent will be implemented by the target API user. I want to avoid
having to make required FieldHandler implementations for each instance
implemented by the developer. It would be great if I could get a handle to
my FieldHandler created for ServerEvent at the time the ServerEvent
constructor is called.

Just to give you the heads up here is the basic structure of implementing
the interface class.

public class MyControl implements Control{

    ServerEvent myCustomEvent = null;

    public MyControl(){
        // this refers to the source of the event
        myCustomEvent = new
ServerEvent(this,"targetMustSupportThisMethodName");
    }

    public boolean addCustomEventListener(EventListener el){
        myCustomEvent.addListener(el);
    }
}

----- Original Message -----
From: "Keith Visco" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, February 10, 2005 10:09 PM
Subject: Re: [castor-user] mapping question



You can specify attributes as constructor arguments, but you can't pass
in an arbitrary value.



http://castor.codehaus.org/xml-mapping.html#7.3-Mapping-constructor-argument s

--Keith

Bryan LaPlante wrote:

Never mind, I just put a call to super(EventObject.class) into an no
argument constructor so that it could be marshaled and still satisfy the
EventObject contract. It would be nice if I could handle this in the

mapping

file or a custom FieldHandler so that I don't have to find another way

to

enforce my contracts for the application.

Bryan

----- Original Message -----
From: "Bryan LaPlante" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, February 09, 2005 7:24 AM
Subject: [castor-user] mapping question




I have a class that extends EventObject, the mandatory constructor must

take


an Object. Is there any way to provide a constructor argument in the

class

tag of the mapping file. Here is the mapping and the class. I get the
following error when trying to marshal this class.

Nested error: org.exolab.castor.mapping.MappingException: The Java class
org.xoscript.server.event.ServerEvent is not constructable -- it does

not

contain a default public constructor


public class ServerEvent extends EventObject{

  public String target = null;

  public ServerEvent (Object source, String targ){
      super(source);
      this.setTarget(targ);
  }

  getter and setters......
}

I want to ignore source in the output xml, that is way it is missing.
<class name="org.xoscript.server.event.ServerEvent">

  <field name="target" type="java.lang.String" direct="false">

      <bind-xml name="target" node="attribute"/>

  </field>

</class>

Bryan LaPlante



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




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





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




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






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

Reply via email to