[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui ...

Peter Muir peter at bleepbleep.org.uk
Sun Apr 15 13:41:23 EDT 2007


  User: pmuir   
  Date: 07/04/15 13:41:22

  Modified:    src/ui/org/jboss/seam/ui   EntityConverter.java
  Added:       src/ui/org/jboss/seam/ui   EntityConverterStore.java
  Log:
  Refactor EntityIdentifier/EntityConverterStore
  
  Revision  Changes    Path
  1.4       +2 -3      jboss-seam/src/ui/org/jboss/seam/ui/EntityConverter.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EntityConverter.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/EntityConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- EntityConverter.java	27 Mar 2007 21:29:17 -0000	1.3
  +++ EntityConverter.java	15 Apr 2007 17:41:22 -0000	1.4
  @@ -19,7 +19,6 @@
   import org.jboss.seam.annotations.Transactional;
   import org.jboss.seam.annotations.jsf.Converter;
   import org.jboss.seam.core.Expressions.ValueBinding;
  -import org.jboss.seam.framework.EntityIdentifierStore;
   
   /**
    * Allows conversion of an entity to/from a key which can be written to a page.
  @@ -36,12 +35,12 @@
   {
      
      private ValueBinding<EntityManager> entityManager;
  -   private EntityIdentifierStore entityIdentifierStore;
  +   private EntityConverterStore entityIdentifierStore;
   
      @Create
      public void create()
      {
  -      entityIdentifierStore = EntityIdentifierStore.instance();
  +      entityIdentifierStore = EntityConverterStore.instance();
         if (getEntityManager() != null)
         {
            entityIdentifierStore.setEntityManager(getEntityManager());
  
  
  
  1.7       +40 -60    jboss-seam/src/ui/org/jboss/seam/ui/EntityConverterStore.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EntityConverterStore.java
  ===================================================================
  RCS file: EntityConverterStore.java
  diff -N EntityConverterStore.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ EntityConverterStore.java	15 Apr 2007 17:41:22 -0000	1.7
  @@ -0,0 +1,78 @@
  +package org.jboss.seam.ui;
  +
  +import static org.jboss.seam.annotations.Install.BUILT_IN;
  +import static org.jboss.seam.ScopeType.PAGE;
  +import static org.jboss.seam.InterceptionType.NEVER;
  +
  +import java.util.ArrayList;
  +import java.util.List;
  +
  +import org.jboss.seam.Component;
  +import org.jboss.seam.annotations.Install;
  +import org.jboss.seam.annotations.Intercept;
  +import org.jboss.seam.annotations.Name;
  +import org.jboss.seam.annotations.Scope;
  +import org.jboss.seam.annotations.Transactional;
  +import org.jboss.seam.contexts.Contexts;
  +import org.jboss.seam.framework.EntityIdentifier;
  +import org.jboss.seam.framework.MutableEntityController;
  +
  +/**
  + * Stores entity identifiers under a key, which can be used on a page
  + *
  + */
  +
  + at Name("org.jboss.seam.ui.entityConverterStore")
  + at Install(precedence=BUILT_IN)
  + at Scope(PAGE)
  + at Intercept(NEVER)
  +public class EntityConverterStore extends MutableEntityController
  +{
  +   
  +   private List<EntityIdentifier> store = new ArrayList<EntityIdentifier>();
  +   
  +   /**
  +    * Load and return the entity stored
  +    * @param key
  +    * @return The entity or null if no entity is available at that key
  +    */
  +   @Transactional
  +   public Object get(Integer key)
  +   {
  +      try
  +      {
  +         return store.get(key).find(getEntityManager());
  +      }
  +      catch (IndexOutOfBoundsException e)
  +      {
  +         return null;
  +      }   
  +      
  +   }
  +   
  +   /**
  +    * Store an entity id/clazz
  +    * @param entity The entity to store
  +    * @return The key under which the clazz/id are stored
  +    */
  +   @Transactional
  +   public Integer put(Object entity)
  +   {      
  +      EntityIdentifier key = new EntityIdentifier(entity, getEntityManager());
  +      if (!store.contains(key))
  +      {
  +         store.add(key);
  +         setDirty();
  +      }
  +      return store.indexOf(key);
  +   }
  +   
  +   public static EntityConverterStore instance() 
  +   {
  +      if (!Contexts.isPageContextActive())
  +      {
  +         throw new IllegalArgumentException("Page scope not active");
  +      }
  +      return (EntityConverterStore) Component.getInstance(EntityConverterStore.class);
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list