[seam-commits] Seam SVN: r8049 - in trunk: src/main/org/jboss/seam and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Apr 28 11:04:14 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-04-28 11:04:14 -0400 (Mon, 28 Apr 2008)
New Revision: 8049

Added:
   trunk/src/main/org/jboss/seam/ui-2.1.xsd
   trunk/ui/src/main/java/org/jboss/seam/ui/AbstractEntityLoader.java
   trunk/ui/src/main/java/org/jboss/seam/ui/EntityConverter.java
   trunk/ui/src/main/java/org/jboss/seam/ui/EntityIdentifierStore.java
   trunk/ui/src/main/java/org/jboss/seam/ui/HibernateEntityLoader.java
   trunk/ui/src/main/java/org/jboss/seam/ui/JpaEntityLoader.java
   trunk/ui/src/main/java/org/jboss/seam/ui/package-info.java
Removed:
   trunk/ui/src/main/java/org/jboss/seam/ui/converter/EntityConverter.java
   trunk/ui/src/main/java/org/jboss/seam/ui/converter/entityConverter/
Modified:
   trunk/seam21migration.txt
   trunk/ui/src/main/config/component/convertEntity.xml
Log:
Move entityConverter entity manager specification around and add an xsd

Modified: trunk/seam21migration.txt
===================================================================
--- trunk/seam21migration.txt	2008-04-28 15:01:17 UTC (rev 8048)
+++ trunk/seam21migration.txt	2008-04-28 15:04:14 UTC (rev 8049)
@@ -20,4 +20,11 @@
 ------------------
 
 The caught exception is now available in EL as #{org.jboss.seam.caughtException}
-rather than #{org.jboss.seam.exception}
\ No newline at end of file
+rather than #{org.jboss.seam.exception}
+
+
+EntityConverter configuration
+-----------------------------
+
+If you need to configure which entity manager to use, this is now done on the 
+entity-loader component. See the documentation for details. 
\ No newline at end of file

Added: trunk/src/main/org/jboss/seam/ui-2.1.xsd
===================================================================
--- trunk/src/main/org/jboss/seam/ui-2.1.xsd	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/ui-2.1.xsd	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
+    targetNamespace="http://jboss.com/products/seam/ui"
+    xmlns:ui="http://jboss.com/products/seam/ui"
+    xmlns:components="http://jboss.com/products/seam/components" attributeFormDefault="unqualified">
+    <xs:import namespace="http://jboss.com/products/seam/components" schemaLocation="components-2.1.xsd"/>
+    
+    <xs:element name="entity-loader">
+      <xs:complexType>
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attribute name="entity-manager" type="xs:string" />
+      </xs:complexType>
+    </xs:element>
+    
+    <xs:element name="hibernate-entity-loader">
+      <xs:complexType>
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attribute name="session" type="xs:string" />
+      </xs:complexType>
+    </xs:element>
+    
+    <xs:element name="entity-converter">
+      <xs:complexType>
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attribute name="entity-loader" type="xs:string" />
+      </xs:complexType>
+    </xs:element>
+    
+</xs:schema>


Property changes on: trunk/src/main/org/jboss/seam/ui-2.1.xsd
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/ui/src/main/config/component/convertEntity.xml
===================================================================
--- trunk/ui/src/main/config/component/convertEntity.xml	2008-04-28 15:01:17 UTC (rev 8048)
+++ trunk/ui/src/main/config/component/convertEntity.xml	2008-04-28 15:04:14 UTC (rev 8049)
@@ -4,7 +4,7 @@
 	<converter generate="false" >
 		<id>org.jboss.seam.ui.EntityConverter</id>
 		<family>org.jboss.seam.ui.EntityConverter</family>
-		<classname>org.jboss.seam.ui.converter.EntityConverter</classname>
+		<classname>org.jboss.seam.ui.EntityConverter</classname>
 		<description>
 			<![CDATA[Convert an entity.]]>
 		</description>

