[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...
Gavin King
gavin.king at jboss.com
Wed Sep 27 19:14:42 EDT 2006
User: gavin
Date: 06/09/27 19:14:42
Modified: src/main/org/jboss/seam/interceptors
ManagedEntityIdentityInterceptor.java
Log:
propagate page parameters across navigation rule redirects
improvements to framework
Revision Changes Path
1.4 +8 -27 jboss-seam/src/main/org/jboss/seam/interceptors/ManagedEntityIdentityInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ManagedEntityIdentityInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/ManagedEntityIdentityInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ManagedEntityIdentityInterceptor.java 27 Sep 2006 03:53:49 -0000 1.3
+++ ManagedEntityIdentityInterceptor.java 27 Sep 2006 23:14:42 -0000 1.4
@@ -2,7 +2,6 @@
import java.io.Serializable;
import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
@@ -11,12 +10,12 @@
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.persistence.EntityManager;
-import javax.persistence.Id;
import org.hibernate.Session;
import org.jboss.seam.Component;
import org.jboss.seam.Seam;
import org.jboss.seam.core.TouchedContexts;
+import org.jboss.seam.util.Persistence;
import org.jboss.seam.util.Reflections;
/**
@@ -102,19 +101,25 @@
{
Object persistenceContext = Component.getInstance(persistenceContextName);
boolean managed;
+ Object id;
if (persistenceContext instanceof EntityManager)
{
EntityManager em = (EntityManager) persistenceContext;
managed = em.contains(value);
+ id = managed ? Persistence.getId(value, em) : null;
}
else
{
Session session = (Session) persistenceContext;
managed = session.contains(value);
+ id = managed ? session.getIdentifier(value) : null;
}
if (managed)
{
- Object id = getId(value, entityClass);
+ if (id==null)
+ {
+ throw new IllegalStateException("could not get id of: " + beanClass.getName() + '.' + field.getName());
+ }
list.add( new PassivatedEntity( id, entityClass, field.getName(), persistenceContextName ) );
Reflections.set(field, bean, null);
break;
@@ -164,28 +169,4 @@
}
}
- private static Object getId(Object bean, Class entityClass) throws Exception
- {
- for (Class beanClass=entityClass; beanClass!=Object.class; beanClass=beanClass.getSuperclass() )
- {
- for (Field field: beanClass.getDeclaredFields()) //TODO: superclasses
- {
- if ( field.isAnnotationPresent(Id.class) )
- {
- if ( !field.isAccessible() ) field.setAccessible(true);
- return Reflections.get(field, bean);
- }
- }
- for (Method method: beanClass.getDeclaredMethods())
- {
- if ( method.isAnnotationPresent(Id.class) )
- {
- if ( !method.isAccessible() ) method.setAccessible(true);
- return Reflections.invoke(method, bean);
- }
- }
- }
- throw new IllegalArgumentException("no id property found for entity class: " + entityClass.getName());
- }
-
}
More information about the jboss-cvs-commits
mailing list