pier 2004/05/06 01:43:18
Modified: src/kernel/org/apache/cocoon/kernel BlockLoader.java
DeployedWirings.java KernelDeployer.java
ProxyWire.java
src/kernel/org/apache/cocoon/kernel/composition
WiringException.java
src/kernel/org/apache/cocoon/kernel/identification
BlockDescriptor.java
src/kernel/org/apache/cocoon/kernel/startup
AbstractLogger.java KernelServlet.java
ServletWrapper.java
Log:
Added initial support for a "compilation" class path usable by blocks.
WiringException now extends "runtime exception".
ProxyWire handling of exceptions in invoked methods.
AbstractLogger handles ServletExceptions.
Revision Changes Path
1.5 +26 -2
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/BlockLoader.java
Index: BlockLoader.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/BlockLoader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BlockLoader.java 3 May 2004 20:45:50 -0000 1.4
+++ BlockLoader.java 6 May 2004 08:43:17 -0000 1.5
@@ -15,6 +15,8 @@
*/
package org.apache.cocoon.kernel;
+import java.io.File;
+import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
@@ -179,6 +181,28 @@
/* Remove circular dependancies checking and return the block */
this.creating.remove(descriptor);
return(block);
+ }
+
+ /**
+ * <p>Return the compilation class path configured from all deployed
+ * blocks and localized for the current operating system.</p>
+ *
+ * @return a <b>non null</b> [EMAIL PROTECTED] String}.
+ */
+ protected String getCompilationClassPath() {
+ URL urls[] = this.loader.getURLs();
+ StringBuffer buffer = new StringBuffer();
+ for (int x = 0; x < urls.length; x++) {
+ if ("file".equals(urls[x].getProtocol())) try {
+ String path = new File(urls[x].getPath()).getCanonicalPath();
+ buffer.append(System.getProperty("path.separator"));
+ buffer.append(path);
+ } catch (IOException exception) {
+ /* TODO: log this exception? */
+ }
+ }
+ if (buffer.length() > 0) buffer.deleteCharAt(0);
+ return(buffer.toString());
}
/*
====================================================================== */
1.7 +7 -4
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/DeployedWirings.java
Index: DeployedWirings.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/DeployedWirings.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DeployedWirings.java 4 May 2004 17:49:46 -0000 1.6
+++ DeployedWirings.java 6 May 2004 08:43:17 -0000 1.7
@@ -84,7 +84,7 @@
ClassLoader loader = block.loader(Descriptor.ACCESS_PRIVATE);
/* Attempt to find and create a composer instance */
- try {
+ if ((composer != null) || (component != null)) try {
/* If the composer was specified, we load the class */
Class clazz = SimpleComposer.class;
if (composer != null) clazz = loader.loadClass(composer);
@@ -157,6 +157,9 @@
*/
protected Wire newWire(Class role, Resolver resolver)
throws WiringException {
+ if (this.composer == null) {
+ throw new WiringException("Block does not provide components");
+ }
return(new ProxyWire(this.composer, role, this, resolver).getWire());
}
@@ -227,9 +230,9 @@
*/
public void init()
throws LifecycleException {
- try {
- this.composer.configure(this.instance.configuration());
+ if (this.composer != null) try {
this.composer.contextualize(this); // TODO wrap this instance
+ this.composer.configure(this.instance.configuration());
} catch (Throwable throwable) {
throw new LifecycleException("Unable to configure or
contextualize"
+ " composer instance", throwable);
1.8 +17 -1
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/KernelDeployer.java
Index: KernelDeployer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/KernelDeployer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- KernelDeployer.java 3 May 2004 20:45:50 -0000 1.7
+++ KernelDeployer.java 6 May 2004 08:43:18 -0000 1.8
@@ -345,4 +345,20 @@
protected DeployedWirings lookup(String name) {
return((DeployedWirings)this.wiringsByName.get(name));
}
+
+ /**
+ * <p>Return the compilation class path configured from all deployed
+ * blocks and localized for the current operating system.</p>
+ *
+ * @return a <b>non null</b> [EMAIL PROTECTED] String}.
+ */
+ public String getCompilationClassPath() {
+ try {
+ return(((BlockLoader)this.loader).getCompilationClassPath());
+ } catch (Throwable t) {
+ return("");
+ }
+ }
+
+
}
1.7 +5 -2
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/ProxyWire.java
Index: ProxyWire.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/ProxyWire.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ProxyWire.java 4 May 2004 17:47:08 -0000 1.6
+++ ProxyWire.java 6 May 2004 08:43:18 -0000 1.7
@@ -16,6 +16,7 @@
package org.apache.cocoon.kernel;
import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -211,8 +212,10 @@
if (this.check(method, wired)) return(new
Boolean(this.isConnected()));
/* Invoke the method on the remote instance */
- if (this.instance != null) {
+ if (this.instance != null) try {
return(method.invoke(this.instance, arguments));
+ } catch (InvocationTargetException exception) {
+ throw exception.getCause();
}
/* Have we been released? */
1.4 +2 -2
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/composition/WiringException.java
Index: WiringException.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/composition/WiringException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WiringException.java 31 Mar 2004 13:01:38 -0000 1.3
+++ WiringException.java 6 May 2004 08:43:18 -0000 1.4
@@ -22,7 +22,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
* @version 1.0 (CVS $Revision$)
*/
-public class WiringException extends Exception {
+public class WiringException extends RuntimeException {
/**
* <p>Create a new [EMAIL PROTECTED] WiringException} instance.</p>
*/
1.6 +3 -3
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/identification/BlockDescriptor.java
Index: BlockDescriptor.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/identification/BlockDescriptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BlockDescriptor.java 3 May 2004 20:40:45 -0000 1.5
+++ BlockDescriptor.java 6 May 2004 08:43:18 -0000 1.6
@@ -73,11 +73,11 @@
current = configuration.child(NAMESPACE, "provides");
this.provision = current.getStringAttribute("class", null);
this.composer = current.getStringAttribute("composer", null);
- if ((this.provision == null) && (this.composer == null)) {
+ /*if ((this.provision == null) && (this.composer == null)) {
throw new ConfigurationException("Descriptor does not provide "
+ "composer or component class "
+ "name", configuration);
- }
+ }*/
}
/*
====================================================================== */
1.7 +18 -11
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/AbstractLogger.java
Index: AbstractLogger.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/AbstractLogger.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractLogger.java 4 May 2004 17:38:53 -0000 1.6
+++ AbstractLogger.java 6 May 2004 08:43:18 -0000 1.7
@@ -18,6 +18,9 @@
import java.text.SimpleDateFormat;
import java.util.Date;
+import javax.servlet.ServletException;
+import javax.xml.transform.TransformerException;
+
import org.xml.sax.SAXException;
/**
@@ -256,8 +259,10 @@
Throwable causedby = null;
if (throwable instanceof SAXException) {
causedby = ((SAXException)throwable).getException();
+ } else if (throwable instanceof ServletException) {
+ causedby = ((ServletException)throwable).getRootCause();
} else causedby = throwable.getCause();
-
+
/* Print the logging header and an explaination */
buffer.append(header);
buffer.append(cause ? "+ Caused by " : "Exception ");
@@ -268,17 +273,19 @@
/* Print the Throwable message */
String message = throwable.getMessage();
- if (message != null) {
- /* Print the header for the message */
- buffer.append(header);
+ if (throwable instanceof TransformerException) {
+ message =
((TransformerException)throwable).getMessageAndLocation();
+ }
+ if (message == null) message = "[Null Exception Message!]";
+ /* Print the header for the message */
+ buffer.append(header);
- /* Widgeting, many checks, one buffer append call */
- if (!cause) buffer.append("+--- ");
- else buffer.append(causedby == null ? " +--- " : "| +--- ");
+ /* Widgeting, many checks, one buffer append call */
+ if (!cause) buffer.append("+--- ");
+ else buffer.append(causedby == null ? " +--- " : "| +--- ");
- /* Print out the message */
- buffer = this.out(buffer.append(message));
- }
+ /* Print out the message */
+ buffer = this.out(buffer.append(message));
/* Analyze every single stack trace element */
StackTraceElement trace[] = throwable.getStackTrace();
1.2 +9 -5
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/KernelServlet.java
Index: KernelServlet.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/KernelServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KernelServlet.java 4 May 2004 17:38:53 -0000 1.1
+++ KernelServlet.java 6 May 2004 08:43:18 -0000 1.2
@@ -45,6 +45,7 @@
private Logger logger = null;
private Wirings wirings = null;
private ServletConfig config = null;
+ private KernelDeployer deployer = null;
public synchronized void init(ServletConfig config)
throws ServletException {
@@ -106,20 +107,23 @@
Configuration conf = null;
/* Now let's create our core deployer */
- KernelDeployer deployer = new KernelDeployer();
- deployer.logger(logger);
+ this.deployer = new KernelDeployer();
+ this.deployer.logger(logger);
conf = ConfigurationBuilder.parse(deplurl);
- deployer.configure(conf);
+ this.deployer.configure(conf);
/* Instantiate an installer and process deployment */
- Installer installer = new Installer(deployer);
+ Installer installer = new Installer(this.deployer);
conf = ConfigurationBuilder.parse(insturl);
installer.process(conf);
/* Store the current kernel configuration */
this.config = config;
- this.wirings = new CoreWirings(deployer);
+ this.wirings = new CoreWirings(this.deployer);
KernelServlet.instance = this;
+ /* TODO: this doesn't get updated upon blocks changes */
+ ctxt.setAttribute("org.apache.cocoon.kernel.class.path",
+ deployer.getCompilationClassPath());
} catch (Throwable throwable) {
String message = "An error occurred initializing the kernel";
1.2 +24 -12
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/ServletWrapper.java
Index: ServletWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/ServletWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletWrapper.java 4 May 2004 17:38:53 -0000 1.1
+++ ServletWrapper.java 6 May 2004 08:43:18 -0000 1.2
@@ -24,7 +24,6 @@
import javax.servlet.ServletResponse;
import org.apache.cocoon.kernel.composition.Wire;
-import org.apache.cocoon.kernel.composition.Wirings;
/**
@@ -35,9 +34,8 @@
*/
public class ServletWrapper implements Servlet {
+ private KernelServlet kernel = null;
private Servlet servlet = null;
- private Wirings wirings = null;
- private Logger logger = null;
private boolean expose = false;
public void init(ServletConfig config)
@@ -54,21 +52,19 @@
this.expose = "true".equalsIgnoreCase(expose);
/* Get a hold on the kernel servlet, its wirings and logger */
- KernelServlet instance = KernelServlet.instance;
- if (instance == null) {
+ this.kernel = KernelServlet.instance;
+ if (this.kernel == null) {
throw new ServletException("Framework not initialized");
}
- this.wirings = instance.getWirings();
- this.logger = instance.getLogger();
/* Get a hold on the wrapped servlet and initialize it */
try {
- this.servlet = (Servlet) this.wirings.lookup(Servlet.class,
inst);
+ this.servlet = (Servlet)
this.kernel.getWirings().lookup(Servlet.class, inst);
this.servlet.init(config);
} catch (ServletException e) {
throw (e);
} catch (Throwable t) {
- this.logger.fatal("Unable to access wrapped servlet", t);
+ this.kernel.getLogger().fatal("Unable to access wrapped
servlet", t);
throw new ServletException("Unable to access wrapped servlet");
}
}
@@ -81,9 +77,25 @@
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
if (this.expose) {
- request.setAttribute("org.apache.cocoon.kernel.wirings",
wirings);
+ request.setAttribute("org.apache.cocoon.kernel.wirings.global",
+ this.kernel.getWirings());
+ }
+
+ try {
+ this.servlet.service(request, response);
+ } catch (ServletException exception) {
+ this.kernel.getLogger().error("Exception serviceing page",
exception);
+ throw(exception);
+ } catch (java.io.IOException exception) {
+ this.kernel.getLogger().error("Exception serviceing page",
exception);
+ throw(exception);
+ } catch (RuntimeException exception) {
+ this.kernel.getLogger().error("Exception serviceing page",
exception);
+ throw(exception);
+ } catch (Throwable throwable) {
+ this.kernel.getLogger().error("Exception serviceing page",
throwable);
+ throw(new ServletException("Whoha bessie"));
}
- this.servlet.service(request, response);
}
public ServletConfig getServletConfig() {