String name = getParameter( parameters, "name" );
long lease = getLongParameter( parameters, "lease" );
String instrument = getParameter( parameters, "instrument", null );
String chart = getParameter( parameters, "chart", null );
InstrumentSampleDescriptor desc;
try
{
desc = getInstrumentManager().locateInstrumentSampleDescriptor( name );
}
catch ( NoSuchInstrumentSampleException e )
{
// Sample no longer exists, go back to the parent instrument.
int pos = name.lastIndexOf( '.' );
if ( pos >= 0 )
{
throw new HTTPRedirect(
"instrument.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.
lease = Math.max( 1, Math.min( lease, m_connector.getMaxLeasedSampleLease() ) );
if ( getInstrumentManager().getLeaseSampleCount() >= m_connector.getMaxLeasedSamples() )
{
lease = 1;
}
// Renew the lease
desc.extendLease( lease );
if ( instrument != null )
{
// Go to the instrument page.
int pos = name.lastIndexOf( '.' );
if ( pos >= 0 )
{
throw new HTTPRedirect(
"instrument.html?name=" + urlEncode( name.substring( 0, pos ) ) );
}
else
{
throw new HTTPRedirect( "instrumentable.html" );
}
}
else
{
// Redirect to the sample page.
throw new HTTPRedirect( "sample.html?name=" + urlEncode( desc.getName() )
+ ( chart == null ? "" : "&chart=true" ) );
}
}