Thanks for reply. 
I think the (B) is the best,but I have some questions on this.
Please see my comments below. 

Thanks,  
wangfeng


On 2007-12-11, Jean-Sebastien Delfino <[EMAIL PROTECTED]> wrote:

>wang feng wrote:
>> Hi,all
>>     I has a scenario as below.
>>     When get a service,I want to use a common service class such as 
>> 'ServiceInvoker'.
>>     The use of the common class like a class reflect.
>> 
>> ServiceInvoker.java
>> public interface ServiceInvoker{
>>      Object  invoke(String methodName,Class[] argType,Object[] args);
>> }
>> 
>> Calculator example:
>> CalculatorService calculatorService = 
>> scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent");
>> double res = calculatorService.add(3.0, 2.0)
>> 
>> To
>> ServiceInvoker invoker =  scaDomain.getService("CalculatorServiceComponent");
>> Object res = invoker.invoke("add",new Class[]{Double.class,Double.class},new 
>> Double[]{2.0,3.0});
>> 
>> How can I do for this,anyone has advice.
>>                              
>> Thanks
>> Wang Feng
>> 
>
>You can do the following:
>
>(A) use reflection, not very different from your ServiceInvoker:
>
>Object service = scaDomain.getService("CalculatorServiceComponent");
>
What the instance of the result 'getService'?
When get a servcice by DefaultSCADomain, we must supply a interface of the 
service.
If not supply a interface ,there may be an error.

>Object res = service.getClass().
>  getMethod("add", new Class[]{Double.class, Double.class}).
>    invoke(new Double[]{2.0, 3.0});
>
>(B) Create a utility class wrapping the above code to provide the
>invocation API you want:
>
>Object res = ServiceInvoker.invoke(service, "add",
>  new Class[]{Double.class, Double.class}, new Double[]{2.0, 3.0}
>
>(C) Customize the Tuscany JDKProxyFactory (to create proxies that
>implement your ServiceInvoker interface) or come up with a different
>implementation of ProxyFactory and configure the runtime to use it.
>
>I would suggest to:
>
>- Try to go with (A) as it's a standard API, not much more complicated
>than ServiceInvoker, and will probably perform better as it allows the
>caller to cache the Class and Method in variables instead of looking up
>the "add" method for each call.
>
>- If (A) really does not meet your requirements go with (B), which
>provides almost the same API as your ServiceInvoker on top of standard
>Java reflection.
>
>- Do (C) only if you really can't do (A) or (B), as with (C) you are
>starting to be dependent on Tuscany SPIs and a specific customization of
>the Tuscany runtime. You're also stepping away from the SCA standard as
>your applications will start to depend on that non-standard
>ServiceInvoker and its implementation as a customization of Tuscany.
>
>Hope this helps.
>-- 
>Jean-Sebastien
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to