<commit_before>/*******************************************************************************
 * Copyright (c) 2004, 2009 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.engine.internal.document.v4;

import java.util.logging.Level;

import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.InstanceID;
import org.eclipse.birt.report.engine.content.IContent;
import org.eclipse.birt.report.engine.extension.IReportItemExecutor;
import org.eclipse.birt.report.engine.internal.document.DocumentExtension;
import org.eclipse.birt.report.engine.internal.executor.doc.Fragment;
import org.eclipse.birt.report.engine.internal.executor.doc.Segment;
import org.eclipse.birt.report.engine.presentation.InstanceIndex;

/**
 * <p>
 * The container executor uses a fragment to define its children. The fragment
 * is defined by segments, each segment is defined with two InstanceID. The
 * first index of the segment may be Segment.LEFT_MOST_EDGE, which means the
 * segment starts from the first child. The second index of the segment may be
 * Segment.RIGHT_MOST_EDGE, which means it ends to the last children.
 * </p>
 * 
 * <p>
 * To create the child executor, the container needs:
 * <ul>
 * <li> if it starts with the segment, call skipToExecutor to locate the current
 * executor.</li>
 * <li> call createExecutor() to the next executor.</li>
 * <li> get the content from executor to see if it matches the edge end.</li>
 * <li> if it reaches the edge end, skip to the next segment.</li>
 * </ul>
 * </p>
 * <p>
 * To create the child executor, the container needs prepare the content
 * template which is loaded from the document. the template is loaded as:
 * <ul>
 * <li>If there exits the next content, use the content.
 * <li>otherwise,
 * 
 */
abstract public class ContainerExecutor extends ReportItemExecutor
{
	/**
	 * we need prepare the next executable child
	 */
	private boolean needPrepareNext;

	protected boolean prepareFirstChild;
	/**
	 * the sections defined in the fragment.
	 */
	protected Object[][] sections;
	/**
	 * if we need jump to next section
	 */
	protected boolean useNextSection;
	/**
	 * the current section used by nextFragment
	 */
	protected int nextSection;

	protected long nextOffset;

	protected ContainerExecutor( ExecutorManager manager, int type )
	{
		super( manager, type );
		needPrepareNext = true;
		prepareFirstChild = true;
		sections = null;
		useNextSection = true;
		nextSection = -1;
		nextOffset = -1;
	}

	public void close( )
	{
		if ( nextOffset != -1 )
		{
			reader.unloadContent( nextOffset );
			nextOffset = -1;
		}
		prepareFirstChild = true;
		needPrepareNext = true;
		sections = null;
		useNextSection = true;
		nextSection = -1;
		nextOffset = -1;
		super.close( );
	}

	private IReportItemExecutor childExecutor;

	public boolean hasNextChild( )
	{
		if ( needPrepareNext )
		{
			try
			{
				childExecutor = prepareChildExecutor( );
			}
			catch ( Exception ex )
			{
				logger.log( Level.WARNING, ex.getMessage( ), ex );
				context.addException( this.getDesign( ), new EngineException(
						ex.getLocalizedMessage( ), ex ) );
			}
			needPrepareNext = false;
		}
		return childExecutor != null;
	}<commit_msg>T31805: Stop the execution if there are some exceptions  to avoid the endless loop<commit_after>/*******************************************************************************
 * Copyright (c) 2004, 2009 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.engine.internal.document.v4;

import java.util.logging.Level;

import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.InstanceID;
import org.eclipse.birt.report.engine.content.IContent;
import org.eclipse.birt.report.engine.extension.IReportItemExecutor;
import org.eclipse.birt.report.engine.internal.document.DocumentExtension;
import org.eclipse.birt.report.engine.internal.executor.doc.Fragment;
import org.eclipse.birt.report.engine.internal.executor.doc.Segment;
import org.eclipse.birt.report.engine.presentation.InstanceIndex;

/**
 * <p>
 * The container executor uses a fragment to define its children. The fragment
 * is defined by segments, each segment is defined with two InstanceID. The
 * first index of the segment may be Segment.LEFT_MOST_EDGE, which means the
 * segment starts from the first child. The second index of the segment may be
 * Segment.RIGHT_MOST_EDGE, which means it ends to the last children.
 * </p>
 * 
 * <p>
 * To create the child executor, the container needs:
 * <ul>
 * <li> if it starts with the segment, call skipToExecutor to locate the current
 * executor.</li>
 * <li> call createExecutor() to the next executor.</li>
 * <li> get the content from executor to see if it matches the edge end.</li>
 * <li> if it reaches the edge end, skip to the next segment.</li>
 * </ul>
 * </p>
 * <p>
 * To create the child executor, the container needs prepare the content
 * template which is loaded from the document. the template is loaded as:
 * <ul>
 * <li>If there exits the next content, use the content.
 * <li>otherwise,
 * 
 */
abstract public class ContainerExecutor extends ReportItemExecutor
{
	/**
	 * we need prepare the next executable child
	 */
	private boolean needPrepareNext;

	protected boolean prepareFirstChild;
	/**
	 * the sections defined in the fragment.
	 */
	protected Object[][] sections;
	/**
	 * if we need jump to next section
	 */
	protected boolean useNextSection;
	/**
	 * the current section used by nextFragment
	 */
	protected int nextSection;

	protected long nextOffset;

	protected ContainerExecutor( ExecutorManager manager, int type )
	{
		super( manager, type );
		needPrepareNext = true;
		prepareFirstChild = true;
		sections = null;
		useNextSection = true;
		nextSection = -1;
		nextOffset = -1;
	}

	public void close( )
	{
		if ( nextOffset != -1 )
		{
			reader.unloadContent( nextOffset );
			nextOffset = -1;
		}
		prepareFirstChild = true;
		needPrepareNext = true;
		sections = null;
		useNextSection = true;
		nextSection = -1;
		nextOffset = -1;
		super.close( );
	}

	private IReportItemExecutor childExecutor;

	public boolean hasNextChild( )
	{
		if ( needPrepareNext )
		{
			try
			{
				childExecutor = prepareChildExecutor( );
			}
			catch ( Exception ex )
			{
				childExecutor = null;
				logger.log( Level.WARNING, ex.getMessage( ), ex );
				context.addException( this.getDesign( ), new EngineException(
						ex.getLocalizedMessage( ), ex ) );
			}
			needPrepareNext = false;
		}
		return childExecutor != null;
	}
{'fraction_non_alphanumeric': 0.13688780355447022, 'fraction_numerical': 0.005833672500339167, 'mean_word_length': 3.954301075268817, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6895227', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2071, 'n_words': 697}