If I understand your question correctly, activators must have a default
constructor. You cannot have an activator that takes arguments, because
the framework has no way of supplying them.

-> richard


On 8/6/09 23:42, MichaelMichael wrote:
> Hi, Richard
> Thanks a lot for you help .Exactly what I want to know .One more short 
> question please , thanks .I examine the code of Felix and find the place : 
> Felix.createBundleActivator [1]
> What is the case when it comes to classes that newInstance() are not 
> applicable , for example there is no constructor without a parameter .Is 
> there a workaround other than newInstance() ?Thanks !![1] if (className != 
> null)        {            className = className.trim();            Class 
> clazz;            try            {                clazz = 
> impl.getCurrentModule().getClassByDelegation(className);            }         
>    catch (ClassNotFoundException ex)            {                throw new 
> BundleException("Not found: " + className, ex);            }            
> activator = (BundleActivator) clazz.newInstance();        }
>
>   
>> Date: Thu, 6 Aug 2009 10:44:58 -0400
>> From: he...@ungoverned.org
>> To: users@felix.apache.org
>> Subject: Re: A questions about the classloading mechanism in Felix
>>
>> On 8/6/09 10:24, MichaelMichael wrote:
>>     
>>> Hi Richard
>>> Thanks for the reply.
>>> Right , the moduleClassloaderBut how does the jvm know which classloader to 
>>> pick ??There are a number of bundles and so a number of modules Is there 
>>> some tricks inside ?
>>>   
>>>       
>> It uses the class loader of the class needing to load the class.
>> Essentially, what happens is this:
>>
>>    1. The OSGi framework creates a class loader for each bundle.
>>    2. The OSGi framework loads the bundle's activator class using its
>>       class loader.
>>    3. Any classes needed by the activator (and thus all of the bundle)
>>       are requested from its class loader.
>>
>> So, the JVM always starts with the class loader of the class which is
>> executing. We don't need to worry about this, it is automatic. Now, not
>> all classes will come from the bundle, some will come from other
>> bundles. In standard Java classes are only loaded from parent class
>> loaders, but in OSGi parent class loaders are not used much.
>>
>> Instead, the bundle's class loader is "wired" to other bundle class
>> loaders (based on imports). So, when a request comes in for a class
>> (such as "new Foo()"), the instigating bundle's class loader is asked,
>> at which point it will go out and ask other bundles if it is importing
>> from them. This part happens in OSGi and it is framework implementation
>> specific.
>>
>> -> richard
>>
>>     
>>>   
>>>       
>>>> Date: Thu, 6 Aug 2009 10:03:43 -0400
>>>> From: he...@ungoverned.org
>>>> To: users@felix.apache.org
>>>> Subject: Re: A questions about the classloading mechanism in Felix
>>>>
>>>> When a bundle loads a class it does NOT go through
>>>> Bundle.loadClass()...this is only if outside code wants to load a class
>>>> from a bundle. When a bundle loads a class, it is loaded from its own
>>>> class loader (called ModuleClassLoader in trunk). The call to this class
>>>> loader's loadClass() method is done automatically by the JVM as needed.
>>>>
>>>> -> richard
>>>>
>>>> On 8/5/09 22:27, MichaelMichael wrote:
>>>>     
>>>>         
>>>>> Hi all
>>>>> I studying classloading's in felix.I have made many search but there is 
>>>>> still one thing I don't understand .
>>>>> The question :(correct if I am wrong )As we know a "new" will invoke a 
>>>>> java.lang.classloader.load class normally.In felix , after the 
>>>>> frameword(Felix) started , a  "new ClassType()"(take the ClassType be a 
>>>>> class could be found by the bundle ) will invoke the loadclass of 
>>>>> Bundle.loadclass .I am always wandering how could this happens .I 
>>>>> followed the source code , and also also tried the 
>>>>> thread.setcontextclassloader,all failed .Recently I found that this 
>>>>> should replace the systemclassloader ,is this correct ?But how to replace 
>>>>> it after the launching of Felix ? 
>>>>> Could anyone please explain this to me ?
>>>>> Thanks a billion !!!
>>>>>
>>>>> RegardsMichael 
>>>>> _________________________________________________________________
>>>>> 您可以借助 Windows Live 整理、编辑和共享您的照片。
>>>>> http://www.microsoft.com/china/windows/windowslive/products/photo-gallery-edit.aspx
>>>>>   
>>>>>       
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
>>>> For additional commands, e-mail: users-h...@felix.apache.org
>>>>
>>>>     
>>>>         
>>> _________________________________________________________________
>>> 上Windows Live 中国首页,下载最新版Messenger!
>>> http://www.windowslive.cn
>>>   
>>>       
> _________________________________________________________________
> 您可以借助 Windows Live 整理、编辑和共享您的照片。
> http://www.microsoft.com/china/windows/windowslive/products/photo-gallery-edit.aspx
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to