KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > http > HTMLInstrumentableHandler


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.http;
21
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
27 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
28 import org.apache.excalibur.instrument.manager.InstrumentableDescriptor;
29 import org.apache.excalibur.instrument.manager.InstrumentDescriptor;
30 import org.apache.excalibur.instrument.manager.NoSuchInstrumentableException;
31
32 /**
33  *
34  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
35  * @version CVS $Revision: 1.6 $ $Date: 2004/03/06 14:01:28 $
36  * @since 4.1
37  */

38 public class HTMLInstrumentableHandler
39     extends AbstractHTMLHandler
40 {
41     /*---------------------------------------------------------------
42      * Constructors
43      *-------------------------------------------------------------*/

44     /**
45      * Creates a new HTMLInstrumentableHandler.
46      *
47      * @param manager Reference to the DefaultInstrumentManager.
48      * @param connector The InstrumentManagerHTTPConnector.
49      */

50     public HTMLInstrumentableHandler( DefaultInstrumentManager manager,
51                                       InstrumentManagerHTTPConnector connector )
52     {
53         super( "/instrumentable.html", manager, connector );
54     }
55     
56     /*---------------------------------------------------------------
57      * AbstractHTTPURLHandler Methods
58      *-------------------------------------------------------------*/

59     /**
60      * Handles the specified request.
61      *
62      * @param The full path being handled.
63      * @param parameters A Map of the parameters in the request.
64      * @param os The PrintWriter to write the result to.
65      */

66     public void doGet( String JavaDoc path, Map JavaDoc parameters, PrintWriter JavaDoc out )
67         throws IOException JavaDoc
68     {
69         String JavaDoc name = getParameter( parameters, "name" );
70         InstrumentableDescriptor desc;
71         try
72         {
73             desc = getInstrumentManager().locateInstrumentableDescriptor( name );
74         }
75         catch ( NoSuchInstrumentableException e )
76         {
77             // Sample no longer exists, go back to the parent instrument.
78
int pos = name.lastIndexOf( '.' );
79             if ( pos >= 0 )
80             {
81                 throw new HTTPRedirect(
82                     "instrumentable.html?name=" + urlEncode( name.substring( 0, pos ) ) );
83             }
84             else
85             {
86                 throw new HTTPRedirect( "instrument-manager.html" );
87             }
88         }
89         
90         out.println( "<html>" );
91         out.println( "<head><title>" + desc.getDescription() + "</title></head>" );
92         out.println( "<body>" );
93         
94         breadCrumbs( out, desc, false );
95         
96         out.println( "<h2>Instrumentable</h2>" );
97         startTable( out );
98         tableRow( out, 0, "Name", desc.getName() );
99         tableRow( out, 0, "Description", desc.getDescription() );
100         endTable( out );
101         
102         InstrumentableDescriptor[] instrumentables = desc.getChildInstrumentableDescriptors();
103         if ( instrumentables.length > 0 )
104         {
105             out.println( "<h2>Instrumentables</h2>" );
106             outputInstrumentables( out, instrumentables );
107         }
108         
109         InstrumentDescriptor[] instruments = desc.getInstrumentDescriptors();
110         if ( instruments.length > 0 )
111         {
112             out.println( "<h2>Instruments</h2>" );
113             outputInstruments( out, instruments );
114         }
115         
116         footer( out );
117         
118         out.println( "</body>" );
119         out.println( "</html>" );
120     }
121             
122     /*---------------------------------------------------------------
123      * Methods
124      *-------------------------------------------------------------*/

125 }
126
127
Popular Tags