/*******************************************************************************
 * 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.api.extension.ExtendedElementException;
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 )
		{
			try
			{
				toValidate.initializeReportItem( module );		
			}
			catch ( ExtendedElementException e )
			{
				return list;
			}
		}
		
		List exceptions = toValidate.getExtendedElement( ).validate( );

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

		return list;
	}
}
@@ -738,16 +738,80 @@
 eption;%0A
+import org.eclipse.birt.report.model.api.extension.IReportItem;%0A
 import o
@@ -965,24 +965,79 @@
 tendedItem;%0A
+import org.eclipse.birt.report.model.elements.Library;%0A
 import org.e
@@ -2437,72 +2437,465 @@
 %0A%0A%09%09
-if ( toValidate.getExtendedElement( ) == null )%0A%09%09%7B%0A%09%09%09try%0A%09%09%09%7B%0A
+// if the module is a library and not includded by any report, it is not%0A%09%09// necessary to initialized it%0A%09%09// by the validate. This method will be called by the parser in the end%0A%09%09// document method. The library error information will not be displayed%0A%09%09// in the report design console.%0A%09%09if ( toValidate.getExtendedElement( ) == null )%0A%09%09%7B%0A%09%09%09if ( !( ( module instanceof Library ) && ( (Library) module )%0A%09%09%09%09%09.getHost( ) != null ) )%0A%09%09%09%7B%0A%09%09%09%09try%0A%09%09%09%09%7B%0A%09
 %09%09%09%09
@@ -2940,19 +2940,18 @@
 e );
-%09%09
 %0A
+%09
 %09%09%09%7D%0A%09%09%09
 catc
@@ -2946,16 +2946,17 @@
 %09%09%09%7D%0A%09%09%09
+%09
 catch ( 
@@ -2983,26 +2983,28 @@
 tion e )%0A%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09return l
@@ -3008,16 +3008,22 @@
 n list;%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D
@@ -3027,11 +3027,64 @@
 %09%09%7D%0A
-%09%09
 %0A
+%09%09if ( toValidate.getExtendedElement( ) != null )%0A%09%09%7B%0A%09
 %09%09Li
@@ -3144,24 +3144,25 @@
 date( );%0A%0A%09%09
+%09
 if ( excepti
@@ -3175,16 +3175,17 @@
  null )%0A
+%09
 %09%09%09list.
@@ -3206,16 +3206,19 @@
 ions );%0A
+%09%09%7D
 %0A%09%09retur

Fix the bug 143898