[jboss-cvs] jboss-seam/src/main/org/jboss/seam/framework ...

Gavin King gavin.king at jboss.com
Thu Oct 5 16:41:02 EDT 2006


  User: gavin   
  Date: 06/10/05 16:41:02

  Modified:    src/main/org/jboss/seam/framework     EntityActions.java
                        ManagedEntity.java ManagedHibernateEntity.java
                        ManagedObject.java
  Log:
  much improved extensibility
  
  Revision  Changes    Path
  1.6       +7 -7      jboss-seam/src/main/org/jboss/seam/framework/EntityActions.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EntityActions.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/EntityActions.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- EntityActions.java	28 Sep 2006 01:47:33 -0000	1.5
  +++ EntityActions.java	5 Oct 2006 20:41:02 -0000	1.6
  @@ -6,10 +6,10 @@
   import org.jboss.seam.annotations.Transactional;
   import org.jboss.seam.core.FacesMessages;
   
  -public class EntityActions
  +public class EntityActions<E>
   {
      private EntityManager entityManager;
  -   private Object entity;
  +   private E entity;
      
      @In(create=true) 
      private FacesMessages facesMessages; 
  @@ -27,7 +27,7 @@
      public String persist()
      {
         getEntityManager().joinTransaction();
  -      getEntityManager().persist(entity);
  +      getEntityManager().persist( getEntity() );
         getEntityManager().flush();
         facesMessages.add("Successfully created");
         return "persisted";
  @@ -37,7 +37,7 @@
      public String remove()
      {
         getEntityManager().joinTransaction();
  -      getEntityManager().remove(entity);
  +      getEntityManager().remove( getEntity() );
         getEntityManager().flush();
         facesMessages.add("Successfully deleted");
         return "removed";
  @@ -45,7 +45,7 @@
      
      public boolean isManaged()
      {
  -      return entityManager.contains(entity);
  +      return getEntityManager().contains( getEntity() );
      }
   
      public EntityManager getEntityManager()
  @@ -58,12 +58,12 @@
         this.entityManager = entityManager;
      }
   
  -   public Object getEntity()
  +   public E getEntity()
      {
         return entity;
      }
   
  -   public void setEntity(Object entity)
  +   public void setEntity(E entity)
      {
         this.entity = entity;
      }
  
  
  
  1.5       +13 -8     jboss-seam/src/main/org/jboss/seam/framework/ManagedEntity.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ManagedEntity.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/ManagedEntity.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ManagedEntity.java	5 Oct 2006 19:43:59 -0000	1.4
  +++ ManagedEntity.java	5 Oct 2006 20:41:02 -0000	1.5
  @@ -19,7 +19,7 @@
    *
    */
   @Intercept(NEVER)
  -public class ManagedEntity extends ManagedObject
  +public class ManagedEntity<E> extends ManagedObject<E>
   {
      private EntityManager entityManager;
      private Object id;
  @@ -50,7 +50,7 @@
      @Override
      protected void initInstance() throws Exception
      {
  -      if ( id==null || "".equals(id) )
  +      if ( getId()==null || "".equals( getId() ) )
         {
            super.initInstance();
         }
  @@ -60,11 +60,16 @@
            //after remove() is called on the instance
            //is this really a Good Idea??
            getEntityManager().joinTransaction();
  -         instance = loadInstance( getConvertedId() );
  +         instance = loadInstance();
         }            
      }
   
  -   protected Object loadInstance(Object id)
  +   protected E loadInstance() throws Exception
  +   {
  +      return loadInstance( getConvertedId() );
  +   }
  +
  +   protected E loadInstance(Object id) throws Exception
      {
         return getEntityManager().find( getObjectClass(), id );
      }
  @@ -89,14 +94,14 @@
         
         if (idConverter==null)
         {
  -         return id;
  +         return getId();
         }
         else
         {
            return idConverter.getAsObject( 
                  facesContext, 
                  facesContext.getViewRoot(), 
  -               (String) id 
  +               (String) getId() 
               );
         }
      }
  @@ -131,12 +136,12 @@
         this.idClass = idClass;
      }
   
  -   public Class<?> getEntityClass()
  +   public Class<E> getEntityClass()
      {
         return getObjectClass();
      }
   
  -   public void setEntityClass(Class<?> entityClass)
  +   public void setEntityClass(Class<E> entityClass)
      {
         setObjectClass(entityClass);
      }
  
  
  
  1.4       +16 -11    jboss-seam/src/main/org/jboss/seam/framework/ManagedHibernateEntity.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ManagedHibernateEntity.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/ManagedHibernateEntity.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ManagedHibernateEntity.java	5 Oct 2006 19:43:59 -0000	1.3
  +++ ManagedHibernateEntity.java	5 Oct 2006 20:41:02 -0000	1.4
  @@ -17,7 +17,7 @@
    * @author Gavin King
    *
    */
  -public class ManagedHibernateEntity extends ManagedObject
  +public class ManagedHibernateEntity<E> extends ManagedObject<E>
   {
      private Session session;
      private Serializable id;
  @@ -45,21 +45,21 @@
         this.id = id;
      }
      
  -   public Class getEntityClass()
  +   public Class<E> getEntityClass()
      {
         return getObjectClass();
      }
   
  -   public void setEntityClass(Class<?> entityClass)
  +   public void setEntityClass(Class<E> entityClass)
      {
         setObjectClass(entityClass);
      }
   
      
      @Override
  -   public void initInstance() throws Exception
  +   protected void initInstance() throws Exception
      {
  -      if ( id==null || "".equals(id) )
  +      if ( getId()==null || "".equals( getId() ) )
         {
            super.initInstance();
         }
  @@ -68,18 +68,23 @@
            //we cache the instance so that it does not "disappear"
            //after remove() is called on the instance
            //is this really a Good Idea??
  -         instance = loadInstance( getConvertedId() );
  +         instance = loadInstance();
         }
      }
      
  -   protected Object loadInstance(Serializable id)
  +   protected E loadInstance() throws Exception
      {
  -      return getSession().get( getObjectClass(), id );
  +      return loadInstance( getConvertedId() );
  +   }
  +   
  +   protected E loadInstance(Serializable id)
  +   {
  +      return (E) getSession().get( getObjectClass(), id );
      }
      
      ////////////TODO: copy/paste from ManagedEntity ///////////////////
   
  -   private Serializable getConvertedId() throws Exception
  +   protected Serializable getConvertedId() throws Exception
      {
         FacesContext facesContext = FacesContext.getCurrentInstance();
         if (idConverter==null)
  @@ -97,14 +102,14 @@
         
         if (idConverter==null)
         {
  -         return id;
  +         return getId();
         }
         else
         {
            return (Serializable) idConverter.getAsObject( 
                  facesContext, 
                  facesContext.getViewRoot(), 
  -               (String) id 
  +               (String) getId() 
               );
         }
      }
  
  
  
  1.4       +11 -11    jboss-seam/src/main/org/jboss/seam/framework/ManagedObject.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ManagedObject.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/ManagedObject.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ManagedObject.java	5 Oct 2006 19:48:14 -0000	1.3
  +++ ManagedObject.java	5 Oct 2006 20:41:02 -0000	1.4
  @@ -20,26 +20,26 @@
    *
    */
   @Intercept(NEVER)
  -public class ManagedObject
  +public class ManagedObject<E>
   {
  -   private Class<?> objectClass;
  -   protected Object instance;
  +   private Class<E> objectClass;
  +   protected E instance;
      
      private Map<String, String> initialFieldValues;
      private Map<String, String> initialPropertyValues;
      
  -   public Class getObjectClass()
  +   public Class<E> getObjectClass()
      {
         return objectClass;
      }
   
  -   public void setObjectClass(Class<?> objectClass)
  +   public void setObjectClass(Class<E> objectClass)
      {
         this.objectClass = objectClass;
      }
   
      @Unwrap @Transactional
  -   public final Object getInstance() throws Exception
  +   public final E getInstance() throws Exception
      {
         if (instance==null)
         {
  @@ -54,17 +54,17 @@
         initialize(instance);
      }
   
  -   public void setInstance(Object instance)
  +   public void setInstance(E instance)
      {
         this.instance = instance;
      }
   
  -   protected Object createInstance() throws Exception
  +   protected E createInstance() throws Exception
      {
  -      return objectClass.newInstance();
  +      return getObjectClass().newInstance();
      }
   
  -   protected void initialize(Object instance) throws Exception
  +   protected void initialize(E instance) throws Exception
      {
         if (initialFieldValues!=null)
         {
  @@ -73,7 +73,7 @@
               Object value = Expressions.instance().createValueBinding( initializer.getValue() ).getValue();
               if ( value!=null )
               {
  -               Field field = Reflections.getField( objectClass, initializer.getKey() );
  +               Field field = Reflections.getField( getObjectClass(), initializer.getKey() );
                  if ( !field.isAccessible() ) field.setAccessible(true);
                  Reflections.set(field, instance, value);
               }
  
  
  



More information about the jboss-cvs-commits mailing list