KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xfire > FactoryInvoker


1 package jfun.yan.xfire;
2
3 import jfun.yan.factory.Factory;
4
5 import org.codehaus.xfire.MessageContext;
6 import org.codehaus.xfire.fault.XFireFault;
7 import org.codehaus.xfire.service.binding.ObjectInvoker;
8
9 /**
10  * This invoker implementation calls a Factory to create the service object
11  * and then applies a scope policy for caching.
12  * @author Ben Yu
13  * Feb 2, 2006 12:55:59 PM
14  */

15 public class FactoryInvoker extends ObjectInvoker {
16   private final Factory factory;
17   private final ScopePolicy scope;
18   /**
19    * Create a FactoryInvoker object.
20    * @param factory the factory used to create service object.
21    * @param scope the scope policy. Null for default.
22    */

23   public FactoryInvoker(Factory factory, ScopePolicy scope) {
24     this.factory = factory;
25     this.scope = scope==null?ApplicationScopePolicy.instance():scope;
26   }
27
28   public Object JavaDoc getServiceObject(MessageContext context)
29       throws XFireFault{
30     return getScopedFactory(context).create();
31   }
32   private Factory getScopedFactory(MessageContext context){
33     return scope.applyScope(factory, context);
34   }
35 }
Popular Tags