/*******************************************************************************
 * 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 java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.elements.structures.ConfigVariable;
import org.eclipse.birt.report.model.elements.ReportDesign;

/**
 * Represents all information about the report and the context in which the
 * report is running.
 */

public class Report
{

	/**
	 * The cached report design
	 */

	private ReportDesignHandle designHandle = null;

	/**
	 * The report design definition.
	 */

	private ReportDefinition reportDefn = null;

	/**
	 * Constructs a report object for the java-scriptable report object.
	 * 
	 * @param designHandle
	 *            the report design handle.
	 */

	public Report( ReportDesignHandle designHandle )
	{
		this.designHandle = designHandle;
		this.reportDefn = new ReportDefinition( designHandle );
	}

	/**
	 * Returns the config variables bound with the report design.
	 * 
	 * @return a map containing config variables.
	 */

	public Map getConfig( )
	{
		List list = (List) designHandle
				.getProperty( ReportDesign.CONFIG_VARS_PROP );

		Map retValue = new LinkedHashMap( );
		if ( list != null )
		{
			for ( Iterator iter = list.iterator( ); iter.hasNext( ); )
			{
				ConfigVariable conf = (ConfigVariable) iter.next( );
				retValue.put( conf.getName( ), conf );
			}
		}
		return retValue;
	}

	/**
	 * Returns a <code>ReportDefinition</code> object that describes the
	 * design of the report.
	 * 
	 * @return a <code>ReportDefinition</code> object
	 */

	public ReportDefinition getDesign( )
	{
		return reportDefn;
	}
}