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

import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;

/**
 * Adapter converting the Model interface of Report definition to script
 * interface.
 */
public class ReportDefinition extends ElementDefinition
{

	/**
	 * 
	 * constructs the adapter with the given report design.
	 * 
	 * @param design
	 *            the report design
	 */

	public ReportDefinition( ReportDesignHandle design )
	{
		super( design );
	}

	/**
	 * Finds the style in the design according to the given style name.*
	 * 
	 * @param styleName
	 *            name of the style
	 * @return the definition of the style element
	 */

	ElementDefinition findStyle( String styleName )
	{
		DesignElementHandle elementHandle = ( (ReportDesignHandle) element )
				.findStyle( styleName );
		if ( elementHandle != null )
			return new ElementDefinition( elementHandle );

		return null;
	}

	/**
	 * Finds the report item according to the given element name.
	 * 
	 * @param itemName
	 *            name of the finding element
	 * @return the definition of the finding element.
	 */

	ElementDefinition findReportItem(   String itemName )
	{
		DesignElementHandle elementHandle = ( (ReportDesignHandle) element )
				.findElement( itemName );
		if ( elementHandle != null )
			return new ElementDefinition( elementHandle );

		return null;
	}

	/**
	 * Finds the data source in the design according to the given name.
	 * 
	 * @param sourceName
	 *            name of the data source
	 * @return the definition of the data source.
	 */

	ElementDefinition findDataSource( String sourceName )
	{
		DesignElementHandle elementHandle = ( (ReportDesignHandle) element )
				.findDataSource( sourceName );
		if ( elementHandle != null )
			return new ElementDefinition( elementHandle );

		return null;
	}

	/**
	 * Finds the data set in the design according to the given name.
	 * 
	 * @param dataSetName
	 *            name of the data set.
	 * @return the definition of the data set.
	 */

	ElementDefinition findDataSet( String dataSetName )
	{
		DesignElementHandle elementHandle = ( (ReportDesignHandle) element )
				.findDataSet( dataSetName );
		if ( elementHandle != null )
			return new ElementDefinition( elementHandle );

		return null;
	}

	/**
	 * Finds the parameter in the design according to the given name.
	 * 
	 * @param parameterName
	 *            name of the parameter
	 * @return the definition of the parameter.
	 */

	ElementDefinition findParameter( String parameterName )
	{
		DesignElementHandle elementHandle = ( (ReportDesignHandle) element )
				.findParameter( parameterName );
		if ( elementHandle != null )
			return new ElementDefinition( elementHandle );

		return null;
	}

	/**
	 * Returns the list which contains all styles in the current design.
	 * 
	 * @return the style list.
	 */
	List getStyles( )
	{
		List list = ( (ReportDesignHandle) element ).getStyles( ).getContents( );
		return list;
	}

	/**
	 * Returns the list which contains all dataSources in the current design.
	 * 
	 * @return the dataSource list.
	 */
	List getDataSourses( )
	{
		List list = ( (ReportDesignHandle) element ).getDataSources( )
				.getContents( );
		return list;
	}

	/**
	 * Returns the list which contains all dataSets in the current design.
	 * 
	 * @return the dataSet list.
	 */
	List getDataSets( )
	{
		List list = ( (ReportDesignHandle) element ).getDataSets( )
				.getContents( );
		return list;
	}

	/**
	 * Returns the list which contains all parameters in the current design.
	 * 
	 * @return the parameter list.
	 */
	List getParameters( )
	{
		List list = ( (ReportDesignHandle) element ).getParameters( )
				.getContents( );
		return list;
	}

}