avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Sutic" <leo.su...@inspireinfrastructure.com>
Subject RE: Son of ComponentManager
Date Sat, 16 Feb 2002 14:38:20 GMT


> From: Leo Sutic [mailto:leo.sutic@inspireinfrastructure.com]
> 
> package packagename;
> 
> import org.apache.avalon.framework.component.Component;
> import org.apache.avalon.framework.component.ComponentException;
> 
> public interface ObjectManager implements Component {
>   public static void ROLE = "packagename.ObjectManager";
>   public Object lookup (String role) throws ComponentException;
> }
> 
> ----------------------------
> 
> public class DefaultObjectManager implements ObjectManager, Composable,
> ThreadSafe {
> 
>   private ComponentManager manager = null;
> 
>   public void compose (ComponentManager manager) {
>     this.manager = manager;
>   }
> 
>   public Object lookup (String role) throws ComponentException {
>     Component maybeWrapper = manager.lookup (role);
>     if (maybeWrapper instanceof ComponentWrapper) {
>       return ((ComponentWrapper) maybeWrapper).getObject ();
>     } else {
>       return maybeWrapper;
>     }
>   }
> }
> 

Oops - for Avalon4 compatibility, must not forget:

public interface ObjectManager implements Component {
  public static void ROLE = "packagename.ObjectManager";
  public Object lookup (String role) throws ComponentException;
  public void release (Object obj);
}

public class DefaultObjectManager implements ObjectManager, Composable,
ThreadSafe {

  private ComponentManager manager = null;

  public void compose (ComponentManager manager) {
    this.manager = manager;
  }
 
  public Object lookup (String role) throws ComponentException {
    Component maybeWrapper = manager.lookup (role);
    if (maybeWrapper instanceof ComponentWrapper) {
      return ((ComponentWrapper) maybeWrapper).getObject ();
    } else {
      return maybeWrapper;
    }
  }

  public void release (Object object) {
    if (object instanceof Component) {
      manager.release ((Component) object);
    }
  }
}



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


Mime
View raw message