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

Reply via email to