1 19 20 package org.apache.excalibur.instrument.manager.http; 21 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import java.util.Map ; 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 37 public class XMLSampleLeaseHandler 38 extends AbstractXMLHandler 39 { 40 43 49 public XMLSampleLeaseHandler( DefaultInstrumentManager manager, 50 InstrumentManagerHTTPConnector connector ) 51 { 52 super( "/sample-lease.xml", manager, connector ); 53 } 54 55 58 65 public void doGet( String path, Map parameters, PrintWriter out ) 66 throws IOException 67 { 68 String name = getParameter( parameters, "name" ); 69 long lease = getLongParameter( parameters, "lease" ); 70 boolean packed = getBooleanParameter( parameters, "packed", false ); 71 72 InstrumentSampleDescriptor desc; 73 try 74 { 75 desc = getInstrumentManager().locateInstrumentSampleDescriptor( name ); 76 } 77 catch ( NoSuchInstrumentSampleException e ) 78 { 79 throw new FileNotFoundException ( 80 "The specified instrument does not exist: " + name ); 81 } 82 83 lease = Math.max( 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) ); 87 88 if ( getInstrumentManager().getLeaseSampleCount() >= getConnector().getMaxLeasedSamples() ) 89 { 90 lease = 1; 91 } 92 93 desc.extendLease( lease ); 95 96 out.println( InstrumentManagerHTTPConnector.XML_BANNER ); 97 outputSample( out, desc, "", packed ); 98 } 99 100 103 } 104 105 | Popular Tags |