# Class Compiler

java.lang.Object
org.apache.jasper.compiler.Compiler

Direct Known Subclasses:
  `AntCompiler, JavaCompiler, JDTCompiler`

public abstract class Compiler extends Object
Main JSP compiler class. This class uses Ant for compiling.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected JspCompilationContext`
`ctxt`
The JSP compilation context.
`protected ErrorDispatcher`
`errDispatcher`
The error dispatcher.
`protected JspServletWrapper`
`jsw`
The JSP servlet wrapper.
`protected Options`
`options`
The compilation options.
`protected PageInfo`
`pageInfo`
The page information.
`protected Node.Nodes`
`pageNodes`
The page nodes.
`protected TagFileProcessor`
`tfp`
The tag file processor.

## Constructor Summary

Constructors
Constructor
Description
`Compiler()`
Default constructor for Compiler.

## Method Summary

Modifier and Type
Method
Description
`void`
`compile()`
Compile the jsp file from the current engine context.
`void`
`compile(boolean compileClass)`
Compile the jsp file from the current engine context.
`void`
`compile(boolean compileClass, boolean jspcMode)`
Compile the jsp file from the current engine context.
`protected abstract void`
`generateClass(Map<String, SmapStratum> smaps)`
Servlet compilation.
`protected Map<String, SmapStratum>`
`generateJava()`
Compile the jsp file into equivalent servlet in .java file
`JspCompilationContext`
`getCompilationContext()`
Returns the JSP compilation context.
`ErrorDispatcher`
`getErrorDispatcher()`
Returns the error dispatcher.
`PageInfo`
`getPageInfo()`
Returns the page information.
`SmapStratum`
`getSmap(String className)`
Returns the source map for the specified class.
`void`
`init(JspCompilationContext ctxt, JspServletWrapper jsw)`
Initializes the compiler with the given compilation context and servlet wrapper.
`boolean`
`isOutDated()`
This is a protected method intended to be overridden by subclasses of Compiler.
`boolean`
`isOutDated(boolean checkClass)`
Determine if a compilation is necessary by checking the time stamp of the JSP page with that of the corresponding .class or .java file.
`void`
`removeGeneratedClassFiles()`
Remove generated class files.
`void`
`removeGeneratedFiles()`
Remove generated files

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ctxt

protected JspCompilationContext ctxt
The JSP compilation context.

### errDispatcher

protected ErrorDispatcher errDispatcher
The error dispatcher.

### pageInfo

protected PageInfo pageInfo
The page information.

### jsw

protected JspServletWrapper jsw
The JSP servlet wrapper.

### tfp

protected TagFileProcessor tfp
The tag file processor.

### options

protected Options options
The compilation options.

### pageNodes

protected Node.Nodes pageNodes
The page nodes.

## Constructor Details

### Compiler

public Compiler()
Default constructor for Compiler.

## Method Details

### init

public void init(JspCompilationContext ctxt, JspServletWrapper jsw)
Initializes the compiler with the given compilation context and servlet wrapper.

Parameters:
  `ctxt` - the JSP compilation context
  `jsw` - the JSP servlet wrapper

### getSmap

public SmapStratum getSmap(String className)
Returns the source map for the specified class.

Parameters:
  `className` - the class name
Returns:
  the source map, or `null` if not available

### generateJava

protected Map<String, SmapStratum> generateJava() throws Exception
Compile the jsp file into equivalent servlet in .java file

Returns:
  A map of class names to JSR 045 source maps
Throws:
  `Exception` - Error generating Java source

### generateClass

protected abstract void generateClass(Map<String, SmapStratum> smaps) throws FileNotFoundException, JasperException, Exception
Servlet compilation. This compiles the generated sources into Servlets.

Parameters:
  `smaps` - The source maps for the class(es) generated from the source file
Throws:
  `FileNotFoundException` - Source files not found
  `JasperException` - Compilation error
  `Exception` - Some other error

### compile

public void compile() throws FileNotFoundException, JasperException, Exception
Compile the jsp file from the current engine context.

Throws:
  `FileNotFoundException` - Source files not found
  `JasperException` - Compilation error
  `Exception` - Some other error

### compile

public void compile(boolean compileClass) throws FileNotFoundException, JasperException, Exception
Compile the jsp file from the current engine context. As a side effect, tag files that are referenced by this page are also compiled.

Parameters:
  `compileClass` - If true, generate both .java and .class file If false, generate only .java file
Throws:
  `FileNotFoundException` - Source files not found
  `JasperException` - Compilation error
  `Exception` - Some other error

### compile

public void compile(boolean compileClass, boolean jspcMode) throws FileNotFoundException, JasperException, Exception
Compile the jsp file from the current engine context. As a side effect, tag files that are referenced by this page are also compiled.

Parameters:
  `compileClass` - If true, generate both .java and .class file If false, generate only .java file
  `jspcMode` - true if invoked from JspC, false otherwise
Throws:
  `FileNotFoundException` - Source files not found
  `JasperException` - Compilation error
  `Exception` - Some other error

### isOutDated

public boolean isOutDated()
This is a protected method intended to be overridden by subclasses of Compiler. This is used by the compile method to do all the compilation.

Returns:
  `true` if the source generation and compilation should occur

### isOutDated

public boolean isOutDated(boolean checkClass)
Determine if a compilation is necessary by checking the time stamp of the JSP page with that of the corresponding .class or .java file. If the page has dependencies, the check is also extended to its dependents, and so on. This method can be overridden by a subclasses of Compiler.

Parameters:
  `checkClass` - If true, check against .class file, if false, check against .java file.
Returns:
  `true` if the source generation and compilation should occur

### getErrorDispatcher

public ErrorDispatcher getErrorDispatcher()
Returns the error dispatcher.

Returns:
  the error dispatcher.

### getPageInfo

public PageInfo getPageInfo()
Returns the page information.

Returns:
  the info about the page under compilation

### getCompilationContext

public JspCompilationContext getCompilationContext()
Returns the JSP compilation context.

Returns:
  the compilation context

### removeGeneratedFiles

public void removeGeneratedFiles()
Remove generated files

### removeGeneratedClassFiles

public void removeGeneratedClassFiles()
Remove generated class files.