Robert, 

In general I believe - after looking into source code for a few minutes - that 
the UnmarshalListener interface should be extended, adding a new method similar 
to your attributeProcessed(String, String) (though I am not sure whether this 
shouldn't be attributeProcessed(String, Object)).

Why not open a feature request at

http://jira.codehaus.org/browse/CASTOR

and we'll take it from there.

Werner

> -----Ursprüngliche Nachricht-----
> Von: Robert La Ferla [mailto:[EMAIL PROTECTED]
> Gesendet: Montag, 14. Mai 2007 19:35
> An: dev@castor.codehaus.org
> Betreff: [castor-dev] AttributeListener interface
> 
> I am preparing to port our software to use castor 1.1.1 and I have
> one Castor customization that I think may be useful for the main
> release.  It allows you to specify an object in your application (a
> delegate) that listens to attributes as they are being unmarshalled.
> 
> I have created an interface called AttributeListener that defines a
> single method:
> 
> public interface AttributeListener {
>       public void processAttribute(String attName, String attValue)
> }
> 
> Simply implement this on a class in your application and tell the
> unmarshaller to use your object as the attribute listener.  When
> objects are unmarshalled, your method gets called and gives you a
> chance to monitor the attributes being loaded in.  In the example
> below, the "ID" attribute and it's value are stored in a map.  After
> the object has been fully unmarshalled, a substitution is performed
> on the object.  This is useful in an application which has a master
> document that imports template documents.
> 
> public MyClass implements AttributeListener {
> 
>       ...
> 
>       public void processAttribute(String attName, String attValue) {
>               if (attName.equals("ID") == true) {
>                       String newValue;
> 
>                       newValue = org.myproject.ObjectType.newObjectID();
>                       // key = old ID, value = new ID
>                       oldIDtoNewIDMap.put(attValue, newValue);
>               }
>       }
> 
>       ...
> }
> 
> I am not aware of a way to do this without a customized Castor.  If
> there is enough interest, I will submit a patch.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
> 
>     http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to