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 XMLCreateSamplesHandler 40 extends AbstractXMLHandler 41 { 42 45 51 public XMLCreateSamplesHandler( DefaultInstrumentManager manager, 52 InstrumentManagerHTTPConnector connector ) 53 { 54 super( "/create-samples.xml", manager, connector ); 55 } 56 57 60 67 public void doGet( String path, Map parameters, PrintWriter out ) 68 throws IOException 69 { 70 String [] names = getParameters( parameters, "name" ); 71 String [] descriptions = getParameters( parameters, "description" ); 72 long[] intervals = getLongParameters( parameters, "interval", 0 ); 73 int[] sizes = getIntegerParameters( parameters, "size", 0 ); 74 long[] leases = getLongParameters( parameters, "lease", 0 ); 75 int[] types = getIntegerParameters( parameters, "type", 0 ); 76 boolean packed = getBooleanParameter( parameters, "packed", false ); 77 78 if ( names.length != descriptions.length ) 79 { 80 throw new FileNotFoundException ( 81 "The number of descriptions not equal to the number of names." ); 82 } 83 if ( names.length != intervals.length ) 84 { 85 throw new FileNotFoundException ( 86 "The number of intervals not equal to the number of names." ); 87 } 88 if ( names.length != sizes.length ) 89 { 90 throw new FileNotFoundException ( 91 "The number of sizes not equal to the number of names." ); 92 } 93 if ( names.length != leases.length ) 94 { 95 throw new FileNotFoundException ( 96 "The number of leases not equal to the number of names." ); 97 } 98 if ( names.length != types.length ) 99 { 100 throw new FileNotFoundException ( 101 "The number of types not equal to the number of names." ); 102 } 103 104 out.println( InstrumentManagerHTTPConnector.XML_BANNER ); 105 if ( names.length > 0 ) 106 { 107 outputLine( out, "", packed, "<samples>" ); 108 109 for ( int i = 0; i < names.length; i++ ) 110 { 111 String name = names[i]; 112 String description = descriptions[i]; 113 long interval = intervals[i]; 114 int size = sizes[i]; 115 long lease = leases[i]; 116 int type = types[i]; 117 118 InstrumentDescriptor desc; 119 try 120 { 121 desc = getInstrumentManager().locateInstrumentDescriptor( name ); 122 } 123 catch ( NoSuchInstrumentException e ) 124 { 125 desc = null; 127 } 128 129 if ( desc != null ) 130 { 131 size = Math.max( 1, Math.min( size, getConnector().getMaxLeasedSampleSize() ) ); 135 lease = Math.max( 136 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) ); 137 138 if ( getInstrumentManager().getLeaseSampleCount() 139 >= getConnector().getMaxLeasedSamples() ) 140 { 141 lease = 1; 142 } 143 144 InstrumentSampleDescriptor sample; 146 try 147 { 148 sample = 149 desc.createInstrumentSample( description, interval, size, lease, type ); 150 } 151 catch ( IllegalArgumentException e ) 152 { 153 throw new FileNotFoundException ( e.getMessage() ); 155 } 156 catch ( IllegalStateException e ) 157 { 158 throw new FileNotFoundException ( e.getMessage() ); 160 } 161 162 outputSample( out, sample, " ", packed ); 163 } 164 } 165 166 outputLine( out, "", packed, "</samples>" ); 167 } 168 else 169 { 170 outputLine( out, "", packed, "<samples/>" ); 171 } 172 } 173 174 177 } 178 179 | Popular Tags |