1 19 package org.apache.avalon.excalibur.logger.util; 20 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.avalon.framework.logger.LogEnabled; 23 import org.apache.avalon.framework.context.Context; 24 import org.apache.avalon.framework.context.Contextualizable; 25 import org.apache.avalon.framework.context.ContextException; 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.apache.avalon.framework.configuration.Configurable; 28 import org.apache.avalon.framework.configuration.ConfigurationException; 29 import org.apache.avalon.framework.activity.Startable; 30 import org.apache.avalon.framework.activity.Disposable; 31 import org.apache.avalon.framework.container.ContainerUtil; 32 import java.util.ArrayList ; 33 34 47 48 public class AvalonTee implements 49 LogEnabled, 50 Contextualizable, 51 Configurable, 52 Startable, 53 Disposable 54 { 55 56 private ArrayList m_listeners = new ArrayList ( 10 ); 57 62 private int m_len = 0; 63 64 65 private boolean m_readOnly = false; 66 67 70 public void makeReadOnly() 71 { 72 m_readOnly = true; 73 } 74 75 79 public void addTee( final Object obj ) 80 { 81 if ( m_readOnly ) 82 { 83 throw new IllegalStateException ( "makeReadOnly() already invoked" ); 84 } 85 86 if ( obj == null ) throw new NullPointerException ( "obj" ); 87 if ( m_listeners.contains( obj ) ) 88 { 89 } 91 else 92 { 93 m_listeners.add( obj ); 95 m_len = m_listeners.size(); 96 } 97 } 98 99 public void enableLogging( final Logger logger ) 100 { 101 for( int i = 0; i < m_len; ++i ) 102 { 103 ContainerUtil.enableLogging( m_listeners.get( i ), logger ); 104 } 105 } 106 107 public void contextualize( final Context context ) throws ContextException 108 { 109 for( int i = 0; i < m_len; ++i ) 110 { 111 ContainerUtil.contextualize( m_listeners.get( i ), context ); 112 } 113 } 114 115 public void configure( final Configuration config ) throws ConfigurationException 116 { 117 for( int i = 0; i < m_len; ++i ) 118 { 119 ContainerUtil.configure( m_listeners.get( i ), config ); 120 } 121 } 122 123 public void start() throws Exception 124 { 125 for( int i = 0; i < m_len; ++i ) 126 { 127 ContainerUtil.start( m_listeners.get( i ) ); 128 } 129 } 130 131 public void stop() throws Exception 132 { 133 for( int i = 0; i < m_len; ++i ) 134 { 135 ContainerUtil.stop( m_listeners.get( i ) ); 136 } 137 } 138 139 public void dispose() 140 { 141 for( int i = 0; i < m_len; ++i ) 142 { 143 ContainerUtil.dispose( m_listeners.get( i ) ); 144 } 145 } 146 } 147 | Popular Tags |