1 50 package org.apache.excalibur.instrument; 51 52 import java.util.ArrayList ; 53 54 64 public abstract class AbstractInstrumentable 65 implements Instrumentable 66 { 67 68 private String m_instrumentableName; 69 70 71 private ArrayList m_instrumentList; 72 73 74 private ArrayList m_childList; 75 76 77 private boolean m_registered; 78 79 82 85 protected AbstractInstrumentable() 86 { 87 m_registered = false; 88 m_instrumentList = new ArrayList (); 89 m_childList = new ArrayList (); 90 } 91 92 95 102 protected void addInstrument( Instrument instrument ) 103 { 104 if( m_registered ) 105 { 106 throw new IllegalStateException ( "Instruments can not be added after the " 107 + "Instrumentable is registered with the InstrumentManager." ); 108 } 109 m_instrumentList.add( instrument ); 110 } 111 112 122 protected void addChildInstrumentable( Instrumentable child ) 123 { 124 if( m_registered ) 125 { 126 throw new IllegalStateException ( "Child Instrumentables can not be added after the " 127 + "Instrumentable is registered with the InstrumentManager." ); 128 } 129 m_childList.add( child ); 130 } 131 132 135 140 public final String getInstrumentableName() 141 { 142 return m_instrumentableName; 143 } 144 145 158 public final void setInstrumentableName( String name ) 159 { 160 m_instrumentableName = name; 161 } 162 163 172 public final Instrumentable[] getChildInstrumentables() 173 { 174 m_registered = true; 175 if( m_childList.size() == 0 ) 176 { 177 return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY; 178 } 179 else 180 { 181 Instrumentable[] children = new Instrumentable[ m_childList.size() ]; 182 m_childList.toArray( children ); 183 return children; 184 } 185 } 186 187 198 public final Instrument[] getInstruments() 199 { 200 m_registered = true; 201 if( m_instrumentList.size() == 0 ) 202 { 203 return Instrumentable.EMPTY_INSTRUMENT_ARRAY; 204 } 205 else 206 { 207 Instrument[] instruments = new Instrument[ m_instrumentList.size() ]; 208 m_instrumentList.toArray( instruments ); 209 return instruments; 210 } 211 } 212 } 213 | Popular Tags |