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

import java.util.Iterator;

import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.olap.LevelHandle;
import org.eclipse.birt.report.model.api.util.StringUtil;
import org.eclipse.birt.report.model.core.DesignElement;
import org.eclipse.birt.report.model.core.Module;
import org.eclipse.birt.report.model.elements.interfaces.IMemberValueModel;

/**
 * CrosstabMemberValueHandle
 */
public class MemberValueHandle extends ContentElementHandle
		implements
			IMemberValueModel
{

	/**
	 * Constructs a member value handle with the given design and the element.
	 * The application generally does not create handles directly. Instead, it
	 * uses one of the navigation methods available on other element handles.
	 * 
	 * @param module
	 *            the module
	 * @param element
	 *            the model representation of the element
	 */

	public MemberValueHandle( Module module, DesignElement element )
	{
		super( module, element );

	}

	/**
	 * Gets the value of this member value handle.
	 * 
	 * @return value of this member
	 */
	public String getValue( )
	{
		return getStringProperty( VALUE_PROP );
	}

	/**
	 * Sets the value of this member value.
	 * 
	 * @param value
	 *            the value to set
	 * @throws SemanticException
	 */
	public void setValue( String value ) throws SemanticException
	{
		setStringProperty( VALUE_PROP, value );
	}

	/**
	 * Gets name of the referred cube level element.
	 * 
	 * @return name of the referred cube level
	 */
	public String getCubeLevelName( )
	{
		return getStringProperty( LEVEL_PROP );
	}

	/**
	 * Gets the cube level handle for this member value.
	 * 
	 * @return the referred cube level handle if resolved, otherwise null
	 */
	public LevelHandle getLevel( )
	{
		return (LevelHandle) getElementProperty( LEVEL_PROP );
	}

	/**
	 * Sets the referred level of this member value.
	 * 
	 * @param levelHandle
	 * @throws SemanticException
	 */
	public void setLevel( LevelHandle levelHandle ) throws SemanticException
	{
		if ( levelHandle == null )
			setStringProperty( LEVEL_PROP, null );
		else
		{
			ModuleHandle moduleHandle = levelHandle.getRoot( );
			String valueToSet = levelHandle.getElement( ).getFullName( );
			if ( moduleHandle instanceof LibraryHandle )
			{
				String namespace = ( (LibraryHandle) moduleHandle )
						.getNamespace( );
				valueToSet = StringUtil.buildQualifiedReference( namespace,
						valueToSet );
			}
			setStringProperty( LEVEL_PROP, valueToSet );
		}
	}

	/**
	 * Returns the iterator for filter list defined on this member value.
	 * 
	 * @return the iterator for <code>FilterCond</code> structure list defined
	 *         on a table or list.
	 */

	public Iterator<FilterConditionHandle> filtersIterator( )
	{
		PropertyHandle propHandle = getPropertyHandle( FILTER_PROP );
		assert propHandle != null;
		return propHandle.iterator( );
	}
}

@@ -2691,16 +2691,25 @@
 %0A%09%09%7B%0A%09%09%09
+/*%0A%09%09%09 * 
 ModuleHa
@@ -2755,18 +2755,21 @@
 ( );
-%0A%09%09%09
+ 
 String
+%0A%09%09%09 *
  val
@@ -2823,16 +2823,19 @@
 ( );
-%0A%09%09%09if (
+ if (%0A%09%09%09 *
  mod
@@ -2874,18 +2874,11 @@
 le )
-%0A%09%09%09%7B%0A%09%09%09%09
+ %7B 
 Stri
@@ -2893,16 +2893,22 @@
 pace = (
+%0A%09%09%09 *
  (Librar
@@ -2930,23 +2930,17 @@
 Handle )
-%0A%09%09%09%09%09%09
+ 
 .getName
@@ -2948,21 +2948,17 @@
 pace( );
-%0A%09%09%09%09
+ 
 valueToS
@@ -2961,16 +2961,22 @@
 eToSet =
+%0A%09%09%09 *
  StringU
@@ -3018,15 +3018,9 @@
 ace,
-%0A%09%09%09%09%09%09
+ 
 valu
@@ -3032,17 +3032,17 @@
 t );
-%0A%09%09%09
+ 
 %7D%0A%09%09%09
+ * 
 setS
@@ -3082,16 +3082,66 @@
 oSet );%0A
+%09%09%09 */%0A%09%09%09setProperty( LEVEL_PROP, levelHandle );%0A
 %09%09%7D%0A%09%7D%0A%0A

change logic of setLevel in MemberValueHandle.