KickJava   Java API By Example, From Geeks To Geeks.

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


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

37 public class XMLSnapshotsHandler
38     extends AbstractXMLHandler
39 {
40     /*---------------------------------------------------------------
41      * Constructors
42      *-------------------------------------------------------------*/

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

49     public XMLSnapshotsHandler( DefaultInstrumentManager manager,
50                                 InstrumentManagerHTTPConnector connector )
51     {
52         super( "/snapshots.xml", manager, connector );
53     }
54     
55     /*---------------------------------------------------------------
56      * AbstractHTTPURLHandler Methods
57      *-------------------------------------------------------------*/

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

65     public void doGet( String JavaDoc path, Map JavaDoc parameters, PrintWriter JavaDoc out )
66         throws IOException JavaDoc
67     {
68         String JavaDoc[] names = getParameters( parameters, "name" );
69         long[] baseTimes = getLongParameters( parameters, "base-time", 0 );
70         boolean packed = getBooleanParameter( parameters, "packed", false );
71         boolean compact = getBooleanParameter( parameters, "compact", false );
72         
73         if ( ( baseTimes.length == 0 ) && ( names.length > 0 ) )
74         {
75             baseTimes = new long[names.length];
76         }
77         else if ( names.length != baseTimes.length )
78         {
79             throw new FileNotFoundException JavaDoc(
80                 "The number of base-time values not equal to the number of names." );
81         }
82         
83         out.println( InstrumentManagerHTTPConnector.XML_BANNER );
84         if ( names.length > 0 )
85         {
86             outputLine( out, "", packed, "<samples>" );
87             
88             for ( int i = 0; i < names.length; i++ )
89             {
90                 InstrumentSampleDescriptor desc;
91                 try
92                 {
93                     desc =
94                         getInstrumentManager().locateInstrumentSampleDescriptor( names[i] );
95                     
96                     outputSampleHistory( out, desc, "", baseTimes[i], packed, compact );
97                 }
98                 catch ( NoSuchInstrumentSampleException e )
99                 {
100                     outputLine( out, " ", packed,
101                         "<sample name=\"" + names[i] + "\" expired=\"true\"/>" );
102                 }
103             }
104             
105             outputLine( out, "", packed, "</samples>" );
106         }
107         else
108         {
109             outputLine( out, "", packed, "<samples/>" );
110         }
111     }
112     
113     /*---------------------------------------------------------------
114      * Methods
115      *-------------------------------------------------------------*/

116 }
117
118
Popular Tags