Yes, I was on the point to say that. This is from JavaDoc of Proxy:

"All of the interface types must be visible by name through the
specified class loader."

You may try to define your own class loader that will delegate to the
class loader of clazz and use as parent the class loader of the bundle
that defines the ObjectManagement. But you are on mined ground.

On Fri, Aug 1, 2008 at 5:51 PM, Karl Pauls <[EMAIL PROTECTED]> wrote:
> my guess would be it's the objectmanagment class that can not be found by
> the classloader of the Foo class :-)
>
> regards,
>
> Karl
>
> Am 01.08.2008 um 17:31 schrieb "Jackson, Bruce" <[EMAIL PROTECTED]>:
>
>> Yes, the code in ObjectFactory is basically:
>>
>> public static Object getObject(Class clazz) {
>>
>>   ...
>>   obj= 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
>> in B and not imported explicitly in A) is not loadable from with A.
>>
>> On 01/08/2008 16:25, "Alin Dreghiciu" <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>
>> 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
>>> package 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
>>> same way with a ClassNotFoundException. I could go through the pain in B of
>>> getting 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" <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>
>>> wrote:
>>>>
>>>> Sorry, I don't think I made myself particularly clear:
>>>>
>>>> I have a bundle "A" which exports a package containing a class
>>>> (ObjectFactory.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
>>>> which will call it passing an interface, for example:
>>>>
>>>> Foo foo = (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" <[EMAIL PROTECTED]> 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
>>>>> declare
>>>>> 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
>>
>



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

Reply via email to