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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.birt.report.model.core.DesignElement;
import org.eclipse.birt.report.model.core.Module;
import org.eclipse.birt.report.model.elements.ExtendedItem;
import org.eclipse.birt.report.model.validators.AbstractElementValidator;

/**
 * Validates the extension is valid, which is provided by
 * <code>IReportItem</code>.
 * 
 * <h3>Rule</h3>
 * The rule is defined by
 * {@link org.eclipse.birt.report.model.api.extension.IReportItem#validate()}.
 * 
 * <h3>Applicability</h3>
 * This validator is only applied to <code>TableItem</code>.
 */

public class ExtensionValidator extends AbstractElementValidator
{

	/**
	 * Name of this validator.
	 */

	public final static String NAME = "ExtensionValidator"; //$NON-NLS-1$

	private final static ExtensionValidator instance = new ExtensionValidator( );

	/**
	 * Returns the singleton validator instance.
	 * 
	 * @return the validator instance
	 */

	public static ExtensionValidator getInstance( )
	{
		return instance;
	}

	/**
	 * Validates whether any cell in the given row overlaps others.
	 * 
	 * @param module
	 *            the module
	 * @param element
	 *            the row to validate
	 * @return error list, each of which is the instance of
	 *         <code>SemanticException</code>.
	 */

	public List validate( Module module, DesignElement element )
	{
		if ( !( element instanceof ExtendedItem ) )
			return Collections.EMPTY_LIST;

		return doValidate( module, (ExtendedItem) element );
	}

	private List doValidate( Module module, ExtendedItem toValidate )
	{
		List list = new ArrayList( );

		if ( toValidate.getExtendedElement( ) != null )
		{

			List exceptions = toValidate.getExtendedElement( ).validate( );

			if ( exceptions != null )
				list.addAll( exceptions );
		}

		return list;
	}
}
@@ -661,16 +661,93 @@
 .List;%0A%0A
+import org.eclipse.birt.report.model.api.extension.ExtendedElementException;%0A
 import o
@@ -2352,17 +2352,17 @@
 ment( ) 
-!
+=
 = null )
@@ -2366,18 +2366,156 @@
 l )%0A%09%09%7B%0A
-%0A
 %09
+%09%09try%0A%09%09%09%7B%0A%09%09%09%09toValidate.initializeReportItem( module );%09%09%0A%09%09%09%7D%0A%09%09%09catch ( ExtendedElementException e )%0A%09%09%09%7B%0A%09%09%09%09return list;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A
 %09%09List e
@@ -2575,17 +2575,16 @@
 ( );%0A%0A%09%09
-%09
 if ( exc
@@ -2601,17 +2601,16 @@
  null )%0A
-%09
 %09%09%09list.
@@ -2630,20 +2630,16 @@
 tions );
-%0A%09%09%7D
 %0A%0A%09%09retu

change the extension validator to initialize report item for extension element.