Subversion Repositories pub

Compare Revisions

Ignore whitespace Rev 56 → Rev 61

/pluggablejs/branches/1.1.0build33/src/net/outlyer/plugins/SandboxAccessorImpl.java
26,24 → 26,45
 
// $Id$
 
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
 
/**
* {@see SandboxAccessor}
* Default implementation of a {@see SandboxAccessor}.
*/
public abstract class SandboxAccessorImpl implements SandboxAccessor {
public Callable<Sandbox> _getSandbox;
protected final Sandbox getSandbox() {
if (null == _getSandbox) {
public Object sandboxGetter;
 
public static Sandbox getSandbox(final SandboxAccessor sa) {
try {
// Retrieve the field...
final Field gS = sa.getClass().getField("sandboxGetter");
// Evaluate as a callable
return ((Callable<Sandbox>)gS.get(sa)).call();
}
catch (final NoSuchFieldException e) {
throw new IllegalStateException(sa.getClass()+" hasn't been correctly initialised", e);
}
catch (final Exception e) {
throw new IllegalStateException("getSandbox produced an exception ("+
e.getClass().getSimpleName()+"),"+
"for object "+sa+" which is not expected!: " +
e.getMessage(), e);
}
}
 
public final Sandbox getSandbox() {
if (null == sandboxGetter) {
throw new IllegalStateException(getClass()+" hasn't been correctly initialised");
}
try {
return _getSandbox.call();
return ((Callable<Sandbox>)sandboxGetter).call();
}
catch (final Exception e) {
throw new IllegalStateException("getSandbox produced an exception, which is not expected!");
throw new IllegalStateException("sandboxGetter produced an " +
"exception, which is not expected!");
}
 
}
}