Class CodeBlockImpl

java.lang.Object
de.spraener.nxtgen.CodeBlockImpl
All Implemented Interfaces:
CodeBlock
Direct Known Subclasses:
BlueprintCodeBlock, CodeTargetCodeBlockAdapter, GroovyCodeBlockImpl, JavaCodeBlock

public class CodeBlockImpl extends Object implements CodeBlock
A base implementation of a CodeBlock. Most real CodeBlocks do extend this class.
  • Constructor Details

    • CodeBlockImpl

      public CodeBlockImpl(String name)
      Create a new CodeBlock with the given name.
      Parameters:
      name - a name of the codeblock for reference purpose.
  • Method Details

    • toCode

      public String toCode()
      Write your and the code of all contained codeBlocks to an output string. The implementation calls toCode on all containing CodeBlocks and append them to one long output string.
      Specified by:
      toCode in interface CodeBlock
      Returns:
      a string with the output of all contained CodeBlocks.
    • println

      public void println(String txt)
      Adds the given String to a new SimpleStringCodeBlock and adds them to the contained CodeBlocks.
      Specified by:
      println in interface CodeBlock
      Parameters:
      txt - Some text to print into the codeblock
      See Also:
    • addCodeBlock

      public void addCodeBlock(CodeBlock subBlock)
      Adds onother CodeBlock to the list of conained CodeBlocks.
      Specified by:
      addCodeBlock in interface CodeBlock
      Parameters:
      subBlock - a code block can contain other codeblocks. it is inserted at the current postion/line
    • getName

      public String getName()
      returns the Name of this CodeBlock. The CodeBlock can be referenced by this name.
      Specified by:
      getName in interface CodeBlock
      Returns:
      the name
    • checkProtected

      protected boolean checkProtected(File outFile)

      Checks if the considered outputFile is maybe protected from overwriting. This does not mean that the file is write protected on file system level. It just decides (some how) that the considered file should no be overwritten.

      This implementation delegeates the decision to a changeable ProtectionStrategy.

      Parameters:
      outFile -
      Returns:
      See Also:
    • writeOutput

      public void writeOutput(String workingDir)
      Do the output wrtiing into the given working directory. The output file is determined with an changeable ToFileStrategy.
      Specified by:
      writeOutput in interface CodeBlock
      Parameters:
      workingDir - the full qualified path to the working directory.
      See Also:
    • getToFileStrategy

      public ToFileStrategy getToFileStrategy()
    • setToFileStrategy

      public void setToFileStrategy(ToFileStrategy toFileStrategy)
      Specified by:
      setToFileStrategy in interface CodeBlock