Return-Path: Delivered-To: apmail-db-jdo-dev-archive@www.apache.org Received: (qmail 28308 invoked from network); 22 Dec 2008 19:16:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Dec 2008 19:16:47 -0000 Received: (qmail 50428 invoked by uid 500); 22 Dec 2008 19:16:47 -0000 Mailing-List: contact jdo-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-dev@db.apache.org Delivered-To: moderator for jdo-dev@db.apache.org Received: (qmail 45213 invoked by uid 99); 22 Dec 2008 19:13:16 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=STOX_REPLY_TYPE X-Spam-Check-By: apache.org Received-SPF: unknown (nike.apache.org: error in processing during lookup of kirsh@mta.ac.il) Date: Mon, 22 Dec 2008 21:11:46 +0200 From: Ilan Kirsh Subject: Re: Enhancer specification text for discussion To: jdo-dev@db.apache.org Message-id: MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Mailer: Microsoft Outlook Express 6.00.2900.5512 Content-type: text/plain; format=flowed; charset=iso-8859-1; reply-type=original Content-transfer-encoding: 7BIT X-Priority: 3 X-MSMail-priority: Normal References: <04F61E29-96C4-4E8C-B130-34E559311202@SUN.com> <1DDA5E55-4BBE-4E4C-8D5F-D380DDAF7BBD@SUN.com> <214FE566AA31412AAE4AB255D889325D@ilanc> <91E4B814-3EAD-487F-B84D-8BD2D0A2BDA2@Sun.COM> X-Virus-Checked: Checked by ClamAV on apache.org >>>> 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