org.eclipse.mtl.engine.evaluation
Class MTLEvaluationContext

java.lang.Object
  extended by org.eclipse.mtl.engine.evaluation.MTLEvaluationContext

public final class MTLEvaluationContext
extends java.lang.Object

This will hold all necessary variables for the evaluation of an MTL module.


Constructor Summary
MTLEvaluationContext(java.io.File root, java.util.List<MTLTextGenerationListener> listeners)
          Instantiates an evaluation context given the root of the to-be-generated files.
 
Method Summary
 void append(java.lang.String string)
          Appends the given string to the last buffer of the context stack.
 java.lang.String closeContext()
          Closes the last writer of the stack and returns its result if it was a StringWriter.
 void dispose()
          This will be used to dispose of all created buffers.
 java.util.Map<java.lang.String,java.lang.Object> getLastVariablesValues()
          This will return the last variables that were added to the stack so that they can be restored in the evaluation environment.
 java.lang.String getProtectedAreaContent(java.lang.String marker)
          This will return the content of the protected area associated with the given marker in the current context.
 void openNested()
          Creates a new writer and appends it to the end of the stack.
 void openNested(java.io.OutputStream stream)
          Create a new writer directed at the given OutputStream.
 void openNested(java.lang.String filePath, boolean appendMode)
          Create a new writer for the file located at the given path under generationRoot and appends it to the end of the stack.
 void saveVariableValues(java.util.Map<java.lang.String,java.lang.Object> vars)
          This will save the given variables in the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MTLEvaluationContext

public MTLEvaluationContext(java.io.File root,
                            java.util.List<MTLTextGenerationListener> listeners)
Instantiates an evaluation context given the root of the to-be-generated files.

Parameters:
root - Root of all files that will be generated.
listeners - The list of all listeners that are to be notified for text generation from this context.
Method Detail

append

public void append(java.lang.String string)
            throws MTLEvaluationException
Appends the given string to the last buffer of the context stack.

Parameters:
string - String that is to be appended to the current buffer.
Throws:
MTLEvaluationException - Thrown if we cannot append to the current buffer.

closeContext

public java.lang.String closeContext()
                              throws MTLEvaluationException
Closes the last writer of the stack and returns its result if it was a StringWriter. The empty String will be returned for FileWriters.

Returns:
Result held by the last writer of the stack.
Throws:
MTLEvaluationException - This will be thrown if the last writer of the stack cannot be flushed and closed.

dispose

public void dispose()
             throws MTLEvaluationException
This will be used to dispose of all created buffers.

Throws:
MTLEvaluationException - Thrown if the disposal of the old writers fails.

getLastVariablesValues

public java.util.Map<java.lang.String,java.lang.Object> getLastVariablesValues()
This will return the last variables that were added to the stack so that they can be restored in the evaluation environment. Note that calling this method removes the returned variables from the stack.

Returns:
The variables that were last saved.

getProtectedAreaContent

public java.lang.String getProtectedAreaContent(java.lang.String marker)
This will return the content of the protected area associated with the given marker in the current context.

Parameters:
marker - Marker of the sought protected area content.
Returns:
Content of the protected area associated with the given marker. null if no content can be found.

openNested

public void openNested()
                throws MTLEvaluationException
Creates a new writer and appends it to the end of the stack.

Throws:
MTLEvaluationException - Thrown if the precedent buffer cannot be flushed.

openNested

public void openNested(java.io.OutputStream stream)
Create a new writer directed at the given OutputStream. This is mainly used for fileBlocks with "stdout" URI.

Parameters:
stream - Stream to which writing will be directed.

openNested

public void openNested(java.lang.String filePath,
                       boolean appendMode)
                throws MTLEvaluationException
Create a new writer for the file located at the given path under generationRoot and appends it to the end of the stack.

"file" schemes are handled as absolute paths and will ignore the generationRoot.

Parameters:
filePath - Path of the file around which we need a FileWriter. The file will be created under the generationRoot if needed.
appendMode - If false, the file will be replaced by a new one.
Throws:
MTLEvaluationException - Thrown if the file cannot be created.

saveVariableValues

public void saveVariableValues(java.util.Map<java.lang.String,java.lang.Object> vars)
This will save the given variables in the stack.

Parameters:
vars - Variables which values will need to be restored after evaluation.

Copyright 2008 Obeo
All Rights Reserved.