KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > impl > extensions > InstrumentableCreator


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.fortress.impl.extensions;
19
20 import org.apache.avalon.framework.context.Context;
21 import org.apache.avalon.lifecycle.AbstractCreator;
22 import org.apache.excalibur.instrument.InstrumentManageable;
23 import org.apache.excalibur.instrument.InstrumentManager;
24 import org.apache.excalibur.instrument.Instrumentable;
25
26 /**
27  * The InstrumentableCreator is used as a standard lifecycle
28  * extension for containers that support it.
29  */

30 public final class InstrumentableCreator extends AbstractCreator
31 {
32     private final InstrumentManager m_instrumentManager;
33     private final boolean m_instrumentEnabled;
34
35     public InstrumentableCreator( final InstrumentManager instrumentManager )
36     {
37         m_instrumentManager = instrumentManager;
38         m_instrumentEnabled = instrumentManager != null;
39     }
40
41     /**
42      * Assign the instrumentables and InstrumentManageables
43      */

44     public void create( final Object JavaDoc object, final Context context ) throws Exception JavaDoc
45     {
46         if ( m_instrumentEnabled && object instanceof Instrumentable )
47         {
48             final String JavaDoc instrumentableName = (String JavaDoc) context.get( "component.name" );
49             final Instrumentable instrumentable = (Instrumentable) object;
50             instrumentable.setInstrumentableName( instrumentableName );
51
52             // Get the name from the instrumentable in case it was changed since being set above.
53
m_instrumentManager.registerInstrumentable(
54                 instrumentable, instrumentable.getInstrumentableName() );
55
56         }
57
58         if ( m_instrumentEnabled && object instanceof InstrumentManageable )
59         {
60             ( (InstrumentManageable) object ).setInstrumentManager( m_instrumentManager );
61         }
62
63     }
64 }
65
Popular Tags