On Dec 22, 2008, at 11:11 AM, Ilan Kirsh wrote:

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)?

My mistake.


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());
          }
      }

Just to clarify, as I have not used these particular APIs:

Does this allow the enhancer to get a read/write File handle for a URL that's in the classpath? And if it's a jar file, does it allow the enhancer to replace files within it?

Craig

Ilan






Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:[email protected]
P.S. A good JDO? O, Gasp!

Reply via email to