## org.apache.jasper.compiler
Class JspRuntimeContext

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

All Implemented Interfaces:
  Runnable

    public final class JspRuntimeContext

extends Object
implements Runnable

Class for tracking JSP compile time file dependencies when the &060;%@include file="..."%&062; directive is used. A background thread periodically checks the files a JSP page is dependent upon. If a dpendent file changes the JSP page which included it is recompiled. Only used if a web application context is a directory.

Version:
  $Revision: 1.14 $
Author:
  Glenn L. Nielsen

Constructor Summary
`JspRuntimeContext(ServletContext context, Options options)` Create a JspRuntimeContext for a web application context.

Method Summary
`void` `addWrapper(String jspUri, JspServletWrapper jsw)` Add a new JspServletWrapper.
`void` `adjustBytecodeTime(String name, long reference)`
`void` `destroy()` Process a "destory" event for this web application context.
`byte[]` `getBytecode(String name)` Retrieve the bytecode associated with the class
`long` `getBytecodeBirthTime(String name)` Retrieve the time the bytecode for a class was created
`Map<String,byte[]>` `getBytecodes()` Get the class-name to bytecode map
`String` `getClassPath()` The classpath that is passed off to the Java compiler.
`CodeSource` `getCodeSource()` Get the SecurityManager Policy CodeSource for this web applicaiton context.
`int` `getJspCount()` Returns the number of JSPs for which JspServletWrappers exist, i.e., the number of JSPs that have been loaded into the webapp.
`int` `getJspReloadCount()` Gets the current value of the JSP reload counter.
`Map<String,ArrayList<Object>>` `getPackageMap()` The packageMap keeps track of the bytecode files in a package generated by a java compiler.
`URLClassLoader` `getParentClassLoader()` Get the parent URLClassLoader.
`PermissionCollection` `getPermissionCollection()` Get the SecurityManager PermissionCollection for this web application context.
`JspServletWrapper` `getWrapper(String jspUri)` Get an already existing JspServletWrapper.
`void` `incrementJspReloadCount()` Increments the JSP reload counter.
`void` `removeWrapper(String jspUri)` Remove a JspServletWrapper.
`void` `run()` The background thread that checks for changes to files included by a JSP and flags that a recompile is required.
`void` `saveBytecode(String className, String classFileName)` Save the bytecode for a class to disk.
`void` `setBytecode(String name, byte[] bytecode)` Save the bytecode for the class in a map.
`void` `setJspReloadCount(int count)` Resets the JSP reload counter.
`protected void` `threadSleep()` Sleep for the duration specified by the `checkInterval` property.
`protected void` `threadStart()` Start the background thread that will periodically check for changes to compile time included files in a JSP.
`protected void` `threadStop()` Stop the background thread that is periodically checking for changes to compile time included files in a JSP.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JspRuntimeContext

    public JspRuntimeContext(ServletContext context,
                             Options options)

  Create a JspRuntimeContext for a web application context. Loads in any previously generated dependencies from file.

  Parameters:
    `context` - ServletContext for web application

Method Detail

### addWrapper

    public void addWrapper(String jspUri,
                           JspServletWrapper jsw)

  Add a new JspServletWrapper.

  Parameters:
    `jspUri` - JSP URI
    `jsw` - Servlet wrapper for JSP

### getWrapper

    public JspServletWrapper getWrapper(String jspUri)

  Get an already existing JspServletWrapper.

  Parameters:
    `jspUri` - JSP URI
  Returns:
    JspServletWrapper for JSP

### removeWrapper

    public void removeWrapper(String jspUri)

  Remove a JspServletWrapper.

  Parameters:
    `jspUri` - JSP URI of JspServletWrapper to remove

### getJspCount

    public int getJspCount()

  Returns the number of JSPs for which JspServletWrappers exist, i.e., the number of JSPs that have been loaded into the webapp.

  Returns:
    The number of JSPs that have been loaded into the webapp

### getCodeSource

    public CodeSource getCodeSource()

  Get the SecurityManager Policy CodeSource for this web applicaiton context.

  Returns:
    CodeSource for JSP

### getParentClassLoader

    public URLClassLoader getParentClassLoader()

  Get the parent URLClassLoader.

  Returns:
    URLClassLoader parent

### getPermissionCollection

    public PermissionCollection getPermissionCollection()

  Get the SecurityManager PermissionCollection for this web application context.

  Returns:
    PermissionCollection permissions

### destroy

    public void destroy()

  Process a "destory" event for this web application context.

### incrementJspReloadCount

    public void incrementJspReloadCount()

  Increments the JSP reload counter.

### setJspReloadCount

    public void setJspReloadCount(int count)

  Resets the JSP reload counter.

  Parameters:
    `count` - Value to which to reset the JSP reload counter

### getJspReloadCount

    public int getJspReloadCount()

  Gets the current value of the JSP reload counter.

  Returns:
    The current value of the JSP reload counter

### setBytecode

    public void setBytecode(String name,
                            byte[] bytecode)

  Save the bytecode for the class in a map. The current time is noted.

  Parameters:
    `name` - The name of the class
    `bytecode` - The bytecode in byte array

### adjustBytecodeTime

    public void adjustBytecodeTime(String name,
                                   long reference)

### getBytecodes

    public Map<String,byte[]> getBytecodes()

  Get the class-name to bytecode map

### getBytecode

    public byte[] getBytecode(String name)

  Retrieve the bytecode associated with the class

### getBytecodeBirthTime

    public long getBytecodeBirthTime(String name)

  Retrieve the time the bytecode for a class was created

### getPackageMap

    public Map<String,ArrayList<Object>> getPackageMap()

  The packageMap keeps track of the bytecode files in a package generated by a java compiler. This is in turn loaded by the java compiler during compilation. This is gets around the fact that JSR199 API does not provide a way for the compiler use current classloader.

### saveBytecode

    public void saveBytecode(String className,
                             String classFileName)

  Save the bytecode for a class to disk.

### getClassPath

    public String getClassPath()

  The classpath that is passed off to the Java compiler.

### threadStart

    protected void threadStart()

  Start the background thread that will periodically check for changes to compile time included files in a JSP.

  Throws:
    `IllegalStateException` - if we should not be starting a background thread now

### threadStop

    protected void threadStop()

  Stop the background thread that is periodically checking for changes to compile time included files in a JSP.

### threadSleep

    protected void threadSleep()

  Sleep for the duration specified by the `checkInterval` property.

### run

    public void run()

  The background thread that checks for changes to files included by a JSP and flags that a recompile is required.

  Specified by:
    `run` in interface `Runnable`

Copyright © 2008 Mort Bay Consulting. All Rights Reserved.