rendered paste body
import patterns.request.*;
import hep.aida.IAnalysisFactory;
import hep.aida.ITree;
import java.util.MissingResourceException;
public class AidaLazyMakeTreeRequest extends AidaTreeRequest {
String _treeName;
String _treeType;
ITree _cachedTree;
public AidaLazyMakeTreeRequest(String treeName,
String treeType) {
super();
init(treeName, treeType);
}
public AidaLazyMakeTreeRequest(Object caller,
String treeName,
String treeType) {
super(caller);
init(treeName, treeType);
}
private void init(String treeName, String treeType) {
_cachedTree = null;
_treeName = treeName;
_treeType = treeType;
}
public ITree getReturn() throws IllegalStateException, MissingResourceException {
if (!wasExecuted()) { throw new IllegalStateException();}
// returning the pre-cached tree
if (getCachedTree() != null)
return getCachedTree();
else
throw new MissingResourceException("The cached tree turned out to be null");
}
protected void enterExecutedState() throws IllegalStateException {
AidaAnalysisFactoryRequest afRequest = new AnalysisFactoryRequest();
afRequest.execute();
if (getTreeName() == null)
_cachedTree = afRequest.getReturn().createTreeFactory().create();
else if (getTreeType() == null)
_cachedTree = afRequest.getReturn().createTreeFactory().create(getTreeName());
else
_cachedTree = afRequest.getReturn().createTreeFactory().create(getTreeName(),
getTreeType());
super.enterExecutedState();
}
// to un-execute, we just un-precache the tree
protected void enterUnexecutedState() throws IllegalStateException {
_cachedTree = null;
super.enterUnexecutedState();
}
public boolean supportsUnexecution() { return true;}
// accessor methods
protected ITree getCachedTree() { return _cachedTree;}
protected String getTreeName() { return _treeName;}
protected String getTreeType() { return _treeType;}
}