View Javadoc

    1   package org.codehaus.xfire;
    2
    3   import java.io.IOException;
    4   import java.io.OutputStream;
    5   import java.util.ArrayList;
    6   import java.util.List;
    7
    8   import org.apache.commons.logging.Log;
    9   import org.apache.commons.logging.LogFactory;
    10  import org.codehaus.xfire.handler.AbstractHandlerSupport;
    11  import org.codehaus.xfire.handler.DispatchServiceHandler;
    12  import org.codehaus.xfire.handler.ParseMessageHandler;
    13  import org.codehaus.xfire.handler.Phase;
    14  import org.codehaus.xfire.service.DefaultServiceRegistry;
    15  import org.codehaus.xfire.service.Service;
    16  import org.codehaus.xfire.service.ServiceRegistry;
    17  import org.codehaus.xfire.transport.DefaultTransportManager;
    18  import org.codehaus.xfire.transport.TransportManager;
    19  import org.codehaus.xfire.wsdl.WSDLWriter;
    20
    21  /***
    22   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    23   * @since Feb 13, 2004
    24   */
    25  public class DefaultXFire
    26          extends AbstractHandlerSupport
    27          implements XFire
    28  {
    29      private ServiceRegistry registry;
    30
    31      private TransportManager transportManager;
    32
    33      private static final Log logger = LogFactory.getLog(DefaultXFire.class);
    34
    35      private List inPhases;
    36      private List outPhases;
    37      private List faultPhases;
    38
    39      public DefaultXFire()
    40      {
    41          registry = new DefaultServiceRegistry();
    42          transportManager = new DefaultTransportManager(registry);
    43
    44          createPhases();
    45          createHandlers();
    46      }
    47
    48      public DefaultXFire(final ServiceRegistry registry,
    49                          final TransportManager transportManager)
    50      {
    51          this.registry = registry;
    52          this.transportManager = transportManager;
    53
    54          createPhases();
    55          createHandlers();
    56      }
    57
    58      protected void createHandlers()
    59      {
    60          addInHandler(new ParseMessageHandler());
    61          addInHandler(new DispatchServiceHandler());
    62      }
    63
    64      /***
    65       * Creates a default list of phases for this XFire instance.
    66       */
    67      protected void createPhases()
    68      {
    69          inPhases = new ArrayList();
    70          inPhases.add(new Phase(Phase.TRANSPORT, 1000));
    71          inPhases.add(new Phase(Phase.PARSE, 2000));
    72          inPhases.add(new Phase(Phase.PRE_DISPATCH, 3000));
    73          inPhases.add(new Phase(Phase.DISPATCH, 4000));
    74          inPhases.add(new Phase(Phase.POLICY, 5000));
    75          inPhases.add(new Phase(Phase.USER, 6000));
    76          inPhases.add(new Phase(Phase.PRE_INVOKE, 7000));
    77          inPhases.add(new Phase(Phase.SERVICE, 8000));
    78
    79          outPhases = new ArrayList();
    80          outPhases.add(new Phase(Phase.POST_INVOKE, 1000));
    81          outPhases.add(new Phase(Phase.POLICY, 2000));
    82          outPhases.add(new Phase(Phase.USER, 3000));
    83          outPhases.add(new Phase(Phase.TRANSPORT, 4000));
    84          outPhases.add(new Phase(Phase.SEND, 5000));
    85
    86          faultPhases = new ArrayList();
    87          faultPhases.add(new Phase(Phase.POLICY, 1000));
    88          faultPhases.add(new Phase(Phase.USER, 2000));
    89          faultPhases.add(new Phase(Phase.TRANSPORT, 3000));
    90          faultPhases.add(new Phase(Phase.SEND, 4000));
    91      }
    92
    93      protected Service findService(final String serviceName)
    94      {
    95          Service service = getServiceRegistry().getService(serviceName);
    96
    97          if (service == null)
    98          {
    99              throw new XFireRuntimeException("Couldn't find service " + serviceName);
    100         }
    101
    102         return service;
    103     }
    104
    105     public void generateWSDL(final String serviceName, final OutputStream out)
    106     {
    107         try
    108         {
    109             final WSDLWriter wsdl = getWSDL(serviceName);
    110
    111             wsdl.write(out);
    112         }
    113         catch (IOException e)
    114         {
    115             throw new XFireRuntimeException("Couldn't generate WSDL.", e);
    116         }
    117     }
    118
    119     private WSDLWriter getWSDL(final String serviceName)
    120     {
    121         final Service service = findService(serviceName);
    122         return service.getWSDLWriter();
    123     }
    124
    125     public ServiceRegistry getServiceRegistry()
    126     {
    127         return registry;
    128     }
    129
    130     public TransportManager getTransportManager()
    131     {
    132         return transportManager;
    133     }
    134
    135     public List getInPhases()
    136     {
    137         return inPhases;
    138     }
    139
    140     public void setInPhases(List inPhases)
    141     {
    142         this.inPhases = inPhases;
    143     }
    144
    145     public List getOutPhases()
    146     {
    147         return outPhases;
    148     }
    149
    150     public void setOutPhases(List outPhases)
    151     {
    152         this.outPhases = outPhases;
    153     }
    154
    155     public List getFaultPhases()
    156     {
    157         return faultPhases;
    158     }
    159
    160     public void setFaultPhases(List faultPhases)
    161     {
    162         this.faultPhases = faultPhases;
    163     }
    164 }