Copied: trunk/ui/src/main/java/org/jboss/seam/ui/AbstractEntityLoader.java (from rev 7958, trunk/ui/src/main/java/org/jboss/seam/ui/converter/entityConverter/AbstractEntityLoader.java)
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/AbstractEntityLoader.java	                        (rev 0)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/AbstractEntityLoader.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,58 @@
+package org.jboss.seam.ui;
+
+import static org.jboss.seam.ScopeType.STATELESS;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.annotations.Transactional;
+import org.jboss.seam.framework.Identifier;
+import org.jboss.seam.framework.PersistenceController;
+
+/**
+ * Helper class to load entities for the entity converter
+ * @author Pete Muir
+ *
+ */
+
+public abstract class AbstractEntityLoader<T> extends PersistenceController<T>
+{
+   
+   /**
+    * 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(String key)
+   {
+      Identifier identifier = EntityIdentifierStore.instance().get(key);
+      if (identifier != null)
+      {
+         return identifier.find(getPersistenceContext());
+      }
+      else
+      {
+         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 String put(Object entity)
+   {
+      return EntityIdentifierStore.instance().put(createIdentifier(entity), entity);
+   }
+   
+   protected abstract Identifier createIdentifier(Object entity);
+
+   public abstract void validate();
+   
+   public static AbstractEntityLoader instance()
+   {
+      return (AbstractEntityLoader) Component.getInstance("org.jboss.seam.ui.entityLoader", STATELESS);
+   }
+
+}
\ No newline at end of file


Property changes on: trunk/ui/src/main/java/org/jboss/seam/ui/AbstractEntityLoader.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ui/src/main/java/org/jboss/seam/ui/EntityConverter.java (from rev 7958, trunk/ui/src/main/java/org/jboss/seam/ui/converter/EntityConverter.java)
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/EntityConverter.java	                        (rev 0)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/EntityConverter.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,83 @@
+package org.jboss.seam.ui;
+
+import static org.jboss.seam.ScopeType.CONVERSATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.io.Serializable;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Transactional;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.annotations.faces.Converter;
+
+/**
+ * Allows conversion of an entity to/from a key which can be written to a page.
+ * 
+ * Support is provided for JPA (by default) and Hibernate (with the session 
+ * specified in components.xml)
+ */
+ at Name("org.jboss.seam.ui.EntityConverter")
+ at Scope(CONVERSATION)
+ at Install(precedence = BUILT_IN)
+ at Converter
+ at BypassInterceptors
+public class EntityConverter implements
+         javax.faces.convert.Converter, Serializable
+{
+   
+   private AbstractEntityLoader entityLoader;
+
+   public AbstractEntityLoader getEntityLoader()
+   {
+      return entityLoader;
+   }
+   
+   public void setEntityLoader(AbstractEntityLoader entityLoader)
+   {
+      this.entityLoader = entityLoader;
+   }
+   
+   @Create
+   public void create()
+   {
+      if (entityLoader == null)
+      {
+         entityLoader = AbstractEntityLoader.instance();
+      }
+      entityLoader.validate();
+   }
+   
+   @SuppressWarnings("unchecked")
+   @Transactional
+   public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) throws ConverterException
+   {
+      if (value == null)
+      {
+         return null;
+      }
+      if (value instanceof String) 
+      {
+         return (String) value;
+      }
+      return entityLoader.put(value);
+   }
+   
+
+   @Transactional
+   public Object getAsObject(FacesContext facesContext, UIComponent cmp, String value) throws ConverterException
+   {
+      if (value == null)
+      {
+         return null;
+      }
+      return entityLoader.get(value);
+   }
+   
+}


