On Thu, 01 Oct 1998 19:58:11 -0400, Andrew V. Shuvalov wrote:

>Hi!
>
>   I have continous problems trying to call "invoke" in
>java.lang.reflect.Method class. I spend several hours and have the
>impression that it is not implemented. I use
>redhat-5.1 and
>jdk-1.1.6sn-1.1glibc package
>
>1) Did somebody ever happens to run "invoke"?
>2) What is the most stable and/or complete Java for Linux distribution?
>( I see many choices on ftp.redhat.com )

I use Invoke in my server support classes all the time.
This has worked in the Linux JDK since 1.1.5 at least (I think
that was when this code went into service on a Linux box)
This code is currently running in all JDK 1.1.6 versions on Linux.
(Including the current test of the v5 changes)

Here is an example of the code:

        /**
         * This method is called to process the command that this
         * entry is for.  It uses reflection to find the command
         * and process it in the handler object.
         *
         * @param context The command context that the command handler will need.
         */
        public void HandleCommand(CommandContext context)
        {
                if (Method == null)
                {
                        // We assume that this is to be handled by the
                        // context itself...
                        context.nullMethod();
                }
                else
                {
                        CommandProcessor handler=context.getProcessor();

                        // First, get the class of the handler object...
                        java.lang.Class handlerClass=handler.getClass();

                        // Just in case the method is not there...
                        try
                        {
                                // Now, get the method for this command...
                                java.lang.reflect.Method handlerMethod;
                                
handlerMethod=handlerClass.getMethod(Method,HandlerArgTypes);

                                // Put together the argument array...
                                Object[] args=new Object[1];
                                args[0]=context;

                                // Just in case there is a access/invoke violation...
                                try
                                {
                                        // Finally, we need to invoke the method...
                                        handlerMethod.invoke(handler,args);
                                }
                                catch (java.lang.IllegalAccessException e)
                                {
                                        // Let the user know (and thus let the system 
know)
                                        // This should really never happen.
                                        context.Error(e.toString());
                                }
                                catch (java.lang.reflect.InvocationTargetException e)
                                {
                                        // Let the user know (and thus let the system 
know)
                                        // This should really never happen.
                                        context.Error(e.toString());
                                }
                        }
                        catch (java.lang.NoSuchMethodException e)
                        {
                                // Let the user know (and thus let the system know)
                                // This should really never happen.
                                context.Error(e.toString());
                        }
                }
        }


Michael Sinz -- Director of Research & Development, NextBus Inc.
mailto:[EMAIL PROTECTED] --------- http://www.nextbus.com
My place on the web ---> http://www.users.fast.net/~michael_sinz

Reply via email to