avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util OverridableServiceManager.java
Date Sun, 10 Nov 2002 09:29:57 GMT
donaldp     2002/11/10 01:29:57

  Added:       fortress/src/java/org/apache/excalibur/fortress/util
                        OverridableServiceManager.java
  Log:
  Add an OveridableServiceManager compliment to OveridableContext
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/OverridableServiceManager.java
  
  Index: OverridableServiceManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.fortress.util;
  
  import org.apache.avalon.framework.service.DefaultServiceManager;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  
  /**
   * The OverridableServiceManager allows you to "null" out entries, even if they are
   * in a parent {@link org.apache.avalon.framework.service.ServiceManager}.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/10 09:29:57 $
   */
  public class OverridableServiceManager
      extends DefaultServiceManager
  {
      /**
       * Marker object that indicates something has bene deliberately nulled out.
       */
      private static final Object MARKER = new Object();
  
      /**
       * Create a OverridableServiceManager with specified parent.
       *
       * @param parent the parent ServiceManager
       */
      public OverridableServiceManager( final ServiceManager parent )
      {
          super( parent );
      }
  
      /**
       * Lookup service and if the marker is found then
       * assume that null has been added and thus throw a ServiceException.
       *
       * @param key the key to lookup
       * @return the service instance
       * @throws ServiceException
       */
      public Object lookup( final String key )
          throws ServiceException
      {
          final Object object = super.lookup( key );
          if( MARKER == object )
          {
              throw new ServiceException( key, "Unable to locate service" );
          }
          return object;
      }
  
      /**
       * Put a service into ServiceManager. If null service is added
       * then a marker is instead placed into map (thus hiding potential
       * service in parent serviceManager).
       *
       * @param key the key
       * @param object the service
       */
      public void put( final String key, final Object object )
      {
          if( null == object )
          {
              super.put( key, MARKER );
          }
          else
          {
              super.put( key, object );
          }
      }
  }
  
  
  

--
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