Property changes on: trunk/ui/src/main/java/org/jboss/seam/ui/EntityConverter.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ui/src/main/java/org/jboss/seam/ui/EntityIdentifierStore.java (from rev 7958, trunk/ui/src/main/java/org/jboss/seam/ui/converter/entityConverter/EntityIdentifierStore.java)
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/EntityIdentifierStore.java	                        (rev 0)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/EntityIdentifierStore.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,72 @@
+package org.jboss.seam.ui;
+
+import static org.jboss.seam.ScopeType.PAGE;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.AbstractMutable;
+import org.jboss.seam.framework.Identifier;
+
+/**
+ * Page scoped store for entity identifiers used by the EntityConverter.
+ * 
+ * By default a list is used and the key returned is the list index. The key
+ * used can be customised by overriding this component and implementing the
+ * get and put methods
+ * 
+ * @author Pete Muir
+ *
+ */
+ at Name("org.jboss.seam.ui.entityIdentifierStore")
+ at Install(precedence=BUILT_IN)
+ at Scope(PAGE)
+public class EntityIdentifierStore extends AbstractMutable
+{
+   
+   private List<Identifier> store;
+   
+   @Create
+   public void create()
+   {
+      store = new ArrayList<Identifier>();
+   }
+   
+   public Identifier get(String key)
+   {
+      try
+      {
+         return store.get(new Integer(key));
+      }
+      catch (IndexOutOfBoundsException e)
+      {
+         return null;
+      }   
+   }
+      
+   public String put(Identifier identifier, Object entity)
+   {      
+      if (!store.contains(identifier))
+      {
+         store.add(identifier);
+         setDirty();
+      }
+      return ((Integer) store.indexOf(identifier)).toString();
+   }
+
+   public static EntityIdentifierStore instance()
+   {
+      if (!Contexts.isPageContextActive())
+      {
+         throw new IllegalArgumentException("Page scope not active");
+      }
+      return (EntityIdentifierStore) Component.getInstance(EntityIdentifierStore.class, PAGE);
+   }
+}


Property changes on: trunk/ui/src/main/java/org/jboss/seam/ui/EntityIdentifierStore.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ui/src/main/java/org/jboss/seam/ui/HibernateEntityLoader.java (from rev 7958, trunk/ui/src/main/java/org/jboss/seam/ui/converter/entityConverter/HibernateEntityLoader.java)
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/HibernateEntityLoader.java	                        (rev 0)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/HibernateEntityLoader.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,57 @@
+package org.jboss.seam.ui;
+
+import static org.jboss.seam.ScopeType.STATELESS;
+import static org.jboss.seam.annotations.Install.FRAMEWORK;
+
+import org.hibernate.Session;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.framework.HibernateEntityIdentifier;
+import org.jboss.seam.framework.Identifier;
+
+/**
+ * Stores entity identifiers under a key, which can be used on a page
+ *
+ * @author Pete Muir
+ */
+
+ at Name("org.jboss.seam.ui.entityLoader")
+ at Install(precedence=FRAMEWORK, classDependencies="org.hibernate.Session", value=false)
+ at Scope(STATELESS)
+public class HibernateEntityLoader extends AbstractEntityLoader<Session>
+{
+
+   @Override
+   protected Identifier createIdentifier(Object entity)
+   {
+      return new HibernateEntityIdentifier(entity, getPersistenceContext());
+   }
+
+   @Override
+   protected String getPersistenceContextName()
+   {
+      return "session";
+   }
+
+   @Override
+   public void validate()
+   {
+      if (getPersistenceContext() == null)
+      {
+         throw new IllegalStateException("Unable to access a Seam Managed Hibernate Session. You must either have a Seam Managed Hibernate Session called session or configure one in components.xml");
+      }
+      
+   }
+   
+   public Session getSession()
+   {
+      return getPersistenceContext();
+   }
+   
+   public void setSession(Session session)
+   {
+      setPersistenceContext(session);
+   }
+
+}


Property changes on: trunk/ui/src/main/java/org/jboss/seam/ui/HibernateEntityLoader.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ui/src/main/java/org/jboss/seam/ui/JpaEntityLoader.java (from rev 7958, trunk/ui/src/main/java/org/jboss/seam/ui/converter/entityConverter/EntityLoader.java)
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/JpaEntityLoader.java	                        (rev 0)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/JpaEntityLoader.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,58 @@
+package org.jboss.seam.ui;
+
+import static org.jboss.seam.ScopeType.STATELESS;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.framework.EntityIdentifier;
+import org.jboss.seam.framework.Identifier;
+
+/**
+ * Stores entity identifiers under a key, which can be used on a page
+ *
+ * @author Pete Muir
+ */
+
+ at Name("org.jboss.seam.ui.entityLoader")
+ at Install(precedence=BUILT_IN, value=true, classDependencies="javax.persistence.EntityManager")
+ at Scope(STATELESS)
+public class JpaEntityLoader extends AbstractEntityLoader<EntityManager>
+{
+
+   @Override
+   protected Identifier createIdentifier(Object entity)
+   {
+      return new EntityIdentifier(entity, getPersistenceContext());
+   }
+
+   @Override
+   protected String getPersistenceContextName()
+   {
+      return "entityManager";
+   }
+   
+   @Override
+   public void validate()
+   {
+      if (getPersistenceContext() == null)
+      {
+         throw new IllegalStateException("Unable to access a persistence context. You must either have a SMPC called entityManager or configure one in components.xml");
+      }
+      
+   }
+   
+   public EntityManager getEntityManager()
+   {
+      return getPersistenceContext();
+   }
+
+   public void setEntityManager(EntityManager entityManager)
+   {
+      setPersistenceContext(entityManager);
+   }
+   
+}


