Hello,

  I've been playing with Digester for quite a while. I use it to make na XML
binding to the proprietory Java object model which is already exists. There
is a lot of challenges in this process, because object model was designed
without having such a task in mind.

  I have the case, when one of the methods requires array of some particular
type to be passed as a parameter. Unfortunately I can only create
java.util.LinkedList with the same content and then I was thinking to use
SetNextRule to call that method. This works for the similar situation with
the CallMethodRule and Digester is using the registered convertors to handle
different types. Unfortunately SetNextRule does not using convertors for the
same situation. This is should be very simple to fix (see end() method of
SetNextRule below).

----
    /**
     * Process the end of this element.
     */
    public void end() throws Exception {

        // Identify the objects to be used
        Object child = digester.peek(0);
        Object parent = digester.peek(1);
        if (digester.log.isDebugEnabled()) {
            if (parent == null) {
                digester.log.debug("[SetNextRule]{" + digester.match +
                        "} Call [NULL PARENT]." +
                        methodName + "(" + child + ")");
            } else {
                digester.log.debug("[SetNextRule]{" + digester.match +
                        "} Call " + parent.getClass().getName() + "." +
                        methodName + "(" + child + ")");
            }
        }

        // Call the specified method
        Class paramTypes[] = new Class[1];
        if (paramType != null) {
            paramTypes[0] =
                    digester.getClassLoader().loadClass(paramType);
        } else {
            paramTypes[0] = child.getClass();
        }

        // Convert parameter to the required type
        if( !paramTypes[ 0].isAssignableFrom( child.getClass()))
          child = ConvertUtils.convert( child, paramTypes[ 0]);

        if (useExactMatch) {

            MethodUtils.invokeExactMethod(parent, methodName,
                new Object[]{ child }, paramTypes);

        } else {

            MethodUtils.invokeMethod(parent, methodName,
                new Object[]{ child }, paramTypes);

        }
    }
----

  I also think that it will be not a bad idea to add the following
constructor to the SetNextRule.

    SetNextRule( String methodName, Class parameterClass)


  regards,
  Eugen Kuleshov


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>

Reply via email to