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 HTMLCreateSampleHandler 40 extends AbstractHTMLHandler 41 { 42 45 51 public HTMLCreateSampleHandler( DefaultInstrumentManager manager, 52 InstrumentManagerHTTPConnector connector ) 53 { 54 super( "/create-sample.html", 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 77 InstrumentDescriptor desc; 78 try 79 { 80 desc = getInstrumentManager().locateInstrumentDescriptor( name ); 81 } 82 catch ( NoSuchInstrumentException e ) 83 { 84 int pos = name.lastIndexOf( '.' ); 86 if ( pos >= 0 ) 87 { 88 throw new HTTPRedirect( 89 "instrumentable.html?name=" + urlEncode( name.substring( 0, pos ) ) ); 90 } 91 else 92 { 93 throw new HTTPRedirect( "instrument-manager.html" ); 94 } 95 } 96 97 size = Math.max( 1, Math.min( size, getConnector().getMaxLeasedSampleSize() ) ); 101 lease = Math.max( 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) ); 102 103 if ( getInstrumentManager().getLeaseSampleCount() >= getConnector().getMaxLeasedSamples() ) 104 { 105 lease = 1; 106 } 107 108 InstrumentSampleDescriptor sample; 110 try 111 { 112 sample = desc.createInstrumentSample( description, interval, size, lease, type ); 113 } 114 catch ( IllegalArgumentException e ) 115 { 116 throw new FileNotFoundException ( e.getMessage() ); 118 } 119 catch ( IllegalStateException e ) 120 { 121 throw new FileNotFoundException ( e.getMessage() ); 123 } 124 125 throw new HTTPRedirect( "sample.html?name=" + urlEncode( sample.getName() ) ); 127 } 128 129 132 } 133 134 | Popular Tags |