db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ilan Kirsh <ki...@mta.ac.il>
Subject Re: Enhancer specification text for discussion
Date Mon, 22 Dec 2008 19:11:46 GMT
>>>> Is class name supported?
>>> That's an open question in my mind. How would you propose that the
>>> enhancer find the file corresponding to the class?
>>> 1. The class loader might not want to give you access to the file,
>>> especially for example if it was loaded from a jar. In that case,  what
>>> you need is the path to the jar or the resource name of the  jar.
>>> 2. As far as I know, there's no reverse translation of class loader  +
>>> class name to file name.
>>
>> It is just more user friendly to let the user specify a class name  and
>> let
>> the implementation convert the class name into resource name by adding
>> a ".class" suffix and replacing '.' with '/'.
>
> This will fail if the class to be enhanced is in a jar file, right? Do  we
> warn users about this problem?
>
> Craig

Why should it fail (assuming the jar is in the classpath)?

>> I don't suggest other changes, so the class will be loaded as a  resource
>> and "-d" will still be required in this case.
>>
>> Ilan

I just checked and found that ObjectDB Enhancer does not require
-d in that case. Given an ordinary resource URL you can find the exact
location of the file or zip entry that contains it:

        private void loadTypeFromUrl(URL url) throws IOException
        {
            // Handle a class file:
            String protocol = url.getProtocol();
            if ("file".equals(protocol))
            {
                File file = new File(
                    URLDecoder.decode(url.getFile(), "UTF8"));
                if (!file.isDirectory())
                    loadTypeFromFile(file);
            }

            // Handle a JAR file:
            else if ("jar".equals(protocol))
            {
                JarURLConnection con =
                    (JarURLConnection)url.openConnection();
                loadTypeFromZipEntry(con.getJarFile(), con.getJarEntry());
            }
        }

Ilan






Mime
View raw message