[seam-commits] Seam SVN: r13208 - in modules/faces/branches/exception_handling: api/src/main/java/org/jboss/seam/faces and 5 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Jun 16 18:32:02 EDT 2010
Author: lightguard
Date: 2010-06-16 18:32:02 -0400 (Wed, 16 Jun 2010)
New Revision: 13208
Added:
modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/exceptionhandling/
modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesState.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparator.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/MethodParameterTypeHelper.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/StateImpl.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesStateImpl.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandler.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandlerTest.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionExceptionHandler.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparatorTest.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/MultipleHandlerTest.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/NullPointerExceptionHandler.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandlerTest.java
Removed:
modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/FacesState.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java
Modified:
modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/HandlerChain.java
modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/HandlerChainImpl.java
modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java
modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java
Log:
Seperating the base impl and api.
HandlerChain changed from next to end.
Base implementation is decently tested.
Deleted: modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/FacesState.java
===================================================================
--- modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/FacesState.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/FacesState.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.exceptionhandling;
-
-import javax.faces.context.FacesContext;
-
-/**
- * Java Server Faces implementation of {@link State}.
- */
-public interface FacesState extends State
-{
- /**
- * @return the currently active Faces Context object
- */
- FacesContext getFacesContext();
-
- /**
- * Convenience method to facilitate navigation to a view id in an
- * {@link ExceptionHandler}.
- * @param viewId JSF view to navigate
- */
- void navigate(String viewId);
-}
Modified: modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/HandlerChain.java
===================================================================
--- modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/HandlerChain.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/HandlerChain.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -28,7 +28,9 @@
public interface HandlerChain
{
/**
- * Continue with the chain.
+ * End execution of the chain.
+ * Calling this method will immediately stop executing the handler chain, leaving any
+ * handlers left in the chain as uncalled.
*/
- void next();
+ void end();
}
Modified: modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java
===================================================================
--- modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -23,10 +23,9 @@
package org.jboss.seam.faces.context;
/**
- * A context that lives from Restore View to the next Render Response.
- *
+ * A context that lives from Restore View to the end Render Response.
+ *
* @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
- *
*/
public interface FlashContext
{
Copied: modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesState.java (from rev 13077, modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/exceptionhandling/FacesState.java)
===================================================================
--- modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesState.java (rev 0)
+++ modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesState.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.exceptionhandling;
+
+import org.jboss.seam.exceptionhandling.State;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * Java Server Faces implementation of {@link org.jboss.seam.exceptionhandling.State}.
+ */
+public interface FacesState extends State
+{
+ /**
+ * @return the currently active Faces Context object
+ */
+ FacesContext getFacesContext();
+
+ /**
+ * Convenience method to facilitate navigation to a view id in an
+ * {@link org.jboss.seam.exceptionhandling.ExceptionHandler}.
+ *
+ * @param viewId JSF view to navigate
+ */
+ void navigate(String viewId);
+}
Property changes on: modules/faces/branches/exception_handling/api/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesState.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Added: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparator.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparator.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparator.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import java.util.Comparator;
+
+/**
+ * Comparator to sort exception handlers according to priority (highest number first) then
+ * by class hierarchy of the Exception types being handled (most specific first).
+ */
+public class ExceptionHandlerComparator implements Comparator<ExceptionHandler>
+{
+ /**
+ * Compares its two arguments for order. Returns a negative integer,
+ * zero, or a positive integer as the first argument is less than, equal
+ * to, or greater than the second.<p>
+ * <p/>
+ * In the foregoing description, the notation
+ * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
+ * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
+ * <tt>0</tt>, or <tt>1</tt> according to whether the value of
+ * <i>expression</i> is negative, zero or positive.<p>
+ * <p/>
+ * The implementor must ensure that <tt>sgn(compare(x, y)) ==
+ * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
+ * implies that <tt>compare(x, y)</tt> must throw an exception if and only
+ * if <tt>compare(y, x)</tt> throws an exception.)<p>
+ * <p/>
+ * The implementor must also ensure that the relation is transitive:
+ * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies
+ * <tt>compare(x, z)>0</tt>.<p>
+ * <p/>
+ * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
+ * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
+ * <tt>z</tt>.<p>
+ * <p/>
+ * It is generally the case, but <i>not</i> strictly required that
+ * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking,
+ * any comparator that violates this condition should clearly indicate
+ * this fact. The recommended language is "Note: this comparator
+ * imposes orderings that are inconsistent with equals."
+ *
+ * @param lhs the first object to be compared.
+ * @param rhs the second object to be compared.
+ * @return a negative integer, zero, or a positive integer as the
+ * first argument is less than, equal to, or greater than the
+ * second.
+ * @throws ClassCastException if the arguments' types prevent them from
+ * being compared by this comparator.
+ */
+ public int compare(ExceptionHandler lhs, ExceptionHandler rhs)
+ {
+ if (lhs.getPriority() == rhs.getPriority())
+ {
+ final MethodParameterTypeHelper lhsTypes = new MethodParameterTypeHelper(lhs);
+ final MethodParameterTypeHelper rhsTypes = new MethodParameterTypeHelper(rhs);
+
+ if (lhsTypes.equals(rhsTypes))
+ {
+ return 0;
+ }
+ // the right hand side is the same or a sub type of left hand side
+ // In other words lhs is a parent type and show go later in the list
+ for (Class type : rhsTypes.getExceptionTypes())
+ {
+ if (lhsTypes.getExceptionTypes().contains(type))
+ {
+ return 1;
+ }
+ }
+ return -1;
+ }
+ return rhs.getPriority() - lhs.getPriority();
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparator.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Modified: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -38,62 +38,72 @@
{
/**
* Observes the event, finds the correct exception handler(s) and invokes them.
+ *
* @param event Event Payload
*/
@SuppressWarnings("unchecked")
public void executeHandlers(@Observes ExceptionEvent event)
{
final HandlerChain chain = new HandlerChainImpl();
- final Throwable exception = event.getException();
+ final Stack<Throwable> unwrappedExceptions = new Stack<Throwable>();
final State state = event.getState();
final BeanManager beanManager = state.getBeanManager();
- ExceptionHandler bean;
- final List<ExceptionHandler> beans = this.getContextualExceptionHandlerInstances(beanManager);
+ final Set<ExceptionHandler> validHandlers = new TreeSet<ExceptionHandler>(new ExceptionHandlerComparator());
+ final List<ExceptionHandler> allHandlers = this.getContextualExceptionHandlerInstances(beanManager);
+ Throwable exception = event.getException();
+ MethodParameterTypeHelper methodParameterTypeHelper;
+
+ do
+ {
+ unwrappedExceptions.push(exception);
+ }
+ while ((exception = exception.getCause()) != null);
+
// Finding the correct exception handlers using reflection based on the method
// to determine if it's the correct
+ for (ExceptionHandler handler : allHandlers)
+ {
+ methodParameterTypeHelper = new MethodParameterTypeHelper(handler);
- // TODO: Uwrap the exception
- for (Iterator<ExceptionHandler> iter = beans.iterator(); iter.hasNext();)
- {
- bean = iter.next();
- try
+ for (Throwable unwrapped : unwrappedExceptions)
{
- // TODO: search for type hierarchy as well.
- bean.getClass().getMethod("handle", HandlerChain.class, state.getClass().getInterfaces()[0], exception.getClass());
+ if (methodParameterTypeHelper.containsExceptionTypeOrSubType(unwrapped.getClass())
+ && methodParameterTypeHelper.containsStateTypeOrSubType(state.getClass()))
+ {
+ validHandlers.add(handler);
+ }
}
- catch (NoSuchMethodException e)
- {
- iter.remove();
- }
}
- // TODO: if priorities are the same look for type hierarchy
- Collections.sort(beans, new Comparator<ExceptionHandler>()
+ for (ExceptionHandler exceptionHandler : validHandlers)
{
- public int compare(ExceptionHandler lhs, ExceptionHandler rhs)
+ exceptionHandler.handle(chain, state, exception);
+ event.setExceptionHandled(true);
+
+ if (((HandlerChainImpl) chain).isChainEnd())
{
- return lhs.getPriority() - rhs.getPriority();
+ break;
}
- });
-
- for (ExceptionHandler handler : beans)
- {
- handler.handle(chain, state, exception);
- event.setExceptionHandled(true);
}
}
+ /**
+ * Method taken from Seam faces BeanManagerUtils.
+ *
+ * @param manager BeanManager instance
+ * @return List of instantiated found by the bean manager
+ */
@SuppressWarnings("unchecked")
- private <T> List<T> getContextualExceptionHandlerInstances(BeanManager manager)
+ private List<ExceptionHandler> getContextualExceptionHandlerInstances(BeanManager manager)
{
- List<T> result = new ArrayList<T>();
+ List<ExceptionHandler> result = new ArrayList<ExceptionHandler>();
for (Bean<?> bean : manager.getBeans(ExceptionHandler.class))
{
- CreationalContext<T> context = (CreationalContext<T>) manager.createCreationalContext(bean);
+ CreationalContext<ExceptionHandler> context = (CreationalContext<ExceptionHandler>) manager.createCreationalContext(bean);
if (context != null)
{
- result.add((T) manager.getReference(bean, ExceptionHandler.class, context));
+ result.add((ExceptionHandler) manager.getReference(bean, ExceptionHandler.class, context));
}
}
return result;
Deleted: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.exceptionhandling;
-
-import javax.enterprise.inject.spi.BeanManager;
-import javax.faces.application.NavigationHandler;
-import javax.faces.context.FacesContext;
-import javax.inject.Inject;
-
-public class FacesStateImpl implements FacesState
-{
- private BeanManager beanManager;
-
- private FacesContext facesContext;
-
- private NavigationHandler navigationHandler;
-
- public FacesStateImpl(BeanManager beanManager, FacesContext facesContext)
- {
- this.beanManager = beanManager;
- this.facesContext = facesContext;
- this.navigationHandler = facesContext.getApplication().getNavigationHandler();
- }
-
- /**
- * @return the currently active Faces Context object
- */
- public FacesContext getFacesContext()
- {
- return this.facesContext;
- }
-
- /**
- * Convenience method to facilitate navigation to a view id in an
- * {@link ExceptionHandler}.
- *
- * @param viewId JSF view to navigate
- */
- public void navigate(String viewId)
- {
- String currentViewId = null;
-
- if (this.facesContext.getViewRoot() != null)
- {
- currentViewId = this.facesContext.getViewRoot().getViewId();
- }
- this.navigationHandler.handleNavigation(this.facesContext, currentViewId, viewId);
- }
-
- /**
- * @return current BeanManager.
- */
- public BeanManager getBeanManager()
- {
- return this.beanManager;
- }
-}
Modified: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/HandlerChainImpl.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/HandlerChainImpl.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/HandlerChainImpl.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -22,23 +22,30 @@
package org.jboss.seam.exceptionhandling;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-
+/**
+ * Implementation of the {@link HandlerChain} interface.
+ * Provides a package private method to check if the chain
+ * needs to end.
+ */
public class HandlerChainImpl implements HandlerChain
{
- private boolean continueChain;
+ private boolean chainEnd;
/**
- * Continue with the chain.
+ * End execution of the chain.
+ * Calling this method will immediately stop executing the handler chain, leaving any
+ * handlers left in the chain as uncalled.
*/
- public void next()
+ public void end()
{
- this.continueChain = true;
+ this.chainEnd = false;
}
- boolean isContinueChain()
+ /**
+ * @return flag indicating if the chain should continue execution
+ */
+ boolean isChainEnd()
{
- return this.continueChain;
+ return this.chainEnd;
}
}
Added: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/MethodParameterTypeHelper.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/MethodParameterTypeHelper.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/MethodParameterTypeHelper.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Helper to encapsulate reflection code for finding parameter types on the handler method.
+ */
+final public class MethodParameterTypeHelper
+{
+ private Set<Class> exceptionTypes;
+ private Set<Class> stateTypes;
+
+ /**
+ * Constructor.
+ *
+ * @param handler Handler for which this helper is constructed
+ */
+ public MethodParameterTypeHelper(ExceptionHandler handler)
+ {
+ final Method[] methods = handler.getClass().getMethods();
+ this.exceptionTypes = new HashSet<Class>();
+ this.stateTypes = new HashSet<Class>();
+
+ for (Method m : methods)
+ {
+ if ("handle".equals(m.getName()))
+ {
+ this.stateTypes.add(m.getParameterTypes()[1]);
+ this.exceptionTypes.add(m.getParameterTypes()[2]);
+ }
+ }
+
+ // Cleanup base types if needed
+ if (this.stateTypes.size() > 1)
+ {
+ this.stateTypes.remove(State.class);
+ }
+
+ if (this.exceptionTypes.size() > 1)
+ {
+ this.exceptionTypes.remove(Throwable.class);
+ }
+ }
+
+ /**
+ * @return Unmodifiable collection of exception types found in the handle method(s).
+ */
+ public Collection<Class> getExceptionTypes()
+ {
+ return Collections.unmodifiableCollection(exceptionTypes);
+ }
+
+ /**
+ * @return Unmodifiable collection of exception types found in the handle method(s).
+ */
+ public Collection<Class> getStateTypes()
+ {
+ return Collections.unmodifiableCollection(stateTypes);
+ }
+
+ /**
+ * Looks for the given type or super types in the exception type collection.
+ *
+ * @param type type (or super types of) to search for
+ * @return flag indicating if the type or super types of that type are found
+ */
+ public boolean containsExceptionTypeOrSubType(Class type)
+ {
+ return this.containsTypeOrSubType(this.exceptionTypes, type);
+ }
+
+ /**
+ * Looks for the given type or super types in the state type collection.
+ *
+ * @param type type (or super types of) to search for
+ * @return flag indicating if the type or super types of that type are found
+ */
+ public boolean containsStateTypeOrSubType(Class type)
+ {
+ return this.containsTypeOrSubType(this.stateTypes, type);
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ MethodParameterTypeHelper that = (MethodParameterTypeHelper) o;
+
+ return this.exceptionTypes.equals(that.exceptionTypes) && this.stateTypes.equals(that.stateTypes);
+ }
+
+ public int hashCode()
+ {
+ int result = exceptionTypes != null ? exceptionTypes.hashCode() : 5;
+ result = 73 * result + (stateTypes != null ? stateTypes.hashCode() : 5);
+ return result;
+ }
+
+ /**
+ * Looks for the given type or super types in the given collection.
+ *
+ * @param types Collection to search
+ * @param type type (or super types of) to search for
+ * @return flag indicating if the type or super types of that type are found
+ */
+ @SuppressWarnings("unchecked")
+ private boolean containsTypeOrSubType(Collection<Class> types, Class type)
+ {
+ if (types.contains(type))
+ {
+ return true;
+ }
+
+ for (Class t : types)
+ {
+ if (t.isAssignableFrom(type))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/MethodParameterTypeHelper.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Added: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/StateImpl.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/StateImpl.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/StateImpl.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Basic {@link State} implementation.
+ */
+public class StateImpl implements State
+{
+ private BeanManager beanManager;
+
+ /**
+ * Constructor
+ *
+ * @param beanManager instance of {@link BeanManager}.
+ */
+ public StateImpl(BeanManager beanManager)
+ {
+ this.beanManager = beanManager;
+ }
+
+ /**
+ * @return current BeanManager.
+ */
+ public BeanManager getBeanManager()
+ {
+ return this.beanManager;
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/StateImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Copied: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesStateImpl.java (from rev 13167, modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java)
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesStateImpl.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesStateImpl.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.exceptionhandling;
+
+import org.jboss.seam.exceptionhandling.StateImpl;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.application.NavigationHandler;
+import javax.faces.context.FacesContext;
+
+public class FacesStateImpl extends StateImpl implements FacesState
+{
+
+ private FacesContext facesContext;
+
+ private NavigationHandler navigationHandler;
+
+ public FacesStateImpl(BeanManager beanManager, FacesContext facesContext)
+ {
+ super(beanManager);
+ this.facesContext = facesContext;
+ this.navigationHandler = facesContext.getApplication().getNavigationHandler();
+ }
+
+ /**
+ * @return the currently active Faces Context object
+ */
+ public FacesContext getFacesContext()
+ {
+ return this.facesContext;
+ }
+
+ /**
+ * Convenience method to facilitate navigation to a view id in an
+ * {@link org.jboss.seam.exceptionhandling.ExceptionHandler}.
+ *
+ * @param viewId JSF view to navigate
+ */
+ public void navigate(String viewId)
+ {
+ String currentViewId = null;
+
+ if (this.facesContext.getViewRoot() != null)
+ {
+ currentViewId = this.facesContext.getViewRoot().getViewId();
+ }
+ this.navigationHandler.handleNavigation(this.facesContext, currentViewId, viewId);
+ }
+
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/FacesStateImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Modified: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -23,29 +23,18 @@
package org.jboss.seam.faces.exceptionhandling;
import org.jboss.seam.exceptionhandling.ExceptionEvent;
-import org.jboss.seam.exceptionhandling.FacesState;
-import org.jboss.seam.exceptionhandling.FacesStateImpl;
import org.jboss.seam.exceptionhandling.HandlerChain;
-import org.jboss.seam.faces.util.BeanManagerUtils;
import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Event;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.util.TypeLiteral;
import javax.faces.FacesException;
-import javax.faces.context.*;
import javax.faces.context.ExceptionHandler;
+import javax.faces.context.ExceptionHandlerWrapper;
+import javax.faces.context.FacesContext;
import javax.faces.event.ExceptionQueuedEvent;
import javax.inject.Inject;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
public class SeamExceptionHandler extends ExceptionHandlerWrapper
Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandler.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandler.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import org.joda.time.DateTime;
+
+public class BaseExceptionHandler
+{
+ protected boolean handleCalled;
+ protected boolean callEnd;
+ protected DateTime timeCalled;
+
+ public boolean isHandleCalled()
+ {
+ return this.handleCalled;
+ }
+
+ public void shouldCallEnd(boolean callEnd)
+ {
+ this.callEnd = callEnd;
+ }
+
+ public DateTime getTimeCalled()
+ {
+ return this.timeCalled;
+ }
+
+ /**
+ * Method called to execute logic for an uncaught exception.
+ *
+ * @param chain Chain object used to continue handling chain
+ * @param state container for any useful application state
+ * @param e uncaught exception
+ */
+ public void baseHandle(HandlerChain chain, State state, Throwable e)
+ {
+ this.timeCalled = new DateTime();
+ this.handleCalled = true;
+
+ if (this.callEnd)
+ {
+ chain.end();
+ }
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandlerTest.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandlerTest.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandlerTest.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+public class BaseExceptionHandlerTest
+{
+ @Inject
+ protected BeanManager beanManager;
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/BaseExceptionHandlerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionExceptionHandler.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionExceptionHandler.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import javax.enterprise.context.RequestScoped;
+
+ at RequestScoped
+public class ExceptionExceptionHandler extends BaseExceptionHandler implements ExceptionHandler<Exception, State>
+{
+ /**
+ * @return the numeric priority of this handler in relationship to
+ * other handlers, 1 being top priority
+ */
+ public int getPriority()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /**
+ * Method called to execute logic for an uncaught exception.
+ *
+ * @param chain Chain object used to continue handling chain
+ * @param state container for any useful application state
+ * @param e uncaught exception
+ */
+ public void handle(HandlerChain chain, State state, Exception e)
+ {
+ super.baseHandle(chain, state, e);
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionExceptionHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparatorTest.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparatorTest.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparatorTest.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class ExceptionHandlerComparatorTest
+{
+ @Test
+ public void testHandlersCalledInCorrectOrder()
+ {
+ NullPointerExceptionHandler nullPointerExceptionHandler = new NullPointerExceptionHandler();
+ ExceptionExceptionHandler exceptionExceptionHandler = new ExceptionExceptionHandler();
+ UnsupportedOperationExceptionHandler unsupportedOperationExceptionHandler = new UnsupportedOperationExceptionHandler();
+ List<? extends ExceptionHandler<? extends Exception, State>> handlerList;
+ handlerList = Arrays.asList(nullPointerExceptionHandler, exceptionExceptionHandler, unsupportedOperationExceptionHandler);
+
+ Collections.sort(handlerList, new ExceptionHandlerComparator());
+
+ assertEquals(unsupportedOperationExceptionHandler, handlerList.get(0));
+ assertEquals(nullPointerExceptionHandler, handlerList.get(1));
+ assertEquals(exceptionExceptionHandler, handlerList.get(2));
+ }
+
+ @Test
+ public void testHandlersCalledInCorrectOrder2()
+ {
+ NullPointerExceptionHandler nullPointerExceptionHandler = new NullPointerExceptionHandler();
+ ExceptionExceptionHandler exceptionExceptionHandler = new ExceptionExceptionHandler();
+ UnsupportedOperationExceptionHandler unsupportedOperationExceptionHandler = new UnsupportedOperationExceptionHandler();
+ List<? extends ExceptionHandler<? extends Exception, State>> handlerList;
+ handlerList = Arrays.asList(nullPointerExceptionHandler, unsupportedOperationExceptionHandler, exceptionExceptionHandler);
+
+ Collections.sort(handlerList, new ExceptionHandlerComparator());
+
+ assertEquals(unsupportedOperationExceptionHandler, handlerList.get(0));
+ assertEquals(nullPointerExceptionHandler, handlerList.get(1));
+ assertEquals(exceptionExceptionHandler, handlerList.get(2));
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Deleted: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -1,100 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.exceptionhandling;
-
-import org.jboss.arquillian.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.faces.environment.FacesContextProducer;
-import org.jboss.seam.faces.environment.MockFacesContext;
-import org.jboss.seam.faces.exceptionhandling.SeamExceptionHandler;
-import org.jboss.seam.faces.exceptionhandling.SeamExceptionHandlerFactory;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ArchivePaths;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.jboss.test.faces.mock.application.MockApplication;
-import org.jboss.test.faces.mock.application.MockNavigationHandler;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.faces.application.NavigationHandler;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.context.ExceptionHandlerFactory;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.inject.Inject;
-
-import java.io.IOException;
-
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertTrue;
-
- at RunWith(Arquillian.class)
-public class ExceptionHandlerTest
-{
- @Inject
- private SeamExceptionHandler seamHandler;
-
- @Inject
- private UnsupportedOperationExceptionHandler handler;
-
- @Inject
- private BeanManager beanManager;
-
- private MockFacesEnvironment environment;
-
- @Deployment
- public static Archive<?> createTestArchive()
- {
- return ShrinkWrap.create("test.jar", JavaArchive.class)
- .addClasses(UnsupportedOperationExceptionHandler.class, SeamExceptionHandler.class,
- ExceptionHandlerExecutor.class)
- .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
- }
-
- @Before
- public void setup()
- {
- this.environment = MockFacesEnvironment.createEnvironment().withApplication();
-
- expect(this.environment.getApplication().getNavigationHandler())
- .andStubReturn(this.environment.createMock(NavigationHandler.class));
-
- this.environment.replay();
- }
-
- @Test
- public void testHandlerIsCalled() throws IOException
- {
- ExceptionEvent event = new ExceptionEvent(new UnsupportedOperationException(), new FacesStateImpl(this.beanManager, this.environment.getFacesContext()));
- this.beanManager.fireEvent(event);
- assertTrue(this.handler.isHandleCalled());
- assertTrue(event.isExceptionHandled());
- }
-}
Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/MultipleHandlerTest.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/MultipleHandlerTest.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/MultipleHandlerTest.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+ at RunWith(Arquillian.class)
+public class MultipleHandlerTest extends BaseExceptionHandlerTest
+{
+ @Inject
+ private UnsupportedOperationExceptionHandler unsupportedOperationExceptionHandler;
+
+ @Inject
+ private ExceptionExceptionHandler exceptionExceptionHandler;
+
+ @Inject
+ private NullPointerExceptionHandler nullPointerExceptionHandler;
+
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(UnsupportedOperationExceptionHandler.class, ExceptionExceptionHandler.class,
+ ExceptionHandlerExecutor.class, NullPointerExceptionHandler.class)
+ .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Test
+ public void testAllValidHandlersCalled()
+ {
+ ExceptionEvent event = new ExceptionEvent(new UnsupportedOperationException(), new StateImpl(this.beanManager));
+ this.beanManager.fireEvent(event);
+
+ assertTrue(this.unsupportedOperationExceptionHandler.isHandleCalled());
+ assertTrue(this.exceptionExceptionHandler.isHandleCalled());
+ assertFalse(this.nullPointerExceptionHandler.isHandleCalled());
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/MultipleHandlerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/NullPointerExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/NullPointerExceptionHandler.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/NullPointerExceptionHandler.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import javax.enterprise.context.RequestScoped;
+
+ at RequestScoped
+public class NullPointerExceptionHandler extends BaseExceptionHandler implements ExceptionHandler<NullPointerException, State>
+{
+ /**
+ * @return the numeric priority of this handler in relationship to
+ * other handlers, 1 being top priority
+ */
+ public int getPriority()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /**
+ * Method called to execute logic for an uncaught exception.
+ *
+ * @param chain Chain object used to continue handling chain
+ * @param state container for any useful application state
+ * @param e uncaught exception
+ */
+ public void handle(HandlerChain chain, State state, NullPointerException e)
+ {
+ super.baseHandle(chain, state, e);
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/NullPointerExceptionHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
Deleted: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.exceptionhandling;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.render.Renderer;
-import java.io.IOException;
-
-public class ThrowExceptionRenderer extends Renderer
-{
- /**
- * <p>Render the beginning specified {@link javax.faces.component.UIComponent} to the
- * output stream or writer associated with the response we are creating.
- * If the conversion attempted in a previous call to
- * <code>getConvertedValue()</code> for this component failed, the state
- * information saved during execution
- * of <code>decode()</code> should be used to reproduce the incorrect
- * input.</p>
- *
- * @param context {@link javax.faces.context.FacesContext} for the request we are processing
- * @param component {@link javax.faces.component.UIComponent} to be rendered
- * @throws java.io.IOException if an input/output error occurs while rendering
- * @throws NullPointerException if <code>context</code>
- * or <code>component</code> is null
- */
- @Override
- public void encodeBegin(FacesContext context, UIComponent component) throws IOException
- {
- throw new UnsupportedOperationException();
- }
-}
Modified: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java 2010-06-16 22:24:06 UTC (rev 13207)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -25,9 +25,8 @@
import javax.enterprise.context.RequestScoped;
@RequestScoped
-public class UnsupportedOperationExceptionHandler implements ExceptionHandler<UnsupportedOperationException, FacesState>
+public class UnsupportedOperationExceptionHandler extends BaseExceptionHandler implements ExceptionHandler<UnsupportedOperationException, State>
{
- private boolean handleCalled;
/**
* @return the numeric priority of this handler in relationship to
@@ -35,7 +34,7 @@
*/
public int getPriority()
{
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ return 1; //To change body of implemented methods use File | Settings | File Templates.
}
/**
@@ -45,13 +44,8 @@
* @param state container for any useful application state
* @param e uncaught exception
*/
- public void handle(HandlerChain chain, FacesState state, UnsupportedOperationException e)
+ public void handle(HandlerChain chain, State state, UnsupportedOperationException e)
{
- this.handleCalled = true;
+ super.baseHandle(chain, state, e);
}
-
- public boolean isHandleCalled()
- {
- return this.handleCalled;
- }
}
Copied: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandlerTest.java (from rev 13167, modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java)
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandlerTest.java (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandlerTest.java 2010-06-16 22:32:02 UTC (rev 13208)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+import java.io.IOException;
+
+import static org.junit.Assert.assertTrue;
+
+ at RunWith(Arquillian.class)
+public class UnsupportedOperationExceptionHandlerTest extends BaseExceptionHandlerTest
+{
+ @Inject
+ private UnsupportedOperationExceptionHandler handler;
+
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(UnsupportedOperationExceptionHandler.class, ExceptionHandlerExecutor.class)
+ .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Test
+ public void testHandlerIsCalled() throws IOException
+ {
+ this.handler.shouldCallEnd(true); // Set so I can reuse this handler in different tests
+ ExceptionEvent event = new ExceptionEvent(new UnsupportedOperationException(), new StateImpl(this.beanManager));
+ this.beanManager.fireEvent(event);
+
+ assertTrue(this.handler.isHandleCalled());
+ assertTrue(event.isExceptionHandled());
+ }
+}
Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandlerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/x-java-source
Name: svn:keywords
+ Author Date Id Revision URL
Name: svn:eol-style
+ native
More information about the seam-commits
mailing list