PageContextImpl pci=(PageContextImpl) pc;
Argument newArgs= pci.getScopeFactory().getArgumentInstance();
newArgs.setFunctionArgumentNames(properties.argumentsSet);
LocalImpl newLocal=pci.getScopeFactory().getLocalInstance();
Undefined undefined=pc.undefinedScope();
Argument oldArgs=pc.argumentsScope();
Local oldLocal=pc.localScope();
Collection.Key oldCalledName=pci.getActiveUDFCalledName();
pc.setFunctionScopes(newLocal,newArgs);
pci.setActiveUDFCalledName(calledName);
int oldCheckArgs=undefined.setMode(properties.localMode==null?pc.getApplicationContext().getLocalMode():properties.localMode.intValue());
PageSource psInc=null;
try {
PageSource ps = getPageSource();
if(doIncludePath)psInc = ps;
//if(!ps.getDisplayPath().endsWith("Dump.cfc"))print.e(getPageSource().getDisplayPath());
if(doIncludePath && getOwnerComponent()!=null) {
//if(!ps.getDisplayPath().endsWith("Dump.cfc"))print.ds(ps.getDisplayPath());
psInc=ComponentUtil.getPageSource(getOwnerComponent());
if(psInc==pci.getCurrentTemplatePageSource()) {
psInc=null;
}
}
pci.addPageSource(ps,psInc);
pci.addUDF(this);
//////////////////////////////////////////
BodyContent bc=null;
Boolean wasSilent=null;
boolean bufferOutput=getBufferOutput(pci);
if(!getOutput()) {
if(bufferOutput) bc = pci.pushBody();
else wasSilent=pc.setSilent()?Boolean.TRUE:Boolean.FALSE;
}
UDF parent=null;
if(ownerComponent!=null) {
parent=pci.getActiveUDF();
pci.setActiveUDF(this);
}
Object returnValue = null;
try {
if(args!=null) defineArguments(pc,getFunctionArguments(),args,newArgs);
else defineArguments(pc,getFunctionArguments(),values,newArgs);
returnValue=implementation(pci);
if(ownerComponent!=null)pci.setActiveUDF(parent);
}
catch(Throwable t) {
if(ownerComponent!=null)pci.setActiveUDF(parent);
if(!getOutput()) {
if(bufferOutput)BodyContentUtil.flushAndPop(pc,bc);
else if(!wasSilent)pc.unsetSilent();
}
//BodyContentUtil.flushAndPop(pc,bc);
throw Caster.toPageException(t);
}
if(!getOutput()) {
if(bufferOutput)BodyContentUtil.clearAndPop(pc,bc);
else if(!wasSilent)pc.unsetSilent();
}
//BodyContentUtil.clearAndPop(pc,bc);
if(properties.returnType==CFTypes.TYPE_ANY) return returnValue;
else if(Decision.isCastableTo(properties.strReturnType,returnValue,false,false,-1)) return returnValue;
else throw new UDFCasterException(this,properties.strReturnType,returnValue);
//REALCAST return Caster.castTo(pageContext,returnType,returnValue,false);
//////////////////////////////////////////
}
finally {
pc.removeLastPageSource(psInc!=null);
pci.removeUDF();
pci.setFunctionScopes(oldLocal,oldArgs);
pci.setActiveUDFCalledName(oldCalledName);
undefined.setMode(oldCheckArgs);
pci.getScopeFactory().recycle(newArgs);
pci.getScopeFactory().recycle(newLocal);
}
}