Methods Summary |
---|
public void | addWrapper(java.lang.String jspUri, org.apache.jasper.servlet.JspServletWrapper jsw)Add a new JspServletWrapper.
// ------------------------------------------------------ Public Methods
jsps.remove(jspUri);
jsps.put(jspUri,jsw);
|
public void | adjustBytecodeTime(java.lang.String name, long reference)
Long time = bytecodeBirthTimes.get(name);
if (time == null)
return;
if (time.longValue() < reference) {
bytecodeBirthTimes.put(name, Long.valueOf(reference));
}
|
private void | checkCompile()Method used by background thread to check the JSP dependencies
registered with this class for JSP's.
for (JspServletWrapper jsw: jsps.values()) {
if (jsw.isTagFile()) {
// Skip tag files in background compiliations, since modified
// tag files will be recompiled anyway when their client JSP
// pages are compiled. This also avoids problems when the
// tag files and their clients are not modified simultaneously.
continue;
}
JspCompilationContext ctxt = jsw.getJspEngineContext();
// JspServletWrapper also synchronizes on this when
// it detects it has to do a reload
synchronized(jsw) {
try {
ctxt.compile();
} catch (FileNotFoundException ex) {
ctxt.incrementRemoved();
} catch (Throwable t) {
jsw.getServletContext().log("Background compile failed",
t);
}
}
}
|
public void | destroy()Process a "destory" event for this web application context.
if(System.err instanceof SystemLogHandler)
System.setErr(((SystemLogHandler)System.err).getWrapped());
threadStop();
for (JspServletWrapper jsw: jsps.values()) {
jsw.destroy();
}
parentClassLoader = null;
|
public byte[] | getBytecode(java.lang.String name)Retrieve the bytecode associated with the class
return bytecodes.get(name);
|
public long | getBytecodeBirthTime(java.lang.String name)Retrieve the time the bytecode for a class was created
Long time = bytecodeBirthTimes.get(name);
return (time != null? time.longValue(): 0);
|
public java.util.Map | getBytecodes()Get the class-name to bytecode map
return bytecodes;
|
public java.lang.String | getClassPath()The classpath that is passed off to the Java compiler.
return classpath;
|
public java.security.CodeSource | getCodeSource()Get the SecurityManager Policy CodeSource for this web
applicaiton context.
return codeSource;
|
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.
return jsps.size();
|
public int | getJspReloadCount()Gets the current value of the JSP reload counter.
return jspReloadCount;
|
public java.util.Map | 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.
if (packageMap == null) {
packageMap = new HashMap<String, ArrayList<Object>>();
}
return packageMap;
|
public java.net.URLClassLoader | getParentClassLoader()Get the parent URLClassLoader.
return parentClassLoader;
|
public java.security.PermissionCollection | getPermissionCollection()Get the SecurityManager PermissionCollection for this
web application context.
return permissionCollection;
|
public org.apache.jasper.servlet.JspServletWrapper | getWrapper(java.lang.String jspUri)Get an already existing JspServletWrapper.
return jsps.get(jspUri);
|
public synchronized void | incrementJspReloadCount()Increments the JSP reload counter.
jspReloadCount++;
|
private void | initClassPath()Method used to initialize classpath for compiles.
URL [] urls = parentClassLoader.getURLs();
StringBuffer cpath = new StringBuffer();
String sep = System.getProperty("path.separator");
for(int i = 0; i < urls.length; i++) {
// Tomcat 4 can use URL's other than file URL's,
// a protocol other than file: will generate a
// bad file system path, so only add file:
// protocol URL's to the classpath.
if( urls[i].getProtocol().equals("file") ) {
cpath.append((String)urls[i].getFile()+sep);
}
}
cpath.append(options.getScratchDir() + sep);
String cp = (String) context.getAttribute(Constants.SERVLET_CLASSPATH);
if (cp == null || cp.equals("")) {
cp = options.getClassPath();
}
classpath = cpath.toString() + cp;
// START GlassFish Issue 845
try {
classpath = URLDecoder.decode(classpath, "UTF-8");
} catch (UnsupportedEncodingException e) {
if (log.isDebugEnabled())
log.debug("Exception decoding classpath : " + classpath, e);
}
// END GlassFish Issue 845
|
private void | initSecurity()Method used to initialize SecurityManager data.
// Setup the PermissionCollection for this web app context
// based on the permissions configured for the root of the
// web app context directory, then add a file read permission
// for that directory.
Policy policy = Policy.getPolicy();
if( policy != null ) {
try {
// Get the permissions for the web app context
String docBase = context.getRealPath("/");
if( docBase == null ) {
docBase = options.getScratchDir().toString();
}
String codeBase = docBase;
if (!codeBase.endsWith(File.separator)){
codeBase = codeBase + File.separator;
}
File contextDir = new File(codeBase);
URL url = contextDir.getCanonicalFile().toURL();
codeSource = new CodeSource(url,(Certificate[])null);
permissionCollection = policy.getPermissions(codeSource);
// Create a file read permission for web app context directory
if (!docBase.endsWith(File.separator)){
permissionCollection.add
(new FilePermission(docBase,"read"));
docBase = docBase + File.separator;
} else {
permissionCollection.add
(new FilePermission
(docBase.substring(0,docBase.length() - 1),"read"));
}
docBase = docBase + "-";
permissionCollection.add(new FilePermission(docBase,"read"));
// Create a file read permission for web app tempdir (work)
// directory
String workDir = options.getScratchDir().toString();
if (!workDir.endsWith(File.separator)){
permissionCollection.add
(new FilePermission(workDir,"read"));
workDir = workDir + File.separator;
}
workDir = workDir + "-";
permissionCollection.add(new FilePermission(workDir,"read"));
// Allow the JSP to access org.apache.jasper.runtime.HttpJspBase
permissionCollection.add( new RuntimePermission(
"accessClassInPackage.org.apache.jasper.runtime") );
if (parentClassLoader instanceof URLClassLoader) {
URL [] urls = parentClassLoader.getURLs();
String jarUrl = null;
String jndiUrl = null;
for (int i=0; i<urls.length; i++) {
if (jndiUrl == null
&& urls[i].toString().startsWith("jndi:") ) {
jndiUrl = urls[i].toString() + "-";
}
if (jarUrl == null
&& urls[i].toString().startsWith("jar:jndi:")
) {
jarUrl = urls[i].toString();
jarUrl = jarUrl.substring(0,jarUrl.length() - 2);
jarUrl = jarUrl.substring(0,
jarUrl.lastIndexOf('/")) + "/-";
}
}
if (jarUrl != null) {
permissionCollection.add(
new FilePermission(jarUrl,"read"));
permissionCollection.add(
new FilePermission(jarUrl.substring(4),"read"));
}
if (jndiUrl != null)
permissionCollection.add(
new FilePermission(jndiUrl,"read") );
}
} catch(Exception e) {
context.log("Security Init for context failed",e);
}
}
|
public void | removeWrapper(java.lang.String jspUri)Remove a JspServletWrapper.
jsps.remove(jspUri);
|
public void | run()The background thread that checks for changes to files
included by a JSP and flags that a recompile is required.
// Loop until the termination semaphore is set
while (!threadDone) {
// Wait for our check interval
threadSleep();
// Check for included files which are newer than the
// JSP which uses them.
try {
checkCompile();
} catch (Throwable t) {
t.printStackTrace();
}
}
|
public void | saveBytecode(java.lang.String className, java.lang.String classFileName)Save the bytecode for a class to disk.
byte[] bytecode = getBytecode(className);
if (bytecode != null) {
try {
FileOutputStream fos = new FileOutputStream(classFileName);
fos.write(bytecode);
fos.close();
} catch (IOException ex) {
context.log("Error in saving bytecode for " + className +
" to " + classFileName, ex);
}
}
|
public void | setBytecode(java.lang.String name, byte[] bytecode)Save the bytecode for the class in a map. The current time is noted.
if (bytecode == null) {
bytecodes.remove(name);
bytecodeBirthTimes.remove(name);
return;
}
bytecodes.put(name, bytecode);
bytecodeBirthTimes.put(name, Long.valueOf(System.currentTimeMillis()));
|
public synchronized void | setJspReloadCount(int count)Resets the JSP reload counter.
this.jspReloadCount = count;
|
protected void | threadSleep()Sleep for the duration specified by the checkInterval
property.
try {
Thread.sleep(options.getCheckInterval() * 1000L);
} catch (InterruptedException e) {
;
}
|
protected void | threadStart()Start the background thread that will periodically check for
changes to compile time included files in a JSP.
// Has the background thread already been started?
if (thread != null) {
return;
}
// Start the background thread
threadDone = false;
thread = new Thread(this, threadName);
thread.setDaemon(true);
thread.start();
|
protected void | threadStop()Stop the background thread that is periodically checking for
changes to compile time included files in a JSP.
if (thread == null) {
return;
}
threadDone = true;
thread.interrupt();
try {
thread.join();
} catch (InterruptedException e) {
;
}
thread = null;
|