tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcel Jansen" <gromm...@languagewise.com>
Subject Re: suggestion for XMLMapper/Setparent
Date Mon, 31 Jul 2000 08:34:27 GMT
I wasn't actually reviewing XmlMapper, but after subclassing
ContextManager and trying to use the subclass with XmlMapper
I stumbled onto this: given a class, a method and its arguments
the XmlMapper code checks for existence and then executes.

An example would be
SomeInterceptorClass.getMethod("setContextManager", new Class[]
 "SomeContextManagerSubclass } )
is used to find the correct method in SetParent.end(..)

however, the only defined method is
Interceptor.setContextManager(ContextManager cm)

and the above won't work because

Interceptor.setContextManager(SomeContextManagerSubclass cm)

is not defined.
I'm sure there's a good reason why Class.getmethod doesn't
take this into account, I'll include a patch.


I've written a number of classes to implement the UPnP service
discovery protocol
(http://www.upnp.org/UPnPDevice_Architecture_1.0.htm chapter 1)
and integrated it into tomcat. For this I needed resident/daemon objects
that weren't servlets. I thought the best place to start and stop
these objects was from a contextManager. The tomcat 3.1 code isn't
always very extension friendly, too bad catalina isn't quite there yet.

patch for SetParent:

class SetParent extends XmlAction {
    String childM;
    public SetParent(String c) {
        childM=c;
    }

    public void end( SaxContext ctx) throws Exception {

        boolean found = false;
        Class current;
        Method m;

        Stack st=ctx.getObjectStack();

        Object obj=st.pop();
        Object parent=st.peek();
        st.push( obj ); // put it back

        String parentC=parent.getClass().getName();
        if (ctx.getDebug() > 0) ctx.log("Calling " +
obj.getClass().getName() + "." + childM +
                                        " " + parentC);

        // --MJ-- checks for the arguments for methods, however,
superclasses
        // as arguments will also work
        Class params[]=new Class[1];
        if (paramT==null) {
            current=parent.getClass();
        } else {
            current=Class.forName( paramT );
        }


        while (!found && current != null) {
            params[0]=current;
            try {
                m = obj.getClass().getMethod( childM, params );
                m.invoke(obj, new Object[] { parent} );
                found = true;
            }
            catch (NoSuchMethodException nsme) {
                current = current.getSuperclass();
            }
        }
        if (!found)
            throw new NoSuchMethodException(childM.toString());
    }
}


Marcel

-----Original Message-----
From: Costin Manolache <cmanolache@yahoo.com>
To: tomcat-dev@jakarta.apache.org <tomcat-dev@jakarta.apache.org>
Date: Friday, July 28, 2000 16:34
Subject: Re: suggestion for XMLMapper/Setparent


>I'm glad someone is reviewing XMLMapper :-)
>Can you give more details ( and maybe a patch )?
>
>Also, what kind of extension do you need to ContextManager?
>
>Costin



Mime
View raw message