
/*******************************************************************************
 * Copyright (c) 2004, 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.data.engine.olap.script;

import org.eclipse.birt.core.script.JavascriptEvalUtil;
import org.eclipse.birt.core.script.ScriptContext;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.expression.CompiledExpression;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

/**
 * 
 */

public class OLAPExpressionHandler extends CompiledExpression
{
	private Script script;
	
	OLAPExpressionHandler( Script script )
	{
		assert script!= null;
		this.script = script;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.birt.data.engine.expression.CompiledExpression#evaluate(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable)
	 */
	public Object evaluate( ScriptContext context, Scriptable scope )
			throws DataException
	{
		Object temp = this.script.exec( context.getContext( ), scope );

		temp = JavascriptEvalUtil.convertJavascriptValue( temp );
		if ( temp instanceof ScriptableObject )
		{
			return ( (ScriptableObject) temp ).getDefaultValue( null );
		}
		return temp;
	}

	public int getType( )
	{
		return 0;
	}
	
}

@@ -807,24 +807,74 @@
 Expression;%0A
+import org.mozilla.javascript.EvaluatorException;%0A
 import org.m
@@ -1469,16 +1469,42 @@
 t temp =
+ null;%0A%09%09try%0A%09%09%7B%0A%09%09%09temp =
  this.sc
@@ -1546,17 +1546,17 @@
 cope );%0A
-%0A
+%09
 %09%09temp =
@@ -1609,16 +1609,17 @@
 mp );%0A%09%09
+%09
 if ( tem
@@ -1652,18 +1652,20 @@
 ect )%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09retur
@@ -1719,16 +1719,109 @@
 null );%0A
+%09%09%09%7D%0A%09%09%7D%0A%09%09catch( EvaluatorException e )%0A%09%09%7B%0A%09%09%09throw new DataException ( e.details( ), e );%0A
 %09%09%7D%0A%09%09re

Fix bugzilla bug 232722 Provide more friendly exception if there is no outer result exist