{
// Sample no longer exists, go back to the parent instrument.
int pos = name.lastIndexOf( '.' );
if ( pos >= 0 )
{
throw new HTTPRedirect(
"instrumentable.html?name=" + urlEncode( name.substring( 0, pos ) ) );
}
else
{
throw new HTTPRedirect( "instrument-manager.html" );
}
}
// The instrument manager will do its own tests of the lease, but the
// restrictions on this connector may be stronger so they must be tested
// here as well.
size = Math.max( 1, Math.min( size, getConnector().getMaxLeasedSampleSize() ) );
lease = Math.max( 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) );
if ( getInstrumentManager().getLeaseSampleCount() >= getConnector().getMaxLeasedSamples() )
{
lease = 1;
}
// Register the new lease
InstrumentSampleDescriptor sample;
try
{
sample = desc.createInstrumentSample( description, interval, size, lease, type );
}
catch ( IllegalArgumentException e )
{
// The sample type is not valid.
throw new FileNotFoundException( e.getMessage() );
}
catch ( IllegalStateException e )
{
// The sample type was incompatible with the instrument.
throw new FileNotFoundException( e.getMessage() );
}
// Redirect to the new sample page.
throw new HTTPRedirect( "sample.html?name=" + urlEncode( sample.getName() ) );
}