[seam-commits] Seam SVN: r7698 - trunk/src/main/org/jboss/seam/security/management.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Mar 25 21:17:30 EDT 2008


Author: shane.bryzak at jboss.com
Date: 2008-03-25 21:17:30 -0400 (Tue, 25 Mar 2008)
New Revision: 7698

Modified:
   trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
Log:
set entityManager via value expression

Modified: trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java	2008-03-26 00:43:27 UTC (rev 7697)
+++ trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java	2008-03-26 01:17:30 UTC (rev 7698)
@@ -9,16 +9,17 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.el.ValueExpression;
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
 
-import org.jboss.seam.Component;
 import org.jboss.seam.annotations.Create;
 import org.jboss.seam.annotations.Observer;
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.Events;
+import org.jboss.seam.core.Expressions;
 import org.jboss.seam.security.Identity;
 import org.jboss.seam.security.management.UserAccount.AccountType;
 
@@ -38,7 +39,7 @@
    
    protected FeatureSet featureSet = new FeatureSet(FeatureSet.FEATURE_ALL);
    
-   private String entityManagerName = "entityManager";
+   private ValueExpression entityManager;  
    
    private Class<? extends UserAccount> accountClass;
    
@@ -67,7 +68,7 @@
    
    protected void loadRoles()
    {
-      List<? extends UserAccount> roles = getEntityManager().createQuery(
+      List<? extends UserAccount> roles = lookupEntityManager().createQuery(
             "from " + accountClass.getName() + " where enabled = true and accountType = :accountType")
             .setParameter("accountType", UserAccount.AccountType.role)
             .getResultList();
@@ -140,7 +141,7 @@
          throw new NoSuchUserException("Could not delete account, no such user '" + name + "'");
       }
       
-      getEntityManager().remove(account);
+      lookupEntityManager().remove(account);
       return true;
    }
    
@@ -235,7 +236,7 @@
          throw new NoSuchRoleException("Could not delete role, role '" + role + "' does not exist");
       }        
       
-      getEntityManager().remove(roleToDelete);
+      lookupEntityManager().remove(roleToDelete);
       return true;
    }
    
@@ -401,7 +402,7 @@
    {
       try
       {
-         UserAccount account = (UserAccount) getEntityManager().createQuery(
+         UserAccount account = (UserAccount) lookupEntityManager().createQuery(
             "from " + accountClass.getName() + " where username = :username")
             .setParameter("username", name)
             .getSingleResult();
@@ -428,7 +429,7 @@
    
    public List<String> listUsers()
    {
-      return getEntityManager().createQuery(
+      return lookupEntityManager().createQuery(
             "select username from " + accountClass.getName() + 
             " where accountType = :accountType")
             .setParameter("accountType", AccountType.user)
@@ -437,7 +438,7 @@
    
    public List<String> listUsers(String filter)
    {
-      return getEntityManager().createQuery(
+      return lookupEntityManager().createQuery(
             "select username from " + accountClass.getName() + 
             " where accountType = :accountType and lower(username) like :username")
             .setParameter("accountType", AccountType.user)
@@ -448,7 +449,7 @@
 
    public List<String> listRoles()
    {
-      return getEntityManager().createQuery(
+      return lookupEntityManager().createQuery(
             "select username from " + accountClass.getName() + 
             " where accountType = :accountType")
             .setParameter("accountType", AccountType.role)
@@ -457,12 +458,12 @@
    
    protected void persistAccount(UserAccount account)
    {
-      getEntityManager().persist(account);
+      lookupEntityManager().persist(account);
    }
    
    protected UserAccount mergeAccount(UserAccount account)
    {
-      return getEntityManager().merge(account);
+      return lookupEntityManager().merge(account);
    }
    
    public Class<? extends UserAccount> getAccountClass()
@@ -475,18 +476,18 @@
       this.accountClass = accountClass;
    }   
    
-   private EntityManager getEntityManager()
+   private EntityManager lookupEntityManager()
    {
-      return (EntityManager) Component.getInstance(entityManagerName);
+      return (EntityManager) entityManager.getValue(Expressions.instance().getELContext());
    }
    
-   public String getEntityManagerName()
+   public ValueExpression getEntityManager()
    {
-      return entityManagerName;
+      return entityManager;
    }
    
-   public void setEntityManagerName(String name)
+   public void setEntityManager(ValueExpression expression)
    {
-      this.entityManagerName = name;
+      this.entityManager = expression;
    }         
 }




More information about the seam-commits mailing list