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 36 public class XMLSampleLeasesHandler 37 extends AbstractXMLHandler 38 { 39 42 48 public XMLSampleLeasesHandler( DefaultInstrumentManager manager, 49 InstrumentManagerHTTPConnector connector ) 50 { 51 super( "/sample-leases.xml", manager, connector ); 52 } 53 54 57 64 public void doGet( String path, Map parameters, PrintWriter out ) 65 throws IOException 66 { 67 String [] names = getParameters( parameters, "name" ); 68 long[] leases = getLongParameters( parameters, "lease", 0 ); 69 boolean packed = getBooleanParameter( parameters, "packed", false ); 70 71 if ( names.length != leases.length ) 72 { 73 throw new FileNotFoundException ( 74 "The number of leases values not equal to the number of names." ); 75 } 76 77 out.println( InstrumentManagerHTTPConnector.XML_BANNER ); 78 if ( names.length > 0 ) 79 { 80 outputLine( out, "", packed, "<samples>" ); 81 82 for ( int i = 0; i < names.length; i++ ) 83 { 84 String name = names[i]; 85 long lease = leases[i]; 86 87 InstrumentSampleDescriptor desc; 88 try 89 { 90 desc = getInstrumentManager().locateInstrumentSampleDescriptor( name ); 91 } 92 catch ( NoSuchInstrumentSampleException e ) 93 { 94 desc = null; 96 } 97 98 if ( desc != null ) 99 { 100 lease = Math.max( 104 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) ); 105 106 if ( getInstrumentManager().getLeaseSampleCount() >= 107 getConnector().getMaxLeasedSamples() ) 108 { 109 lease = 1; 110 } 111 112 desc.extendLease( lease ); 114 115 outputSample( out, desc, " ", packed ); 116 } 117 } 118 119 outputLine( out, "", packed, "</samples>" ); 120 } 121 else 122 { 123 outputLine( out, "", packed, "<samples/>" ); 124 } 125 } 126 127 130 } 131 132 | Popular Tags |