/*******************************************************************************
 * Copyright (c) 2005 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/
package org.eclipse.birt.report.engine.script.internal;

import org.eclipse.birt.data.engine.script.JSMethodRunner;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.mozilla.javascript.Scriptable;

public abstract class DtEScriptExecutor extends ScriptExecutor
{

	protected static final String DATA_SET = "DataSet";

	protected static final String DATA_SOURCE = "DataSource";

	protected static final String BEFORE_OPEN = "beforeOpen";

	protected static final String BEFORE_CLOSE = "beforeClose";

	protected static final String AFTER_OPEN = "afterOpen";

	protected static final String AFTER_CLOSE = "afterClose";

	protected IReportContext reportContext;

	private JSMethodRunner runner;

	public DtEScriptExecutor( IReportContext reportContext )
	{
		this.reportContext = reportContext;
	}

	protected JSMethodRunner getRunner( Scriptable scope, String type,
			String name )
	{
		if ( runner == null )
		{
			String scopeName = type + "[" + name + "]";
			runner = new JSMethodRunner( scope, scopeName );
		}
		return runner;
	}

	protected JSScriptStatus handleJS( Scriptable scope, String type,
			String name, String method, String script )
	{
		if ( script == null || type == null || name == null || method == null )
			return JSScriptStatus.NO_RUN;
		if ( !( DATA_SET.equals( type ) || DATA_SOURCE.equals( type ) ) )
			return JSScriptStatus.NO_RUN;
		Object result = null;
		try
		{
			JSMethodRunner jsr = getRunner( scope, type, name );
			result = jsr.runScript( method, script );
		} catch ( Exception e )
		{
			e.printStackTrace( );
		}
		return new JSScriptStatus( true, result );
	}

	protected abstract JSScriptStatus handleJS( Scriptable scope, String name,
			String method, String script );
}

@@ -1437,37 +1437,8 @@
 %0A%09%7B%0A
-%09%09if ( runner == null )%0A%09%09%7B%0A%09
 %09%09St
@@ -1479,17 +1479,16 @@
  + %22%5D%22;%0A
-%09
 %09%09runner
@@ -1526,28 +1526,24 @@
 copeName );%0A
-%09%09%7D%0A
 %09%09return run

Fix bugzilla bug 121166 in the second time use of scripted data set, the result is null