Chart cmDesignTime, Bounds bo, IExternalContext externalContext, RunTimeContext rtc, IStyleProcessor externalProcessor ) throws ChartException
Chart cmDesignTime, Scriptable scParent, Bounds bo, RunTimeContext rtc ) throws ChartException
	public final GeneratedChartState build( IDisplayServer ids,			Chart cmDesignTime, Bounds bo, IExternalContext externalContext,			RunTimeContext rtc, IStyleProcessor externalProcessor )			throws ChartException	{		if ( ids == null || cmDesignTime == null || bo == null )		{			throw new ChartException( ChartEnginePlugin.ID,					ChartException.GENERATION,					"exception.illegal.null.value", //$NON-NLS-1$ 					ResourceBundle.getBundle( Messages.ENGINE,							Locale.getDefault( ) // LOCALE?							) );		}		// CREATE A RUNTIME CONTEXT IF NEEDED		if ( rtc == null )		{			rtc = new RunTimeContext( );		}		// UPDATE THE CONTEXT WITH A LOCALE IF IT IS UNDEFINED		if ( rtc.getLocale( ) == null )		{			rtc.setLocale( Locale.getDefault( ) );		}		// UPDATE THE CHART SCRIPT CONTEXT		IChartScriptContext icsc = rtc.getScriptContext( );		if ( icsc == null )		{			// re-init chart script context.			ChartScriptContext csc = new ChartScriptContext( );			csc.setChartInstance( (Chart) EcoreUtil.copy( cmDesignTime ) );			csc.setExternalContext( externalContext );			csc.setLocale( rtc.getLocale( ) );			csc.setLogger( logger );			rtc.setScriptContext( csc );			icsc = csc;		}		else if ( icsc instanceof ChartScriptContext )		{			// reset logger.			( (ChartScriptContext) icsc ).setLogger( logger );		}		if ( externalContext != null && icsc instanceof ChartScriptContext )		{			( (ChartScriptContext) icsc ).setExternalContext( externalContext );		}		final Chart cmRunTime = icsc.getChartInstance( );		// flatten the default styles.		prepareStyles( cmRunTime, externalProcessor );		// INITIALIZE THE SCRIPT HANDLER		ScriptHandler sh = rtc.getScriptHandler( );		if ( sh == null ) // IF NOT PREVIOUSLY DEFINED BY		// REPORTITEM ADAPTER		{			sh = new ScriptHandler( );			rtc.setScriptHandler( sh );			try			{				final String sScriptContent = cmRunTime.getScript( );				if ( externalContext != null						&& externalContext.getScriptable( ) != null )				{					sh.init( externalContext.getScriptable( ) );				}				else				{					sh.init( null );				}				sh.setRunTimeModel( cmRunTime );				if ( sScriptContent != null )				{					sh.register( sScriptContent );				}			}			catch ( ChartException sx )			{				throw new ChartException( ChartEnginePlugin.ID,						ChartException.GENERATION,						sx );			}		}		// SETUP THE COMPUTATIONS		ScriptHandler.callFunction( sh,				ScriptHandler.START_GENERATION,				cmRunTime );		ScriptHandler.callFunction( sh,				ScriptHandler.BEFORE_GENERATION,				cmRunTime,				rtc.getScriptContext( ) );		int iChartType = UNDEFINED;		Object oComputations = null;		if ( cmRunTime instanceof ChartWithAxes )		{			iChartType = WITH_AXES;			try			{				if ( cmRunTime.getDimension( ) == ChartDimension.THREE_DIMENSIONAL_LITERAL )				{					oComputations = new PlotWith3DAxes( ids,							(ChartWithAxes) cmRunTime,							rtc );				}				else				{					oComputations = new PlotWith2DAxes( ids,							(ChartWithAxes) cmRunTime,							rtc );				}			}			catch ( Exception e )			{				throw new ChartException( ChartEnginePlugin.ID,						ChartException.GENERATION,						e );			}		}		else if ( cmRunTime instanceof ChartWithoutAxes )		{			iChartType = WITHOUT_AXES;			oComputations = new PlotWithoutAxes( ids,					(ChartWithoutAxes) cmRunTime,					rtc );		}		if ( oComputations == null )		{			throw new ChartException( ChartEnginePlugin.ID,					ChartException.GENERATION,					"exception.unsupported.chart.model", //$NON-NLS-1$					new Object[]{						cmRunTime					},					ResourceBundle.getBundle( Messages.ENGINE, rtc.getLocale( ) ) );		}		// OBTAIN THE RENDERERS		final LinkedHashMap lhmRenderers = new LinkedHashMap( );		BaseRenderer[] brna = null;		try		{			brna = BaseRenderer.instances( cmRunTime, rtc, oComputations );			for ( int i = 0; i < brna.length; i++ )			{				lhmRenderers.put( brna[i].getSeries( ),						new LegendItemRenderingHints( brna[i],								BoundsImpl.create( 0, 0, 0, 0 ) ) );			}		}		catch ( Exception ex )		{			ex.printStackTrace( );			throw new ChartException( ChartEnginePlugin.ID,					ChartException.GENERATION,					ex );		}		// PERFORM THE BLOCKS' LAYOUT		Block bl = cmRunTime.getBlock( );		final LayoutManager lm = new LayoutManager( bl );		ScriptHandler.callFunction( sh, ScriptHandler.BEFORE_LAYOUT, cmRunTime );		try		{			lm.doLayout_tmp( ids, cmRunTime, bo, rtc );		}		catch ( ChartException oex )		{			throw new ChartException( ChartEnginePlugin.ID,					ChartException.GENERATION,					oex );		}		ScriptHandler.callFunction( sh, ScriptHandler.AFTER_LAYOUT, cmRunTime );		// COMPUTE THE PLOT AREA		Bounds boPlot = cmRunTime.getPlot( ).getBounds( );		Insets insPlot = cmRunTime.getPlot( ).getInsets( );		boPlot = boPlot.adjustedInstance( insPlot );		ScriptHandler.callFunction( sh,				ScriptHandler.BEFORE_COMPUTATIONS,				cmRunTime,				oComputations );		long lTimer = System.currentTimeMillis( );		if ( iChartType == WITH_AXES )		{			PlotWithAxes pwa = (PlotWithAxes) oComputations;			try			{				pwa.compute( boPlot );			}			catch ( Exception ex )			{				throw new ChartException( ChartEnginePlugin.ID,						ChartException.GENERATION,						ex );			}		}		else if ( iChartType == WITHOUT_AXES )		{			PlotWithoutAxes pwoa = (PlotWithoutAxes) oComputations;			try			{				pwoa.compute( boPlot );			}			catch ( Exception ex )			{				throw new ChartException( ChartEnginePlugin.ID,						ChartException.GENERATION,						ex );			}		}		ScriptHandler.callFunction( sh,				ScriptHandler.AFTER_COMPUTATIONS,				cmRunTime,				oComputations );		final Collection co = lhmRenderers.values( );		final LegendItemRenderingHints[] lirha = (LegendItemRenderingHints[]) co.toArray( EMPTY_LIRHA );		final int iSize = lhmRenderers.size( );		BaseRenderer br;		for ( int i = 0; i < iSize; i++ )		{			br = lirha[i].getRenderer( );			br.set( brna );			br.set( ids );			br.set( rtc );			try			{				if ( br.getComputations( ) instanceof PlotWithoutAxes )				{					br.set( ( (PlotWithoutAxes) br.getComputations( ) ).getSeriesRenderingHints( br.getSeries( ) ) );				}				else				{					br.set( ( (PlotWithAxes) br.getComputations( ) ).getSeriesRenderingHints( br.getSeriesDefinition( ),							br.getSeries( ) ) );				}				ScriptHandler.callFunction( sh,						ScriptHandler.START_COMPUTE_SERIES,						br.getSeries( ) );				br.compute( bo,						cmRunTime.getPlot( ),						br.getSeriesRenderingHints( ) );				ScriptHandler.callFunction( sh,						ScriptHandler.FINISH_COMPUTE_SERIES,						br.getSeries( ) );			}			catch ( Exception ex )			{				throw new ChartException( ChartEnginePlugin.ID,						ChartException.GENERATION,						ex );			}		}		logger.log( ILogger.INFORMATION,				Messages.getString( "info.compute.elapsed.time.without.axes", //$NON-NLS-1$						new Object[]{							new Long( System.currentTimeMillis( ) - lTimer )						}, rtc.getLocale( ) ) );		final GeneratedChartState gcs = new GeneratedChartState( ids,				cmRunTime,				lhmRenderers,				rtc,				oComputations );		if ( sh != null )		{			sh.setGeneratedChartState( gcs );			ScriptHandler.callFunction( sh,					ScriptHandler.FINISH_GENERATION,					gcs );			ScriptHandler.callFunction( sh,					ScriptHandler.AFTER_GENERATION,					gcs,					rtc.getScriptContext( ) );		}		return gcs;	}