1 50 package org.apache.excalibur.instrument; 51 52 import java.util.ArrayList ; 53 54 import org.apache.avalon.framework.logger.AbstractLogEnabled; 55 56 67 public abstract class AbstractLogEnabledInstrumentable 68 extends AbstractLogEnabled 69 implements Instrumentable 70 { 71 72 private String m_instrumentableName; 73 74 75 private ArrayList m_instrumentList; 76 77 78 private ArrayList m_childList; 79 80 81 private boolean m_registered; 82 83 86 89 protected AbstractLogEnabledInstrumentable() 90 { 91 m_registered = false; 92 m_instrumentList = new ArrayList (); 93 m_childList = new ArrayList (); 94 } 95 96 99 106 protected void addInstrument( Instrument instrument ) 107 { 108 if( m_registered ) 109 { 110 throw new IllegalStateException ( "Instruments can not be added after the " 111 + "Instrumentable is registered with the InstrumentManager." ); 112 } 113 m_instrumentList.add( instrument ); 114 } 115 116 126 protected void addChildInstrumentable( Instrumentable child ) 127 { 128 if( m_registered ) 129 { 130 throw new IllegalStateException ( "Child Instrumentables can not be added after the " 131 + "Instrumentable is registered with the InstrumentManager." ); 132 } 133 m_childList.add( child ); 134 } 135 136 139 144 public final String getInstrumentableName() 145 { 146 return m_instrumentableName; 147 } 148 149 162 public final void setInstrumentableName( String name ) 163 { 164 m_instrumentableName = name; 165 } 166 167 176 public final Instrumentable[] getChildInstrumentables() 177 { 178 m_registered = true; 179 if( m_childList.size() == 0 ) 180 { 181 return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY; 182 } 183 else 184 { 185 Instrumentable[] children = new Instrumentable[ m_childList.size() ]; 186 m_childList.toArray( children ); 187 return children; 188 } 189 } 190 191 202 public final Instrument[] getInstruments() 203 { 204 m_registered = true; 205 if( m_instrumentList.size() == 0 ) 206 { 207 return Instrumentable.EMPTY_INSTRUMENT_ARRAY; 208 } 209 else 210 { 211 Instrument[] instruments = new Instrument[ m_instrumentList.size() ]; 212 m_instrumentList.toArray( instruments ); 213 return instruments; 214 } 215 } 216 } 217 | Popular Tags |