KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > impl > InstrumentableDescriptorImpl


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

19
20 package org.apache.excalibur.instrument.manager.impl;
21
22 import org.apache.excalibur.instrument.manager.InstrumentDescriptor;
23 import org.apache.excalibur.instrument.manager.InstrumentableDescriptor;
24 import org.apache.excalibur.instrument.manager.NoSuchInstrumentException;
25 import org.apache.excalibur.instrument.manager.NoSuchInstrumentableException;
26
27 /**
28  * Describes a Instrumentable and acts as a Proxy to protect the original
29  * Instrumentable.
30  *
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:25 $
33  * @since 4.1
34  */

35 public class InstrumentableDescriptorImpl
36     implements InstrumentableDescriptor
37 {
38     /** InstrumentableProxy being described. */
39     private InstrumentableProxy m_instrumentableProxy;
40
41     /*---------------------------------------------------------------
42      * Constructors
43      *-------------------------------------------------------------*/

44     /**
45      * Creates a new InstrumentableDescriptorImpl.
46      *
47      * @param instrumentableProxy InstrumentableProxy being described.
48      */

49     InstrumentableDescriptorImpl( InstrumentableProxy instrumentableProxy )
50     {
51         m_instrumentableProxy = instrumentableProxy;
52     }
53
54     /*---------------------------------------------------------------
55      * InstrumentableDescriptor Methods
56      *-------------------------------------------------------------*/

57     /**
58      * Returns true if the Instrumentable was configured in the instrumentables
59      * section of the configuration.
60      *
61      * @return True if configured.
62      */

63     public boolean isConfigured()
64     {
65         return m_instrumentableProxy.isConfigured();
66     }
67
68     /**
69      * Returns true if the Instrumentable was registered with the Instrument
70      * Manager.
71      *
72      * @return True if registered.
73      */

74     public boolean isRegistered()
75     {
76         return m_instrumentableProxy.isRegistered();
77     }
78     
79     /**
80      * Gets the name for the Instrumentable. The Instrumentable Name is used
81      * to uniquely identify the Instrumentable during its configuration and to
82      * gain access to a InstrumentableDescriptor through a
83      * DefaultInstrumentManager.
84      *
85      * @return The name used to identify a Instrumentable.
86      */

87     public String JavaDoc getName()
88     {
89         return m_instrumentableProxy.getName();
90     }
91
92     /**
93      * Gets the description of the Instrumentable.
94      *
95      * @return The description of the Instrumentable.
96      */

97     public String JavaDoc getDescription()
98     {
99         return m_instrumentableProxy.getDescription();
100     }
101     
102     /**
103      * Returns the parent InstrumentableDescriptor or null if this is a top
104      * level instrumentable.
105      *
106      * @return The parent InstrumentableDescriptor or null.
107      */

108     public InstrumentableDescriptor getParentInstrumentableDescriptor()
109     {
110         InstrumentableProxy parent = m_instrumentableProxy.getParentInstrumentableProxy();
111         if ( parent == null )
112         {
113             return null;
114         }
115         else
116         {
117             return parent.getDescriptor();
118         }
119     }
120
121     /**
122      * Returns a child InstrumentableDescriptor based on its name or the name
123      * of any of its children.
124      *
125      * @param childInstrumentableName Name of the child Instrumentable being
126      * requested.
127      *
128      * @return A descriptor of the requested child Instrumentable.
129      *
130      * @throws NoSuchInstrumentableException If the specified Instrumentable
131      * does not exist.
132      */

133     public InstrumentableDescriptor getChildInstrumentableDescriptor(
134                                                            String JavaDoc childInstrumentableName )
135         throws NoSuchInstrumentableException
136     {
137         InstrumentableProxy instrumentableProxy =
138             m_instrumentableProxy.getChildInstrumentableProxy( childInstrumentableName );
139         if( instrumentableProxy == null )
140         {
141             throw new NoSuchInstrumentableException(
142                 "No child instrumentable can be found using name: " + childInstrumentableName );
143         }
144
145         return instrumentableProxy.getDescriptor();
146     }
147
148     /**
149      * Returns an array of Descriptors for the child Instrumentables registered
150      * by this Instrumentable.
151      *
152      * @return An array of Descriptors for the child Instrumentables registered
153      * by this Instrumentable.
154      */

155     public InstrumentableDescriptor[] getChildInstrumentableDescriptors()
156     {
157         return m_instrumentableProxy.getChildInstrumentableDescriptors();
158     }
159         
160     /**
161      * Returns a InstrumentDescriptor based on its name.
162      *
163      * @param instrumentName Name of the Instrument being requested.
164      *
165      * @return A Descriptor of the requested Instrument.
166      *
167      * @throws NoSuchInstrumentException If the specified Instrument does
168      * not exist.
169      */

170     public InstrumentDescriptor getInstrumentDescriptor( String JavaDoc instrumentName )
171         throws NoSuchInstrumentException
172     {
173         InstrumentProxy instrumentProxy =
174             m_instrumentableProxy.getInstrumentProxy( instrumentName );
175         if( instrumentProxy == null )
176         {
177             throw new NoSuchInstrumentException(
178                 "No instrument can be found using name: " + instrumentName );
179         }
180
181         return instrumentProxy.getDescriptor();
182     }
183
184     /**
185      * Returns an array of Descriptors for the Instruments registered by this
186      * Instrumentable.
187      *
188      * @return An array of Descriptors for the Instruments registered by this
189      * Instrumentable.
190      */

191     public InstrumentDescriptor[] getInstrumentDescriptors()
192     {
193         return m_instrumentableProxy.getInstrumentDescriptors();
194     }
195     
196     /**
197      * Returns the stateVersion of the instrumentable. The state version
198      * will be incremented each time any of the configuration of the
199      * instrumentable or any of its children is modified.
200      * Clients can use this value to tell whether or not anything has
201      * changed without having to do an exhaustive comparison.
202      *
203      * @return The state version of the instrumentable.
204      */

205     public int getStateVersion()
206     {
207         return m_instrumentableProxy.getStateVersion();
208     }
209 }
210
Popular Tags