You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by cr...@apache.org on 2006/05/26 08:47:49 UTC
svn commit: r409568 - in
/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces:
ExceptionHandler.java ExceptionHandlerFactory.java ExceptionHandlerImpl.java
Author: craigmcc
Date: Thu May 25 23:47:48 2006
New Revision: 409568
URL: http://svn.apache.org/viewvc?rev=409568&view=rev
Log:
Add new classes for the previous SHALE-125 related commit.
Added:
struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java (with props)
struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java (with props)
struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java (with props)
Added: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java?rev=409568&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java (added)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java Thu May 25 23:47:48 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+package org.apache.shale.view.faces;
+
+/**
+ * <p>Interface describing a "strategy pattern" implementation for
+ * handling exceptions thrown by an application event callback that
+ * is managed by Shale. A suitable instance may be acquired by calling
+ * <code>ExceptionHandlerFactory.getInstance().getExceptionHandler().</p>
+ *
+ * @since 1.0.3
+ */
+public interface ExceptionHandler {
+
+
+ /**
+ * <p>Handle the specified exception thrown by an application
+ * event handler.</p>
+ *
+ * @param exception Exception that was thrown
+ */
+ public void handleException(Exception exception);
+
+
+}
Propchange: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java?rev=409568&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java (added)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java Thu May 25 23:47:48 2006
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+package org.apache.shale.view.faces;
+
+import javax.faces.FacesException;
+
+/**
+ * <p>Factory for exception handler instances.</p>
+ *
+ * @since 1.0.3
+ */
+public class ExceptionHandlerFactory {
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ /**
+ * <p>Private constructor to prevent arbitrary object creation.</p>
+ */
+ private ExceptionHandlerFactory() {
+ }
+
+
+ // ---------------------------------------------------------- Static Methods
+
+
+ /**
+ * <p>Return a suitable instance of this factory.</p>
+ */
+ public static ExceptionHandlerFactory getInstance() {
+ return new ExceptionHandlerFactory();
+ }
+
+
+ // ---------------------------------------------------------- Public Methods
+
+
+ /**
+ * <p>Return a suitable implementation of {@link ExceptionHandler}.</p>
+ */
+ public ExceptionHandler getExceptionHandler() {
+
+ ClassLoader cl = getApplicationClassLoader();
+ Class clazz = null;
+ try {
+ clazz = cl.loadClass("org.apache.shale.view.faces.ExceptionHandlerImpl");
+ return (ExceptionHandler) clazz.newInstance();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ }
+
+
+ // --------------------------------------------------------- Private Methods
+
+
+ /**
+ * <p>Return the class loader to use for loading application classes.</p>
+ */
+ private ClassLoader getApplicationClassLoader() {
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ cl = this.getClass().getClassLoader();
+ }
+ return cl;
+
+ }
+
+
+}
Propchange: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java?rev=409568&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java (added)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java Thu May 25 23:47:48 2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+package org.apache.shale.view.faces;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.faces.context.FacesContext;
+import org.apache.shale.view.Constants;
+
+/**
+ * <p>Default implementation of the {@link ExceptionHandler} interface.</p>
+ */
+public class ExceptionHandlerImpl implements ExceptionHandler {
+
+
+ /**
+ * <p>Log the specified exception, and record it in a request scoped
+ * <code>List</code> that can be used to report them all at a future
+ * point in time to report all of the accumulated exceptions.</p>
+ *
+ * @param exception Exception to be handled
+ */
+ public void handleException(Exception exception) {
+
+ // Log the exception unconditionally
+ FacesContext context = FacesContext.getCurrentInstance();
+ if (context != null) {
+ context.getExternalContext().log(exception.getMessage(), exception);
+ } else {
+ System.out.println(exception.getMessage());
+ exception.printStackTrace(System.out);
+ }
+
+ // Are we within the context of a JavaServer Faces request?
+ // If so, accumulate this exception to the list that can be
+ // reported at the completion of the request.
+ if (context == null) {
+ return;
+ }
+ List list = (List) context.getExternalContext().getRequestMap().
+ get(Constants.EXCEPTIONS_LIST);
+ if (list == null) {
+ list = new ArrayList(5);
+ context.getExternalContext().getRequestMap().
+ put(Constants.EXCEPTIONS_LIST, list);
+ }
+ list.add(exception);
+
+ }
+
+
+}
Propchange: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL