View Javadoc

    1   package org.codehaus.xfire.plexus.transport.xmpp;
    2
    3   import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
    4   import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
    5   import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
    6   import org.codehaus.plexus.personality.plexus.lifecycle.phase.ServiceLocator;
    7   import org.codehaus.plexus.personality.plexus.lifecycle.phase.Serviceable;
    8   import org.codehaus.xfire.XFire;
    9   import org.codehaus.xfire.XFireRuntimeException;
    10  import org.codehaus.xfire.transport.TransportManager;
    11  import org.codehaus.xfire.xmpp.XMPPTransport;
    12
    13  /***
    14   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    15   */
    16  public class DefaultXMPPTransportService
    17      implements Initializable, Serviceable, Disposable
    18  {
    19      private String username;
    20      private String password;
    21      private String server;
    22      private ServiceLocator locator;
    23      private XMPPTransport transport;
    24
    25      /***
    26       * @throws Exception
    27       */
    28      public void initialize()
    29      {
    30          transport = new XMPPTransport(getXFire(), server, username, password);
    31          getTransportManager().register(transport);
    32      }
    33
    34      public XFire getXFire()
    35      {
    36          try
    37          {
    38              return (XFire) locator.lookup(XFire.ROLE);
    39          }
    40          catch (ComponentLookupException e)
    41          {
    42              throw new XFireRuntimeException("Couldn't find component.", e);
    43          }
    44      }
    45
    46      public TransportManager getTransportManager()
    47      {
    48          try
    49          {
    50              return (TransportManager) locator.lookup(TransportManager.ROLE);
    51          }
    52          catch (ComponentLookupException e)
    53          {
    54              throw new XFireRuntimeException("Couldn't find component.", e);
    55          }
    56      }
    57
    58      /***
    59       * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Serviceable#service(org.codehaus.plexus.personality.plexus.lifecycle.phase.ServiceLocator)
    60       */
    61      public void service(ServiceLocator locator)
    62      {
    63          this.locator = locator;
    64      }
    65
    66      public void dispose()
    67      {
    68          transport.dispose();
    69      }
    70  }