/*******************************************************************************
 * 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.elements.strategy;

import org.eclipse.birt.report.model.core.DesignElement;
import org.eclipse.birt.report.model.core.Module;
import org.eclipse.birt.report.model.core.PropertySearchStrategy;
import org.eclipse.birt.report.model.elements.GroupElement;
import org.eclipse.birt.report.model.metadata.ElementPropertyDefn;

/**
 * Provides the specific property searching route for <code>GroupElement</code>.
 */

public class GroupElementPropSearchStrategy extends PropertySearchStrategy
{

	private final static GroupElementPropSearchStrategy instance = new GroupElementPropSearchStrategy( );

	/**
	 * Protected constructor.
	 */

	protected GroupElementPropSearchStrategy( )
	{
	}

	/**
	 * Returns the instance of <code>GroupElementPropSearchStrategy</code>
	 * which provide the specific property searching route for
	 * <code>GroupElement</code>.
	 * 
	 * @return the instance of <code>GroupElementPropSearchStrategy</code>
	 */

	public static PropertySearchStrategy getInstance( )
	{
		return instance;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.model.core.PropertySearchStrategy#getPropertyFromSelf(org.eclipse.birt.report.model.core.Module,
	 *      org.eclipse.birt.report.model.core.DesignElement,
	 *      org.eclipse.birt.report.model.metadata.ElementPropertyDefn)
	 */

	protected Object getPropertyFromSelf( Module module, DesignElement element,
			ElementPropertyDefn prop )
	{
		Object value = super.getPropertyFromSelf( module, element, prop );

		if ( !GroupElement.TOC_PROP.equals( prop.getName( ) ) )
			return value;

		// if it is TOC property and the value is not null

		if ( value != null )
			return value;

		ElementPropertyDefn propDefn = element
				.getPropertyDefn( GroupElement.KEY_EXPR_PROP );
		return super.getPropertyFromSelf( module, element, propDefn );
	}
}
