001 /***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 *****************************************************************************/ 008 package org.picocontainer.lifecycle; 009 010 import org.picocontainer.ComponentAdapter; 011 import org.picocontainer.LifecycleStrategy; 012 013 /** 014 * Allow for use of alternate LifecycleStrategy strategies to be used 015 * at the same time. A component can be started/stopped/disposed according 016 * to *any* of the supplied LifecycleStrategy instances. 017 * 018 * @author Paul Hammant 019 */ 020 public class CompositeLifecycleStrategy implements LifecycleStrategy { 021 022 private final StartableLifecycleStrategy[] alternateStrategies; 023 024 public CompositeLifecycleStrategy(StartableLifecycleStrategy... alternateStrategies) { 025 this.alternateStrategies = alternateStrategies; 026 } 027 028 public void start(Object component) { 029 for (StartableLifecycleStrategy lifecycleStrategy : alternateStrategies) { 030 lifecycleStrategy.start(component); 031 } 032 } 033 034 public void stop(Object component) { 035 for (StartableLifecycleStrategy lifecycleStrategy : alternateStrategies) { 036 lifecycleStrategy.stop(component); 037 } 038 } 039 040 public void dispose(Object component) { 041 for (StartableLifecycleStrategy lifecycleStrategy : alternateStrategies) { 042 lifecycleStrategy.dispose(component); 043 } 044 } 045 046 public boolean hasLifecycle(Class<?> type) { 047 for (StartableLifecycleStrategy lifecycleStrategy : alternateStrategies) { 048 if (lifecycleStrategy.hasLifecycle(type)) { 049 return true; 050 } 051 } 052 return false; 053 } 054 055 public boolean isLazy(ComponentAdapter<?> adapter) { 056 for (StartableLifecycleStrategy lifecycleStrategy : alternateStrategies) { 057 if (lifecycleStrategy.isLazy(adapter)) { 058 return true; 059 } 060 } 061 return false; 062 } 063 }