[seam-commits] Seam SVN: r8910 - in trunk/src/main/org/jboss/seam: exception and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Sep 4 11:45:22 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-09-04 11:45:22 -0400 (Thu, 04 Sep 2008)
New Revision: 8910

Added:
   trunk/src/main/org/jboss/seam/persistence/ManagedEntityStateManager.java
Modified:
   trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java
   trunk/src/main/org/jboss/seam/exception/Exceptions.java
   trunk/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java
   trunk/src/main/org/jboss/seam/web/ExceptionFilter.java
Log:
And commit the changes needed for moving rootCause :(

Modified: trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java	2008-09-04 14:04:35 UTC (rev 8909)
+++ trunk/src/main/org/jboss/seam/core/BijectionInterceptor.java	2008-09-04 15:45:22 UTC (rev 8910)
@@ -9,7 +9,7 @@
 import org.jboss.seam.annotations.intercept.Interceptor;
 import org.jboss.seam.intercept.AbstractInterceptor;
 import org.jboss.seam.intercept.InvocationContext;
-import org.jboss.seam.util.EJB;
+import org.jboss.seam.util.Exceptions;
 
 /**
  * Before invoking the component, inject all dependencies. After
@@ -108,9 +108,9 @@
       catch (Exception e)
       {
          Exception root = e;
-         while (EJB.getCause(root) != null)
+         while (Exceptions.getCause(root) != null)
          {
-            root = EJB.getCause(root);
+            root = Exceptions.getCause(root);
          }
          if (root instanceof CyclicDependencyException)
          {

Modified: trunk/src/main/org/jboss/seam/exception/Exceptions.java
===================================================================
--- trunk/src/main/org/jboss/seam/exception/Exceptions.java	2008-09-04 14:04:35 UTC (rev 8909)
+++ trunk/src/main/org/jboss/seam/exception/Exceptions.java	2008-09-04 15:45:22 UTC (rev 8910)
@@ -27,7 +27,6 @@
 import org.jboss.seam.log.LogProvider;
 import org.jboss.seam.log.Logging;
 import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.util.EJB;
 import org.jboss.seam.util.Reflections;
 import org.jboss.seam.util.Strings;
 import org.jboss.seam.util.XML;
@@ -56,7 +55,7 @@
       
       //build a list of the nested exceptions
       List<Exception> causes = new ArrayList<Exception>();
-      for (Exception cause=e; cause!=null; cause=EJB.getCause(cause))
+      for (Exception cause=e; cause!=null; cause=org.jboss.seam.util.Exceptions.getCause(cause))
       {
          causes.add(cause);
       }

Modified: trunk/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java	2008-09-04 14:04:35 UTC (rev 8909)
+++ trunk/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java	2008-09-04 15:45:22 UTC (rev 8910)
@@ -1,26 +1,13 @@
 package org.jboss.seam.persistence;
 
 import static org.jboss.seam.ScopeType.CONVERSATION;
-import static org.jboss.seam.util.JSF.DATA_MODEL;
-import static org.jboss.seam.util.JSF.getWrappedData;
-import static org.jboss.seam.util.JSF.setWrappedData;
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.seam.Seam;
-import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.intercept.AroundInvoke;
 import org.jboss.seam.annotations.intercept.Interceptor;
-import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.BijectionInterceptor;
 import org.jboss.seam.intercept.AbstractInterceptor;
 import org.jboss.seam.intercept.InvocationContext;
 import org.jboss.seam.transaction.Transaction;
-import org.jboss.seam.util.Reflections;
 
 /**
  * Swizzles entity references around each invocation, maintaining
@@ -34,6 +21,9 @@
 @Interceptor(around=BijectionInterceptor.class)
 public class ManagedEntityIdentityInterceptor extends AbstractInterceptor
 {
+    
+    private static ManagedEntityStateManager managedEntityStateManager = new ManagedEntityStateManager();
+   
     private boolean reentrant;
     //TODO: cache the non-ignored fields, probably on Component
     
@@ -49,12 +39,12 @@
             return ctx.proceed();
         } else {
             reentrant = true;
-            entityIdsToRefs(ctx);
+            managedEntityStateManager.entityIdsToRefs(ctx.getTarget(), getComponent());
             try  {
                 return ctx.proceed();
             } finally {
                 if (!isTransactionRolledBackOrMarkedRollback()) {
-                    entityRefsToIds(ctx);
+                    managedEntityStateManager.entityRefsToIds(ctx.getTarget(), getComponent());
                     reentrant = false;
                 }
             }
@@ -73,139 +63,5 @@
       }
    }
    
-   public void entityRefsToIds(InvocationContext ctx) throws Exception
-   {
-      if ( touchedContextsExist() )
-      {
-         Object bean = ctx.getTarget();
-         Class beanClass = bean.getClass();
-         for (; beanClass!=Object.class; beanClass=beanClass.getSuperclass())
-         {
-            for ( Field field: beanClass.getDeclaredFields() )
-            {
-               if ( !ignore(field) )
-               {
-                  Object value = getFieldValue(bean, field);
-                  if (value!=null)
-                  {
-                     Object dataModel = null;
-                     if ( DATA_MODEL.isInstance(value) )
-                     {
-                        dataModel = value;
-                        value = getWrappedData(dataModel);
-                     }
-                     if ( isRef(value) )
-                     {
-                        saveWrapper(bean, field, dataModel, value);
-                     }
-                     else
-                     {
-                        clearWrapper(field);
-                     }
-                  }
-                  else
-                  {
-                     clearWrapper(field);
-                  }
-               }
-            }
-         }
-      }
-   }
-
-   public void entityIdsToRefs(InvocationContext ctx) throws Exception
-   {      
-      if ( touchedContextsExist() )
-      {
-         Object bean = ctx.getTarget();
-         Class beanClass = bean.getClass();
-         for (; beanClass!=Object.class; beanClass=beanClass.getSuperclass())
-         {
-            for ( Field field: beanClass.getDeclaredFields() )
-            {
-               if ( !ignore(field) )
-               {
-                  Object value = getFieldValue(bean, field);
-                  Object dataModel = null;
-                  if (value!=null && DATA_MODEL.isInstance(value) )
-                  {
-                     dataModel = value;
-                  }
-                  //TODO: be more selective
-                  getFromWrapper(bean, field, dataModel);
-               }
-            }
-         }
-      }
-   }
-
-   private boolean isRef(Object value)
-   {
-      //TODO: could do better by checking if the
-      //      collection really contains an entity
-      return value instanceof List || 
-            value instanceof Map || 
-            value instanceof Set || 
-            Seam.getEntityClass(value.getClass()) != null;
-   }
-
-   private Object getFieldValue(Object bean, Field field) throws Exception
-   {
-      if ( !field.isAccessible() ) field.setAccessible(true);
-      Object value = Reflections.get(field, bean);
-      return value;
-   }
-
-   private boolean ignore(Field field)
-   {
-      return Modifier.isTransient( field.getModifiers() ) || 
-            Modifier.isStatic( field.getModifiers() )
-            || field.isAnnotationPresent(In.class);
-   }
-
-   private boolean touchedContextsExist()
-   {
-       PersistenceContexts touchedContexts = PersistenceContexts.instance();
-       return touchedContexts!=null && touchedContexts.getTouchedContexts().size()>0;
-   }
-
-   private String getFieldId(Field field)
-   {
-      return getComponent().getName() + '.' + field.getName();
-   }
-
-   private void saveWrapper(Object bean, Field field, Object dataModel, Object value) throws Exception
-   {
-      Contexts.getConversationContext().set( getFieldId(field), value );
-      if (dataModel==null)
-      {
-         Reflections.set(field, bean, null);
-      }
-      else
-      {
-         setWrappedData(dataModel, null);
-      }
-   }
-
-   private void clearWrapper(Field field) throws Exception
-   {
-      Contexts.getConversationContext().remove( getFieldId(field) );
-   }
-
-   private void getFromWrapper(Object bean, Field field, Object dataModel) throws Exception
-   {
-      Object value = Contexts.getConversationContext().get( getFieldId(field) );
-      if (value!=null)
-      {
-         if (dataModel==null)
-         {
-            Reflections.set(field, bean, value);
-         }
-         else
-         {
-            setWrappedData(dataModel, value);
-         }
-      }
-   }
-
+   
 }

Added: trunk/src/main/org/jboss/seam/persistence/ManagedEntityStateManager.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/ManagedEntityStateManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/persistence/ManagedEntityStateManager.java	2008-09-04 15:45:22 UTC (rev 8910)
@@ -0,0 +1,162 @@
+package org.jboss.seam.persistence;
+
+import static org.jboss.seam.util.JSF.DATA_MODEL;
+import static org.jboss.seam.util.JSF.getWrappedData;
+import static org.jboss.seam.util.JSF.setWrappedData;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.Seam;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.util.Reflections;
+
+/**
+ * @author Gavin King
+ * @author Pete Muir
+ * @author Norman Richards
+ *
+ */
+public class ManagedEntityStateManager
+{
+
+   public void entityRefsToIds(Object controllerBean, Component component) throws Exception
+   {
+      if ( touchedContextsExist() )
+      {
+         Class beanClass = controllerBean.getClass();
+         for (; beanClass!=Object.class; beanClass=beanClass.getSuperclass())
+         {
+            for ( Field field: beanClass.getDeclaredFields() )
+            {
+               if ( !ignore(field) )
+               {
+                  Object value = getFieldValue(controllerBean, field);
+                  if (value!=null)
+                  {
+                     Object dataModel = null;
+                     if ( DATA_MODEL.isInstance(value) )
+                     {
+                        dataModel = value;
+                        value = getWrappedData(dataModel);
+                     }
+                     if ( isRef(value) )
+                     {
+                        saveWrapper(controllerBean, component, field, dataModel, value);
+                     }
+                     else
+                     {
+                        clearWrapper(component, field);
+                     }
+                  }
+                  else
+                  {
+                     clearWrapper(component, field);
+                  }
+               }
+            }
+         }
+      }
+   }
+
+   public void entityIdsToRefs(Object controllerBean, Component component) throws Exception
+   {      
+      if ( touchedContextsExist() )
+      {
+         Class beanClass = controllerBean.getClass();
+         for (; beanClass!=Object.class; beanClass=beanClass.getSuperclass())
+         {
+            for ( Field field: beanClass.getDeclaredFields() )
+            {
+               if ( !ignore(field) )
+               {
+                  Object value = getFieldValue(controllerBean, field);
+                  Object dataModel = null;
+                  if (value!=null && DATA_MODEL.isInstance(value) )
+                  {
+                     dataModel = value;
+                  }
+                  //TODO: be more selective
+                  getFromWrapper(controllerBean, component, field, dataModel);
+               }
+            }
+         }
+      }
+   }
+
+   private boolean isRef(Object value)
+   {
+      //TODO: could do better by checking if the
+      //      collection really contains an entity
+      return value instanceof List || 
+            value instanceof Map || 
+            value instanceof Set || 
+            Seam.getEntityClass(value.getClass()) != null;
+   }
+
+   private Object getFieldValue(Object bean, Field field) throws Exception
+   {
+      if ( !field.isAccessible() ) field.setAccessible(true);
+      Object value = Reflections.get(field, bean);
+      return value;
+   }
+
+   private boolean ignore(Field field)
+   {
+      return Modifier.isTransient( field.getModifiers() ) || 
+            Modifier.isStatic( field.getModifiers() )
+            || field.isAnnotationPresent(In.class);
+   }
+
+   private boolean touchedContextsExist()
+   {
+       PersistenceContexts touchedContexts = PersistenceContexts.instance();
+       return touchedContexts!=null && touchedContexts.getTouchedContexts().size()>0;
+   }
+
+   private String getFieldId(Component component, Field field)
+   {
+      return component.getName() + '.' + field.getName();
+   }
+
+   private void saveWrapper(Object bean, Component component, Field field, Object dataModel, Object value) throws Exception
+   {
+      Contexts.getConversationContext().set( getFieldId(component, field), value );
+      if (dataModel==null)
+      {
+         Reflections.set(field, bean, null);
+      }
+      else
+      {
+         setWrappedData(dataModel, null);
+      }
+   }
+
+   private void clearWrapper(Component component, Field field) throws Exception
+   {
+      Contexts.getConversationContext().remove( getFieldId(component, field) );
+   }
+
+   private void getFromWrapper(Object bean, Component component, Field field, Object dataModel) throws Exception
+   {
+      Object value =Contexts.getConversationContext().get( getFieldId(component, field) );
+      if (value!=null)
+      {
+         if (dataModel==null)
+         {
+            Reflections.set(field, bean, value);
+         }
+         else
+         {
+            setWrappedData(dataModel, value);
+         }
+      }
+   }
+
+   
+}


Property changes on: trunk/src/main/org/jboss/seam/persistence/ManagedEntityStateManager.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/main/org/jboss/seam/web/ExceptionFilter.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/ExceptionFilter.java	2008-09-04 14:04:35 UTC (rev 8909)
+++ trunk/src/main/org/jboss/seam/web/ExceptionFilter.java	2008-09-04 15:45:22 UTC (rev 8910)
@@ -37,7 +37,6 @@
 import org.jboss.seam.mock.MockFacesContext;
 import org.jboss.seam.transaction.Transaction;
 import org.jboss.seam.transaction.UserTransaction;
-import org.jboss.seam.util.EJB;
 
 /**
  * Delegate uncaught exceptions to Seam exception handling.
@@ -66,7 +65,7 @@
       catch (Exception e)
       {
          log.warn( "handling uncaught exception", e );
-         log.warn( "exception root cause", EJB.getCause(e) );
+         log.warn( "exception root cause", org.jboss.seam.util.Exceptions.getCause(e) );
          endWebRequestAfterException( (HttpServletRequest) request, (HttpServletResponse) response, e);
       }
    }




More information about the seam-commits mailing list