db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kathey Marsden <kmarsdende...@sbcglobal.net>
Subject How can I get sysinfo for a custom Derby classloader?
Date Wed, 22 Feb 2006 19:21:45 GMT
Two questions
1) How can I get sysinfo  if  Derby is loaded in a custom Class Loader?
2)  Will DERBY-668 mean that it won't print the right information
anyway,  even if I get the coding right?

Below are some details.

I have a custom ClassLoader DerbyURLClassLoader   and am trying to add a
getSysinfo method to access sysinfo based on the version loaded.  The
code below does not work because  the constructor for sysinfo is not
public.  I could not see how to access the static method with reflection
without instantiating the class and I think need to use reflection so
that it gets loaded from the right place.  

getSysinfo method in DerbyURLClassLoader:

/**
     * Print sysinfo.  Any exceptions will go to out and not be thrown
     * like in sysinfo's getInfo method
     *
     * @param out  PrintWriter for sysinfo output
     */
    public void getSysinfo(PrintWriter out)
    {
        try {
            System.out.println("printSysinfo");
            Object mysysinfo =  
loadClass("org.apache.derby.tools.sysinfo").newInstance();
            Class[] argType = {PrintWriter.class};
            Object[] args = new Object[] { out};
            Method sh = mysysinfo.getClass().getMethod("getInfo",argType);
            sh.invoke(mysysinfo,args);
        } catch (Exception e)
        {
            out.println("Unexpected exception printing sysinfo");
            e.printStackTrace(out);
           
        }
       
    }

calling code:
            DerbyURLClassLoader loader1 =new DerbyURLClassLoader(urls);
            loader1.getSysinfo(new PrintWriter(System.out,true));


Exception that occurs because sysinfo constructor is not public.

Unexpected exception printing sysinfo
java.lang.IllegalAccessException: Class DerbyURLClassLoader can not
access a member of class org.apache.derby.tools.sysinfo with modifiers
"private"
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
        at java.lang.Class.newInstance0(Class.java:302)
        at java.lang.Class.newInstance(Class.java:261)
        at DerbyURLClassLoader.getSysinfo(DerbyURLClassLoader.java:86)
        at DerbyLoaderApp.main(DerbyLoaderApp.java:32)

Possible workarounds I thought might work but haven't tried
1) Extend  sysinfo and provide a constructor.
2) Create a DerbyUtil class that is instantiated in the loader and make
a getSysinfo method that  would then (hopefully) load things from the
right place.

Neither solution seemed right to me, so I thought I would ask.

Kathey




Mime
View raw message