/*******************************************************************************
 * Copyright (c) 2004 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.model.script;

import org.eclipse.birt.core.script.IJavascriptInitializer;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

/**
 * 
 * Model's javascript initilizer, used to initialize model defined native
 * javascript object that model's wrap factory can handle.
 * 
 */

public class ModelJavaScriptInitializer implements IJavascriptInitializer
{

	boolean hasInitialized = false;
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.core.script.IJavascriptInitializer#initialize(org.mozilla.javascript.Context,
	 *      org.mozilla.javascript.Scriptable)
	 */

	public void initialize( Context cx, Scriptable scope )
	{
		if (hasInitialized == false)
		{
			try
			{
				Scriptable top = ScriptableObject.getTopLevelScope(scope);
				ScriptableObject.defineClass( top, NativeConfigVariable.class );
				ScriptableObject.defineClass( top, NativeColor.class );
				ScriptableObject.defineClass( top, NativeDimension.class );
				ScriptableObject.defineClass( top, NativePropertyDefinition.class );
				ScriptableObject.defineClass( top, NativeElementDefinition.class );
				ScriptableObject.defineClass( top, NativeReportDefinition.class );
				ScriptableObject.defineClass( top, NativeReport.class );
				hasInitialized = true;
	
			}
			catch ( Exception e )
			{
				assert false;
			}
		}
	}
}