View Javadoc

    1   package org.codehaus.xfire.picocontainer;
    2
    3   import java.net.URL;
    4   import java.util.Map;
    5
    6   import org.codehaus.xfire.picocontainer.util.PicoObjectInvoker;
    7   import org.codehaus.xfire.service.Service;
    8   import org.codehaus.xfire.service.ServiceFactory;
    9   import org.codehaus.xfire.service.binding.BindingProvider;
    10  import org.codehaus.xfire.service.binding.ObjectBinding;
    11  import org.codehaus.xfire.service.binding.ObjectServiceFactory;
    12  import org.codehaus.xfire.soap.SoapVersion;
    13  import org.codehaus.xfire.transport.TransportManager;
    14  import org.picocontainer.PicoContainer;
    15  import org.picocontainer.defaults.ObjectReference;
    16  import org.picocontainer.defaults.SimpleReference;
    17
    18  /***
    19   * PicoContainer specialization of Java objects-specific implementation of the
    20   * {@link ServiceFactory} interface which uses a given picocontainer to pick
    21   * service objects instance when it's about to invoke them.
    22   *
    23   * @author <a href="mailto:juze@intelli.biz">Jose Peleteiro</a>
    24   */
    25  public class PicoObjectServiceFactory
    26      extends ObjectServiceFactory
    27  {
    28      private ObjectReference picoReference;
    29
    30      public PicoObjectServiceFactory(PicoContainer pico)
    31      {
    32          super();
    33          picoReference = new SimpleReference();
    34          picoReference.set(pico);
    35      }
    36
    37      public PicoObjectServiceFactory(ObjectReference picoReference)
    38      {
    39          super();
    40          this.picoReference = picoReference;
    41      }
    42
    43      public PicoObjectServiceFactory(PicoContainer pico, TransportManager transportManager,
    44              BindingProvider provider)
    45      {
    46          super(transportManager, provider);
    47          picoReference = new SimpleReference();
    48          picoReference.set(pico);
    49      }
    50
    51      public PicoObjectServiceFactory(ObjectReference picoReference,
    52              TransportManager transportManager, BindingProvider provider)
    53      {
    54          super(transportManager, provider);
    55          this.picoReference = picoReference;
    56      }
    57
    58      public Service create(Class clazz, String name, String namespace, Map properties)
    59      {
    60          return prepare(super.create(clazz, name, namespace, properties));
    61      }
    62
    63      public Service create(Class clazz,
    64                            String name,
    65                            String namespace,
    66                            SoapVersion version,
    67                            String style,
    68                            String use,
    69                            Map properties)
    70      {
    71          return prepare(super.create(clazz, name, namespace, version, style, use, properties));
    72      }
    73
    74      public Service create(Class clazz, URL wsdlUrl)
    75          throws Exception
    76      {
    77          return prepare(super.create(clazz, wsdlUrl));
    78      }
    79
    80      public Service create(Class clazz)
    81      {
    82          return prepare(super.create(clazz));
    83      }
    84
    85      /***
    86       * Prepare an ObjectService to use pico.
    87       */
    88      protected Service prepare(Service endpoint)
    89      {
    90          ((ObjectBinding) endpoint.getBinding()).setInvoker(new PicoObjectInvoker(picoReference,
    91                  endpoint.getServiceInfo().getServiceClass()));
    92          return endpoint;
    93      }
    94  }