Property changes on: trunk/ui/src/main/java/org/jboss/seam/ui/JpaEntityLoader.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Deleted: trunk/ui/src/main/java/org/jboss/seam/ui/converter/EntityConverter.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/converter/EntityConverter.java	2008-04-28 15:01:17 UTC (rev 8048)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/converter/EntityConverter.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -1,125 +0,0 @@
-package org.jboss.seam.ui.converter;
-
-import static org.jboss.seam.ScopeType.CONVERSATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.Serializable;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.ConverterException;
-
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Transactional;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.annotations.faces.Converter;
-import org.jboss.seam.core.Expressions.ValueExpression;
-import org.jboss.seam.ui.converter.entityConverter.EntityLoader;
-import org.jboss.seam.ui.converter.entityConverter.HibernateEntityLoader;
-import org.jboss.seam.ui.converter.entityConverter.AbstractEntityLoader;
-
-/**
- * Allows conversion of an entity to/from a key which can be written to a page.
- * 
- * Support is provided for JPA (by default) and Hibernate (with the session 
- * specified in components.xml)
- */
- at Name("org.jboss.seam.ui.EntityConverter")
- at Scope(CONVERSATION)
- at Install(precedence = BUILT_IN)
- at Converter
- at BypassInterceptors
-public class EntityConverter implements
-         javax.faces.convert.Converter, Serializable
-{
-   
-   private ValueExpression entityManager;
-   private ValueExpression session;
-   private AbstractEntityLoader store;
-
-   @Create
-   public void create()
-   {
-      if (getEntityManager() == null && getSession() != null)
-      {
-         store = HibernateEntityLoader.instance();
-      }
-      else
-      {
-         store = EntityLoader.instance();
-      }
-   }
-   
-   private void init()
-   {
-      if (getPersistenceContext() != null)
-      {
-         store.setPersistenceContext(getPersistenceContext().getValue());
-      }
-      store.validate();
-   }
-   
-   @SuppressWarnings("unchecked")
-   @Transactional
-   public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) throws ConverterException
-   {
-      init();
-      if (value == null)
-      {
-         return null;
-      }
-      if (value instanceof String) 
-      {
-         return (String) value;
-      }
-      return store.put(value);
-   }
-   
-
-   @Transactional
-   public Object getAsObject(FacesContext facesContext, UIComponent cmp, String value) throws ConverterException
-   {
-      init();
-      if (value == null)
-      {
-         return null;
-      }
-      return store.get(value);
-   }
-   
-   public ValueExpression getEntityManager()
-   {
-      return entityManager; 
-   }
-   
-   public void setEntityManager(ValueExpression entityManager)
-   {
-      this.entityManager = entityManager;
-   }
-   
-   public ValueExpression getSession()
-   {
-      return session;
-   }
-   
-   public void setSession(ValueExpression session)
-   {
-      this.session = session;
-   }
-   
-   private ValueExpression getPersistenceContext() 
-   {
-      if (getEntityManager() != null)
-      {
-         return getEntityManager();
-      }
-      else
-      {
-         return getSession();
-      }
-   }
-   
-}
\ No newline at end of file

Added: trunk/ui/src/main/java/org/jboss/seam/ui/package-info.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/package-info.java	                        (rev 0)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/package-info.java	2008-04-28 15:04:14 UTC (rev 8049)
@@ -0,0 +1,10 @@
+/**
+ * Seam UI
+ * 
+ */
+ at Namespace(value="http://jboss.com/products/seam/ui", prefix="org.jboss.seam.ui")
+ at AutoCreate
+package org.jboss.seam.ui;
+
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.Namespace;


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




More information about the seam-commits mailing list