Return-Path: Delivered-To: apmail-felix-dev-archive@www.apache.org Received: (qmail 88533 invoked from network); 1 Aug 2008 15:32:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Aug 2008 15:32:48 -0000 Received: (qmail 1039 invoked by uid 500); 1 Aug 2008 15:32:47 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 714 invoked by uid 500); 1 Aug 2008 15:32:46 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 703 invoked by uid 99); 1 Aug 2008 15:32:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Aug 2008 08:32:46 -0700 X-ASF-Spam-Status: No, hits=-2.0 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of brucej@qualcomm.com designates 199.106.114.254 as permitted sender) Received: from [199.106.114.254] (HELO wolverine01.qualcomm.com) (199.106.114.254) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Aug 2008 15:31:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qualcomm.com; i=brucej@qualcomm.com; q=dns/txt; s=qcdkim; t=1217604754; x=1249140754; h=from:to:date:subject:thread-topic:thread-index: message-id:in-reply-to:accept-language:content-language: x-ms-has-attach:x-ms-tnef-correlator:acceptlanguage: content-type:mime-version:x-ironport-av; z=From:=20"Jackson,=20Bruce"=20|To: =20"dev@felix.apache.org"=20|Date: =20Fri,=201=20Aug=202008=2008:31:11=20-0700|Subject:=20Re :=20Classloading=20across=20bundles|Thread-Topic:=20Class loading=20across=20bundles|Thread-Index:=20Acjz6vk/tY9jU7 8hTD2npJD84qECTAAAKbqf|Message-ID:=20|In-Reply-To:=20<87eb8aee0808010825p23c2a7 4ld5ee5b4e088ebb63@mail.gmail.com>|Accept-Language:=20en- US|Content-Language:=20en|X-MS-Has-Attach: |X-MS-TNEF-Correlator:|acceptlanguage:=20en-US |Content-Type:=20multipart/alternative=3B=0D=0A=09boundar y=3D"_000_C4B8EACF4B55brucejqualcommcom_"|MIME-Version: =201.0|X-IronPort-AV:=20E=3DMcAfee=3Bi=3D"5200,2160,5351" =3B=20a=3D"5240994"; bh=Hbgka/3WGQFYQElYjULXpME00VVcrRleDGjlqekeCP0=; b=yZhbPxujgWuoEBbpxs3juJ5pmxMPhwjQB7U1/ARjOD0uE75gvIIcfFJ6 lT9veudHQkV5QTzVkMdUfDzOKlYUJ7xwAztheW1V21UALRuXHzv0bmaDg tK18q6rsijwoBJp8kx8KDHDUuw0qTNIi2pQ3spQKcFpHfN2ZELpkp8IcU 4=; X-IronPort-AV: E=McAfee;i="5200,2160,5351"; a="5240994" Received: from pdmz-ns-mip.qualcomm.com (HELO ithilien.qualcomm.com) ([199.106.114.10]) by wolverine01.qualcomm.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Aug 2008 08:31:14 -0700 Received: from totoro.qualcomm.com (totoro.qualcomm.com [129.46.61.158]) by ithilien.qualcomm.com (8.14.2/8.14.2/1.0) with ESMTP id m71FVDsp011701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 1 Aug 2008 08:31:13 -0700 Received: from nasanexhc01.na.qualcomm.com (nasanexhc01.na.qualcomm.com [172.30.37.21]) by totoro.qualcomm.com (8.14.2/8.14.2/1.0) with ESMTP id m71FVDgv017150 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Fri, 1 Aug 2008 08:31:13 -0700 (PDT) Received: from NASANEXMB02.na.qualcomm.com ([10.45.77.209]) by nasanexhc01.na.qualcomm.com ([172.30.37.21]) with mapi; Fri, 1 Aug 2008 08:31:12 -0700 From: "Jackson, Bruce" To: "dev@felix.apache.org" Date: Fri, 1 Aug 2008 08:31:11 -0700 Subject: Re: Classloading across bundles Thread-Topic: Classloading across bundles Thread-Index: Acjz6vk/tY9jU78hTD2npJD84qECTAAAKbqf Message-ID: In-Reply-To: <87eb8aee0808010825p23c2a74ld5ee5b4e088ebb63@mail.gmail.com> Accept-Language: en-US Content-Language: en X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: multipart/alternative; boundary="_000_C4B8EACF4B55brucejqualcommcom_" MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org --_000_C4B8EACF4B55brucejqualcommcom_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Yes, the code in ObjectFactory is basically: public static Object getObject(Class clazz) { ... obj=3D Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz= , ObjectManagement.class}, new Invoker(clazz, id, tableName)); ... return obj; } That's throws a ClassNotFoundException, I assume, because clazz (declared i= n B and not imported explicitly in A) is not loadable from with A. On 01/08/2008 16:25, "Alin Dreghiciu" wrote: Do you use Proxy.newProxyInstance? The first param of this method is a class loader. So, what is the value you use for that param? In my view you should use the clazz.getClassLoader that is equal with the class loader that loaded Foo. And it should not matter that you export or not the the package that contains Foo. On Fri, Aug 1, 2008 at 5:17 PM, Jackson, Bruce wrote: > I'm not passing any classloader with my class, just the object Foo.class. > > The issue is that bundle B (which is the caller to ObjectFactory declared= in A) does not export Foo.class, and thus the class loader in A can't see = it. > Now that's well, and good for most cases since I can always export the pa= ckage that Foo.class is contained within, and import it in bundle A, but in= this case, ObjectFactory becomes rather useless since its trying to offer = a generic facility. > > I've tried getting the classloader of Foo.class, but that fails in the sa= me way with a ClassNotFoundException. I could go through the pain in B of g= etting the bytes that make up the class, passing them to ObjectFactory and = then doing a defineClass() there, but that seems to be very complex. > > > On 01/08/2008 16:09, "Alin Dreghiciu" wrote: > > What class loader are you pasing to Proxy.newProxyInstance? You should > pass the one of the class you send as parameter so in your case > clazz.getClassLoader. > > On Fri, Aug 1, 2008 at 4:57 PM, Jackson, Bruce wrot= e: >> Sorry, I don't think I made myself particularly clear: >> >> I have a bundle "A" which exports a package containing a class (ObjectFa= ctory.class) with the method: >> >> public static Object getObject(Class clazz); >> >> This method creates a dynamic proxy object to be returned to the caller. >> I have bundles B, C, and D which wish to make use of this class, and whi= ch will call it passing an interface, for example: >> >> Foo foo =3D (Foo) ObjectFactory.getObject(Foo.class); >> >> However, ObjectFactory throws a ClassNotFoundException because Foo.class= is not in the import list for bundle A. Is there a way of allowing this? >> >> >> On 01/08/2008 15:14, "Richard S. Hall" wrote: >> >> Jackson, Bruce wrote: >>> Here's a question: >>> >>> I have a utility class in a bundle which will generate a dynamic proxy = as a >>> service to other bundles running inside Felix. Lets call this bundle "A= ". >>> >>> Is this possible in Felix/OSGi without having having to explicitly decl= are >>> the import of the interface over which A will operate? >>> >> >> Well, you can get access to the interface class definition by calling >> Bundle.loadClass() on bundle A without importing from A, so then you >> should be able to use that to create the proxy, I would imagine. >> >> -> richard >> >>> Thanks >>> >>> Bruce >>> >>> >> >> > > > > -- > Alin Dreghiciu > http://www.ops4j.org - New Energy for OSS Communities - Open > Participation Software. > http://www.qi4j.org - New Energy for Java - Domain Driven Development. > http://malaysia.jayway.net - New Energy for Projects - Great People > working on Great Projects at Great Places > > -- Alin Dreghiciu http://www.ops4j.org - New Energy for OSS Communities - Open Participation Software. http://www.qi4j.org - New Energy for Java - Domain Driven Development. http://malaysia.jayway.net - New Energy for Projects - Great People working on Great Projects at Great Places --_000_C4B8EACF4B55brucejqualcommcom_--