1 17 package org.apache.avalon.excalibur.component; 18 19 import java.util.ArrayList ; 20 21 import org.apache.excalibur.instrument.Instrument; 22 import org.apache.excalibur.instrument.Instrumentable; 23 24 36 public abstract class AbstractDualLogEnabledInstrumentable 37 extends AbstractDualLogEnabled 38 implements Instrumentable 39 { 40 41 private String m_instrumentableName; 42 43 44 private ArrayList m_instrumentList; 45 46 47 private ArrayList m_childList; 48 49 50 private boolean m_registered; 51 52 55 58 protected AbstractDualLogEnabledInstrumentable() 59 { 60 m_registered = false; 61 m_instrumentList = new ArrayList (); 62 m_childList = new ArrayList (); 63 } 64 65 68 75 protected void addInstrument( Instrument instrument ) 76 { 77 if( m_registered ) 78 { 79 throw new IllegalStateException ( "Instruments can not be added after the " 80 + "Instrumentable is registered with the InstrumentManager." ); 81 } 82 m_instrumentList.add( instrument ); 83 } 84 85 95 protected void addChildInstrumentable( Instrumentable child ) 96 { 97 if( m_registered ) 98 { 99 throw new IllegalStateException ( "Child Instrumentables can not be added after the " 100 + "Instrumentable is registered with the InstrumentManager." ); 101 } 102 m_childList.add( child ); 103 } 104 105 108 113 public final String getInstrumentableName() 114 { 115 return m_instrumentableName; 116 } 117 118 131 public final void setInstrumentableName( String name ) 132 { 133 m_instrumentableName = name; 134 } 135 136 145 public final Instrumentable[] getChildInstrumentables() 146 { 147 m_registered = true; 148 if( m_childList.size() == 0 ) 149 { 150 return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY; 151 } 152 else 153 { 154 Instrumentable[] children = new Instrumentable[ m_childList.size() ]; 155 m_childList.toArray( children ); 156 return children; 157 } 158 } 159 160 171 public final Instrument[] getInstruments() 172 { 173 m_registered = true; 174 if( m_instrumentList.size() == 0 ) 175 { 176 return Instrumentable.EMPTY_INSTRUMENT_ARRAY; 177 } 178 else 179 { 180 Instrument[] instruments = new Instrument[ m_instrumentList.size() ]; 181 m_instrumentList.toArray( instruments ); 182 return instruments; 183 } 184 } 185 } 186 | Popular Tags |