avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service UnknownServiceException.java ServiceURLFactory.java ServiceURLConnection.java ServicePublisher.java ServiceManagementContext.java ServiceLocator.java Registry.java package.html InvalidPathException.java Handler.java DefaultRegistry.java
Date Tue, 17 Dec 2002 09:58:46 GMT
mcconnell    2002/12/17 01:58:46

  Added:       merlin/src/java/org/apache/avalon/merlin/service
                        UnknownServiceException.java ServiceURLFactory.java
                        ServiceURLConnection.java ServicePublisher.java
                        ServiceManagementContext.java ServiceLocator.java
                        Registry.java package.html
                        InvalidPathException.java Handler.java
                        DefaultRegistry.java
  Log:
  Inital commit of service regstry facilities used within the kernel and block.  These sources are subject to change as service resultion mechanisms will be tied to a block assembly sub-system (in-progress).
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/UnknownServiceException.java
  
  Index: UnknownServiceException.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  
  
  /**
   * Exception to indicate that a requested service is unknown.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public final class UnknownServiceException
      extends Exception
  {
      private final String m_path;
  
      /**
       * Construct a new <code>UnknownServiceException</code> instance.
       *
       * @param path The supplied URL path.
       * @param message The detail message for this exception.
       */
      public UnknownServiceException( final String path, final String message )
      {
          super( message );
          m_path = path;
      }
  
      /**
       * Return the URL path from which the exception was raised.
       * @return the path
       */
      public String getPath()
      {
          return m_path;
      }
  
      /**
       * Return the exception message.
       * @return the message
       */
      public String getMessage()
      {
          return super.getMessage() + " from the url: '" + getPath() + "'";
      }
  
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/ServiceURLFactory.java
  
  Index: ServiceURLFactory.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.net.URLStreamHandler;
  import java.net.URLStreamHandlerFactory;
  
  /**
   * URL protocol handler factory for the native access protocol.
   * @see Handler
   * @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
   */
  public class ServiceURLFactory implements URLStreamHandlerFactory
  {
      /**
       * The default host name.
       */
      private final String m_host;
  
      /**
       * The resource registry.
       */
      private final Registry m_registry;
  
      /**
       * Creation of a new URL factory for the service protocol.
       *
       * @param host the default host
       * @param registry the service resource registry
       */
      public ServiceURLFactory( String host, Registry registry )
      {
          m_host = host;
          m_registry = registry;
      }
  
      /**
       * Returns a stream URL handler for the service protocol.
       * @param protocol the protocol
       * @return a service protocol handler if the supplied protocol is "native" else null
       */
      public URLStreamHandler createURLStreamHandler( String protocol )
      {
          if( protocol.equals( "native" ) )
          {
              return new Handler( m_host, m_registry );
          }
          else
          {
              return null;
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/ServiceURLConnection.java
  
  Index: ServiceURLConnection.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLConnection;
  
  /**
   * URL connection handler for the service protocol. New instances of
   * the <code>ServiceURLConnection</code> are created by a service
   * URL <code>Handler</code> class.
   * @see Handler
   * @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
   */
  public class ServiceURLConnection extends URLConnection
  {
  
      /**
       * The resource registry.
       */
      private Registry m_registry;
  
      /**
       * The URL.
       */
      private URL m_url;
  
      /**
       * the primary object resolved during the establishment of a connection.
       */
      private Object m_object;
  
      /**
       * Creation of a new <code>ServiceURLConnection</code> handler.
       * @param url the base URL
       * @param registry the parent registry
       */
      public ServiceURLConnection( URL url, Registry registry )
      {
          super( url );
          m_url = url;
          m_registry = registry;
      }
  
      /**
       * Establishment of a connection to the object defined by the URL.
       *
       * @exception IOException if an error is raised while attempting to
       *  establish the connection.
       */
      public void connect() throws IOException
      {
          if( m_url == null )
          {
              throw new IOException( "URL has not been initialized." );
          }
  
          try
          {
              m_object = m_registry.resolve( m_url );
          }
          catch( Throwable e )
          {
              final String error = e.toString();
              throw new IOException( error );
          }
      }
  
      /**
       * Returns the object referenced by the URL.
       * @return and service instance
       * @exception IOException if an error occurs whhile attempting to retireve
       *   the object reference.
       */
      public Object getContent() throws IOException
      {
          return getContent( new Class[ 0 ] );
      }
  
      /**
       * Retrieves the contents of this URL connection.
       *
       * @param classes the <code>Class</code> array
       * indicating the requested types
       * @return     the object fetched that is the first match of the type
       *               specified in the classes array. null if none of
       *               the requested types are supported.
       *               The <code>instanceOf</code> operation should be used to
       *               determine the specific kind of object returned.
       * @exception  IOException              if an I/O error occurs while
       *               getting the content.
       */
      public Object getContent( Class[] classes ) throws IOException
      {
          if( m_object == null )
          {
              connect();
          }
          return m_object;
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/ServicePublisher.java
  
  Index: ServicePublisher.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.net.URL;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  
  /**
   * Interface used to register an established service.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public interface ServicePublisher extends ServiceLocator
  {
      /**
       * Returns a list of published appliances.
       * @return the published appliance instances
       */
      Appliance[] getAppliances();
  
      /**
       * Returns a list of sub-registries.
       * @return the subsidiary registries
       */
      URL[] list();
  
      /**
       * Returns a list of sub-registries.
       * @return the subsidiary registries
       */
      ServicePublisher[] getRegistries();
  
      /**
       * Returns a sub-registry by path.
       * @param uri the registry path
       * @return the subsidiary registry
       * @exception UnknownServiceException if the name is invalid
       * @exception InvalidPathException if the name is already in use
       */
      ServicePublisher getRegistry( String uri ) throws UnknownServiceException, InvalidPathException;
  
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/ServiceManagementContext.java
  
  Index: ServiceManagementContext.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.net.MalformedURLException;
  import org.apache.avalon.assembly.appliance.Appliance;
  
  /**
   * Interface used to register an established service.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public interface ServiceManagementContext extends ServiceLocator
  {
  
      /**
       * Creation of a subsidiary service context.
       *
       * @param name the relative name
       * @return the service context object
       * @exception MalformedURLException if the name is invalid
       * @exception IllegalArgumentException if the name is already in use
       */
      ServiceManagementContext createChild( String name )
          throws MalformedURLException, IllegalArgumentException;
  
      /**
       * Bind an appliance to the naming context.
       * @param the appliance
       */
      void bind( Appliance appliance );
  
      /**
       * Unbind an appliance from the naming context.
       * @param appliance the appliance
       */
      void unbind( Appliance appliance );
  
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/ServiceLocator.java
  
  Index: ServiceLocator.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.net.URL;
  
  /**
   * Interface used to register an established service.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public interface ServiceLocator
  {
      /**
       * Returns the base locator URL.
       *
       * @return the locator url
       */
      URL getBase();
  
      /**
       * Resolves an object relative to the supplied URL.
       *
       * @param url the URL
       * @return the object resolved from the supplied URL
       * @exception Exception is an error occurs
       */
      Object resolve( URL url ) throws Exception;
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/Registry.java
  
  Index: Registry.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.net.MalformedURLException;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  
  /**
   * Interface used to register an established service.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public interface Registry extends ServicePublisher
  {
  
      /**
       * Creation of a subsidiary service context.
       *
       * @param name the relative name
       * @return the service context object
       * @exception MalformedURLException if the name is invalid
       * @exception IllegalArgumentException if the name is already in use
       */
      Registry createChild( String name )
          throws MalformedURLException, IllegalArgumentException;
  
      /**
       * Bind a appliance to the naming context.
       * @param appliance the appliance
       */
      void bind( Appliance appliance );
  
      /**
       * Unbind an appliance from the naming context.
       * @param appliance the appliance
       */
      void unbind( Appliance appliance );
  
      /**
       * Select a set of service based on a supplied filter.  A filter is
       * supplied in the form of a URI String.  Interpritation relative to URI path, query,
       * and fragment are protocol dependent.
       *
       * @param path the service uri
       * @return the appliance corresponding to the supplied URL
       * @exception InvalidPathException if the supplied path is invalid
       * @exception UnknownServiceException if the supplied path does not refer to a service
       */
      public Appliance locate( String path ) throws UnknownServiceException, InvalidPathException;
  
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/package.html
  
  Index: package.html
  ===================================================================
  <body>
  Experimatal resources dealing with service publication.
  </body>
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/InvalidPathException.java
  
  Index: InvalidPathException.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  /**
   * Exception to indicate that service URI is invalid.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public final class InvalidPathException
      extends Exception
  {
      private final String m_path;
  
      /**
       * Construct a new <code>InvalidPathException</code> instance.
       *
       * @param path The supplied url path.
       * @param message The detail message for this exception.
       */
      public InvalidPathException( final String path, final String message )
      {
          super( message );
          m_path = path;
      }
  
      /**
       * Return the URL path from which the exception was raised.
       * @return the path URL
       */
      public String getPath()
      {
          return m_path;
      }
  
      /**
       * Return the exception message.
       * @return the message
       */
      public String getMessage()
      {
          return super.getMessage() + " from the url " + getPath();
      }
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/Handler.java
  
  Index: Handler.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.net.URLStreamHandler;
  
  /**
   * <p>Service URL protocol handler. Creation of a new service URL
   * requires that the appropriate handler be supplied to the URL
   * constructor.</p>
   * <p>
   * @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
   */
  public class Handler extends URLStreamHandler
  {
  
      /**
       * The default host
       */
      private String m_host;
  
      /**
       * The resource registry.
       */
      private Registry m_registry;
  
      /**
       * Creation of a new handler.
       * @param host the host domain name
       * @param registry the service resource management context
       */
      public Handler( String host, Registry registry )
      {
          m_host = host;
          m_registry = registry;
      }
  
      /**
       * Opens a connection to the specified URL.
       *
       * @param url A URL to open a connection to.
       * @return The established connection.
       * @throws IOException If a connection failure occurs.
       */
      protected URLConnection openConnection( final URL url )
          throws IOException
      {
          return new ServiceURLConnection( url, m_registry );
      }
  
      /**
       * Parses the string representation of a <code>URL</code> into a
       * <code>URL</code> object.
       * e.g. native:/root/myService
       * <p>
       * If there is any inherited context, then it has already been
       * copied into the <code>URL</code> argument.
       *
       * @param   url     the <code>URL</code> to receive the result of parsing
       *                  the spec.
       * @param   spec    the <code>String</code> representing the URL that
       *                  must be parsed.
       * @param   start   the character index at which to begin parsing. This is
       *                  just past the '<code>:</code>' (if there is one) that
       *                  specifies the determination of the protocol name.
       * @param   limit   the character position to stop parsing at. This is the
       *                  end of the string or the position of the
       *                  "<code>#</code>" character, if present. All information
       *                  after the sharp sign indicates an anchor.
       */
      protected void parseURL( URL url, String spec, int start, int limit )
      {
  
          //
          // get the ref component
          // (from # to the end of the spec)
          //
  
          String ref = url.getRef();
          String remainder = spec.substring( start, limit );
          int refLoc = spec.indexOf( "#", start );
          if( refLoc > -1 )
          {
              ref = spec.substring( refLoc + 1 );
              remainder = spec.substring( start, refLoc );
          }
  
          //
          // get the query component
          // (from ? to the end of the remainder)
          //
  
          String query = url.getQuery();
          int queryLoc = remainder.indexOf( "?" );
          if( queryLoc > -1 )
          {
              query = remainder.substring( queryLoc + 1, remainder.length() );
              remainder = remainder.substring( 0, queryLoc );
          }
  
          //
          // get the path component
          // (from / to the end of the remainder)
          //
  
          String path = url.getPath();
          if( remainder.startsWith( "//" ) )
          {
              remainder = remainder.substring( 2, remainder.length() );
          }
  
          int pathLoc = remainder.indexOf( "/" );
          if( pathLoc > -1 )
          {
              path = remainder.substring( pathLoc, remainder.length() );
              remainder = remainder.substring( 0, pathLoc );
          }
  
          //
          // set the URL parameters
          //
  
          String user = url.getUserInfo();
  
          String host = url.getHost();
          if( host == null ) 
          {
              host = m_host;
          }
  
          int port = url.getPort();
          if( port == -1 ) 
          {
              port = getDefaultPort();
          }
  
          //
          // create authority string dependending of non-default port reference
          //
  
          String authority = null;
          if( port == getDefaultPort() )
          {
              authority = host;
          }
          else
          {
              authority = host + ":" + port;
          }
  
          setURL( url, "native", host, port, authority, user, path, query, ref );
      }
  
      /**
       * Retuns the default port.
       * @return int the default port value of 0
       */
      protected int getDefaultPort()
      {
          return 0;
      }
  
      /**
       * Returns the URL in a string form.
       * @param url to the URL to externalize
       * @return String the external form of the URL
       */
      protected String toExternalForm( URL url )
      {
          StringBuffer result = new StringBuffer( url.getProtocol() );
          result.append( ":" );
          if( url.getUserInfo() != null )
          {
              result.append( "@" );
              result.append( url.getUserInfo() );
          }
          if( url.getFile() != null )
          {
              result.append( url.getFile() );
          }
          if( url.getRef() != null )
          {
              result.append( "#" );
              result.append( url.getRef() );
          }
          return result.toString();
      }
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/service/DefaultRegistry.java
  
  Index: DefaultRegistry.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.service;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  
  /**
   * Default implementation of a service management context.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/12/17 09:58:46 $
   */
  public class DefaultRegistry implements Registry
  {
      //=============================================================
      // state
      //=============================================================
  
      /**
       * The context url.
       */
      private URL m_base;
  
      /**
       * A map of child naming context entries keyed by context name.
       */
      private Map m_table = new Hashtable();
  
      /**
       * The parent naming context.
       */
      private Registry m_parent;
  
      /**
       * A hashtable of appliance instances keyed by service name.
       */
      private Map m_appliances = new Hashtable();
  
  
      //=============================================================
      // constructor
      //=============================================================
  
      /**
       * Creation of a new service management context.  The implementation
       * handles the once only establishment of the service URL protocol
       * handler and registers this instance as the root of the service
       * management naming context hierachy.
       *
       * @param domain the host domain name
       * @exception NullPointerException if the supplied domain name is null
       * @exception MalformedURLException if the supplied domain name is inconsistent
       */
      public DefaultRegistry( final String domain )
          throws NullPointerException, MalformedURLException
      {
          if( domain == null )
          {
              throw new NullPointerException( "domain" );
          }
          try
          {
              URL.setURLStreamHandlerFactory( new ServiceURLFactory( domain, this ) );
          }
          catch( Error e )
          {
              // handler is already registered
          }
  
          m_base = new URL( "native", domain, -1, "/" );
      }
  
      /**
       * Creation of a new service management context.
       *
       * @param parent the parent context
       * @param name the context name
       * @exception NullPointerException if the supplied name or parent is null
       * @exception MalformedURLException if the supplied name is inconsistent
       */
      public DefaultRegistry( final Registry parent, final String name )
          throws NullPointerException, MalformedURLException
      {
          if( name == null )
          {
              throw new NullPointerException( "name" );
          }
          if( parent == null )
          {
              throw new NullPointerException( "parent" );
          }
  
          m_parent = parent;
          URL base = m_parent.getBase();
          String path = base.getPath();
  
          if( name.endsWith( "/" ) )
          {
              m_base = new URL( base, path + name );
          }
          else
          {
              m_base = new URL( base, path + name + "/" );
          }
      }
  
      //=============================================================
      // Registry
      //=============================================================
  
      /**
       * Returns the base context URL.
       *
       * @return the context url
       */
      public URL getBase()
      {
          return m_base;
      }
  
      /**
       * Creation of a subsidiary service context.
       *
       * @param name the relative name
       * @return the service context object
       * @exception NullPointerException if the supplied name is null
       * @exception MalformedURLException if the name is invalid
       * @exception IllegalArgumentException if the name is already in use
       */
      public Registry createChild( String name )
          throws MalformedURLException, IllegalArgumentException
      {
          if( name == null )
          {
              throw new NullPointerException( "name" );
          }
  
          if( m_table.get( name ) != null )
          {
              final String error = "Duplicate name: " + name;
              throw new IllegalArgumentException( error );
          }
  
          Registry context =
              new DefaultRegistry( this, name );
          m_table.put( name, context );
          return context;
      }
  
      /**
       * Bind an appliance to the naming context.
       * @param appliance the appliance to be bound
       * @exception IllegalArgumentException if the supplied appliance
       *  name already exists within the immediate context
       */
      public void bind( Appliance appliance )
      {
          synchronized( m_appliances )
          {
              final String name = appliance.getProfile().getName();
              if( m_appliances.get( name ) != null )
              {
                  final String error = "Duplicate name: " + name;
                  throw new IllegalArgumentException( error );
              }
              m_appliances.put( name, appliance );
          }
      }
  
      /**
       * Unbind an appliance from the naming context.
       *
       * @param appliance the appliance to be unbound
       * @exception IllegalArgumentException if the supplied appliance is
       *   unknown within the immediate scope of the context
       */
      public void unbind( Appliance appliance )
      {
          synchronized( m_appliances )
          {
              String name = appliance.getProfile().getName();
              Iterator iterator = m_appliances.entrySet().iterator();
              while( iterator.hasNext() )
              {
                  Appliance res = (Appliance)iterator.next();
                  if( res.getProfile().getName().equals( name ) )
                  {
                      m_appliances.remove( name );
                      break;
                  }
              }
              final String error = "Unknown appliance: " + name;
              throw new IllegalArgumentException( error );
          }
      }
  
      /**
       * Resolves an object relative to the supplied URL.
       *
       * @param url the URL
       * @return the object corresponding to the supplied url
       * @exception Exception is an error occurs
       */
      public Object resolve( URL url ) throws Exception
      {
          String uri = normalize( url );
          if( uri.equals( "" ) )
          {
              return this;
          }
          if( uri.indexOf( "/" ) > -1 )
          {
              String name = uri.substring( 0, uri.indexOf( "/" ) );
              Registry child = (Registry)m_table.get( name );
              if( child != null )
              {
                  return child.resolve( url );
              }
              else
              {
                  final String error = "Invalid path element: " + name;
                  throw new InvalidPathException( uri, error );
              }
          }
          else
          {
              //
              // its an immediate appliance
              //
  
              Object child = m_table.get( uri );
              if( child != null )
              {
                  return child;
              }
  
              Appliance appliance = (Appliance)m_appliances.get( uri );
              if( appliance != null )
              {
                  return appliance;
              }
          }
          final String error = "Could not locate the requested service.";
          throw new UnknownServiceException( uri, error );
      }
  
      /**
       * Select a set of service based on a supplied filter.  A filter is
       * supplied in the form of a URI String.  Interpritation relative to URI path, query,
       * and fragment are protocol dependent.
       *
       * @param path the service uri
       * @return the appliance corresponding to the supplied URL
       * @exception InvalidPathException if the supplied path is invalid
       * @exception UnknownServiceException if the supplied path does not refer to a service
       */
      public Appliance locate( String path ) throws UnknownServiceException, InvalidPathException
      {
          if( path == null )
          {
              throw new NullPointerException( "path" );
          }
          String uri = normalize( path );
  
          if( uri.indexOf( "/" ) > -1 )
          {
              String name = uri.substring( 0, uri.indexOf( "/" ) );
              Registry child = (Registry)m_table.get( name );
              if( child != null )
              {
                  return child.locate( uri.substring( uri.indexOf( "/" ) + 1, uri.length() ) );
              }
              else
              {
                  final String error = "Invalid path element: " + name;
                  throw new InvalidPathException( uri, error );
              }
          }
          else
          {
              //
              // its an immediate appliance
              //
  
              Object child = m_table.get( uri );
              if( child != null )
              {
                  return ( (Registry)child ).locate( "" );
              }
  
              Appliance appliance = (Appliance)m_appliances.get( uri );
              if( appliance != null )
              {
                  return appliance;
              }
              final String error = "Could not locate the requested service.";
              throw new UnknownServiceException( uri, error );
          }
      }
  
      //=======================================================================
      // implementation
      //=======================================================================
  
      /**
       * Returns a list of published appliance URLs.
       * @return the appliances
       */
      public URL[] list()
      {
          ArrayList list = new ArrayList();
          Registry[] publishers =
              (Registry[])m_table.values().toArray( new Registry[ 0 ] );
          for( int j = 0; j < publishers.length; j++ )
          {
              URL url = publishers[ j ].getBase();
              list.add( url );
          }
  
          Appliance[] appliances = (Appliance[])m_appliances.values().toArray( new Appliance[ 0 ] );
          for( int i = 0; i < appliances.length; i++ )
          {
              list.add( appliances[ i ].getURL() );
          }
          return (URL[])list.toArray( new URL[ 0 ] );
      }
  
      /**
       * Returns a list of published appliances.
       * @return the appliances
       */
      public Appliance[] getAppliances()
      {
          return (Appliance[])m_appliances.values().toArray( new Appliance[ 0 ] );
      }
  
      /**
       * Returns a sub-registry by path.
       * @param path the registry path
       * @return the subsidiary registry
       * @exception InvalidPathException if the supplied path is invalid
       * @exception UnknownServiceException if the supplied path does not refer to a registry
       */
      public ServicePublisher getRegistry( String path )
          throws UnknownServiceException, InvalidPathException
      {
          if( path == null )
          {
              throw new NullPointerException( "path" );
          }
  
          String uri = normalize( path );
          if( uri.equals( "" ) )
          {
              return this;
          }
  
          if( uri.indexOf( "/" ) > -1 )
          {
              String name = uri.substring( 0, uri.indexOf( "/" ) );
              Registry child = (Registry)m_table.get( name );
              if( child != null )
              {
                  return child.getRegistry( uri.substring( uri.indexOf( "/" ) + 1, uri.length() ) );
              }
              else
              {
                  final String error = "Invalid path element: " + name;
                  throw new InvalidPathException( uri, error );
              }
          }
          else
          {
              //
              // its an immediate registry
              //
  
              ServicePublisher child = (ServicePublisher)m_table.get( uri );
              if( child != null )
              {
                  return child;
              }
              final String error = "Could not locate the requested registry.";
              throw new UnknownServiceException( uri, error );
          }
      }
  
      /**
       * Returns a list of sub-registries.
       * @return the subsidiary registries
       */
      public ServicePublisher[] getRegistries()
      {
          return (ServicePublisher[])m_table.values().toArray( new ServicePublisher[ 0 ] );
      }
  
      /**
       * Normalize a supplied path with the base URL of this registry.
       * @param path the uri path to normalize
       * @return the normalized path relative to this registry
       */
      public String normalize( String path )
      {
          try
          {
              return normalize( new URL( getBase(), path ) );
          }
          catch( Throwable e )
          {
              throw new RuntimeException( path + ", cause: " + e.toString() );
          }
      }
  
      /**
       * Normalize a supplied path with the base URL of this registry.
       * @param url the uri path to normalize
       * @return the normalized path relative to this registry
       */
      public String normalize( URL url )
      {
          String p = url.getPath();
          String root = getBase().getPath();
          if( p.startsWith( root ) )
          {
              String result = p.substring( root.length() );
              if( url.getQuery() != null )
              {
                  result = result + "?" + url.getQuery();
              }
              if( url.getRef() != null )
              {
                  result = result + "#" + url.getRef();
              }
              return result;
          }
          return p;
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message