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.http.server.HTTPRedirect; 28 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager; 29 import org.apache.excalibur.instrument.manager.InstrumentDescriptor; 30 import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor; 31 import org.apache.excalibur.instrument.manager.NoSuchInstrumentException; 32 33 39 public class XMLCreateSampleHandler 40 extends AbstractXMLHandler 41 { 42 45 51 public XMLCreateSampleHandler( DefaultInstrumentManager manager, 52 InstrumentManagerHTTPConnector connector ) 53 { 54 super( "/create-sample.xml", manager, connector ); 55 } 56 57 60 67 public void doGet( String path, Map parameters, PrintWriter out ) 68 throws IOException 69 { 70 String name = getParameter( parameters, "name" ); 71 String description = getParameter( parameters, "description" ); 72 long interval = getLongParameter( parameters, "interval" ); 73 int size = getIntegerParameter( parameters, "size" ); 74 long lease = getLongParameter( parameters, "lease" ); 75 int type = getIntegerParameter( parameters, "type" ); 76 boolean packed = getBooleanParameter( parameters, "packed", false ); 77 78 InstrumentDescriptor desc; 79 try 80 { 81 desc = getInstrumentManager().locateInstrumentDescriptor( name ); 82 } 83 catch ( NoSuchInstrumentException e ) 84 { 85 throw new FileNotFoundException ( 86 "The specified instrument does not exist: " + name ); 87 } 88 89 size = Math.max( 1, Math.min( size, getConnector().getMaxLeasedSampleSize() ) ); 93 lease = Math.max( 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) ); 94 95 if ( getInstrumentManager().getLeaseSampleCount() >= getConnector().getMaxLeasedSamples() ) 96 { 97 lease = 1; 98 } 99 100 InstrumentSampleDescriptor sample; 102 try 103 { 104 sample = desc.createInstrumentSample( description, interval, size, lease, type ); 105 } 106 catch ( IllegalArgumentException e ) 107 { 108 throw new FileNotFoundException ( e.getMessage() ); 110 } 111 catch ( IllegalStateException e ) 112 { 113 throw new FileNotFoundException ( e.getMessage() ); 115 } 116 117 out.println( InstrumentManagerHTTPConnector.XML_BANNER ); 118 outputSample( out, sample, "", packed ); 119 } 120 121 124 } 125 126 | Popular Tags |