[jboss-cvs] jboss-seam/src/main/org/jboss/seam ...
Gavin King
gavin.king at jboss.com
Wed Jul 26 17:51:04 EDT 2006
User: gavin
Date: 06/07/26 17:51:04
Modified: src/main/org/jboss/seam Component.java
Added: src/main/org/jboss/seam InterceptorType.java
Log:
client-side interceptors
Revision Changes Path
1.154 +60 -20 jboss-seam/src/main/org/jboss/seam/Component.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Component.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Component.java,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -b -r1.153 -r1.154
--- Component.java 26 Jul 2006 01:29:21 -0000 1.153
+++ Component.java 26 Jul 2006 21:51:04 -0000 1.154
@@ -65,6 +65,7 @@
import org.jboss.seam.databinding.DataSelector;
import org.jboss.seam.interceptors.BijectionInterceptor;
import org.jboss.seam.interceptors.BusinessProcessInterceptor;
+import org.jboss.seam.interceptors.ClientSideInterceptor;
import org.jboss.seam.interceptors.ConversationInterceptor;
import org.jboss.seam.interceptors.ConversationalInterceptor;
import org.jboss.seam.interceptors.ExceptionInterceptor;
@@ -88,7 +89,7 @@
*
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
* @author Gavin King
- * @version $Revision: 1.153 $
+ * @version $Revision: 1.154 $
*/
@Scope(ScopeType.APPLICATION)
public class Component
@@ -136,6 +137,7 @@
private Hashtable<Locale, ClassValidator> validators = new Hashtable<Locale, ClassValidator>();
private List<Interceptor> interceptors = new ArrayList<Interceptor>();
+ private List<Interceptor> clientSideInterceptors = new ArrayList<Interceptor>();
private Set<Class> businessInterfaces;
@@ -209,10 +211,10 @@
initInitializers(applicationContext);
- if (type==ComponentType.JAVA_BEAN)
- {
+ /*if (type==ComponentType.JAVA_BEAN)
+ {*/
factory = createProxyFactory();
- }
+ //}
}
@@ -570,7 +572,7 @@
{
if ( annotation.annotationType().isAnnotationPresent(Interceptors.class) )
{
- interceptors.add( new Interceptor(annotation, this) );
+ addInterceptor( new Interceptor(annotation, this) );
}
}
@@ -579,6 +581,18 @@
if ( log.isDebugEnabled() ) log.debug("interceptor stack: " + interceptors);
}
+ private void addInterceptor(Interceptor interceptor)
+ {
+ if ( interceptor.getType()==InterceptorType.SERVER)
+ {
+ interceptors.add(interceptor);
+ }
+ else
+ {
+ clientSideInterceptors.add(interceptor);
+ }
+ }
+
private List<Interceptor> newSort(List<Interceptor> list)
{
List<SortItem<Interceptor>> siList = new ArrayList<SortItem<Interceptor>>();
@@ -625,19 +639,23 @@
private void initDefaultInterceptors()
{
- interceptors.add( new Interceptor( new ExceptionInterceptor(), this ) );
- interceptors.add( new Interceptor( new RemoveInterceptor(), this ) );
- interceptors.add( new Interceptor( new ConversationalInterceptor(), this ) );
- interceptors.add( new Interceptor( new BusinessProcessInterceptor(), this ) );
- interceptors.add( new Interceptor( new ConversationInterceptor(), this ) );
- interceptors.add( new Interceptor( new OutcomeInterceptor(), this ) );
- interceptors.add( new Interceptor( new BijectionInterceptor(), this ) );
- interceptors.add( new Interceptor( new ValidationInterceptor(), this ) );
- interceptors.add( new Interceptor( new RollbackInterceptor(), this ) );
+ addInterceptor( new Interceptor( new ExceptionInterceptor(), this ) );
+ addInterceptor( new Interceptor( new RemoveInterceptor(), this ) );
+ addInterceptor( new Interceptor( new ConversationalInterceptor(), this ) );
+ addInterceptor( new Interceptor( new BusinessProcessInterceptor(), this ) );
+ addInterceptor( new Interceptor( new ConversationInterceptor(), this ) );
+ addInterceptor( new Interceptor( new OutcomeInterceptor(), this ) );
+ addInterceptor( new Interceptor( new BijectionInterceptor(), this ) );
+ addInterceptor( new Interceptor( new ValidationInterceptor(), this ) );
+ addInterceptor( new Interceptor( new RollbackInterceptor(), this ) );
if ( getType()==ComponentType.JAVA_BEAN )
{
- interceptors.add( new Interceptor( new TransactionInterceptor(), this ) );
+ addInterceptor( new Interceptor( new TransactionInterceptor(), this ) );
}
+ /*else
+ {
+ addInterceptor( new Interceptor( new EJBExceptionInterceptor(), this ) );
+ }*/
}
public Class<?> getBeanClass()
@@ -677,9 +695,19 @@
return validator;
}
- public List<Interceptor> getInterceptors()
+ public List<Interceptor> getInterceptors(InterceptorType type)
+ {
+ switch(type)
{
- return interceptors;
+ case SERVER: return interceptors;
+ case CLIENT: return clientSideInterceptors;
+ case ANY:
+ List<Interceptor> all = new ArrayList<Interceptor>();
+ all.addAll(clientSideInterceptors);
+ all.addAll(interceptors);
+ return all;
+ default: throw new IllegalArgumentException("no interceptor type specified");
+ }
}
public Method getDestroyMethod()
@@ -773,14 +801,14 @@
{
Factory bean = factory.newInstance();
initialize(bean);
- bean.setCallback( 0, new JavaBeanInterceptor() );
+ bean.setCallback( 0, new JavaBeanInterceptor(this) );
return bean;
}
case ENTITY_BEAN:
return beanClass.newInstance();
case STATELESS_SESSION_BEAN:
case STATEFUL_SESSION_BEAN:
- return Naming.getInitialContext().lookup(jndiName);
+ return wrap( Naming.getInitialContext().lookup(jndiName) );
case MESSAGE_DRIVEN_BEAN:
throw new UnsupportedOperationException("Message-driven beans may not be called: " + name);
default:
@@ -788,6 +816,13 @@
}
}
+ private Object wrap(Object bean) throws Exception
+ {
+ Factory proxy = factory.newInstance();
+ proxy.setCallback( 0, new ClientSideInterceptor(bean, this) );
+ return proxy;
+ }
+
public void initialize(Object bean) throws Exception
{
if ( log.isDebugEnabled() ) log.debug("initializing new instance of: " + name);
@@ -1543,7 +1578,12 @@
en.setUseCache(false);
en.setInterceptDuringConstruction(false);
en.setCallbackType(MethodInterceptor.class);
- en.setSuperclass(beanClass);
+ en.setSuperclass( type==ComponentType.JAVA_BEAN ? beanClass : Object.class );
+ Set<Class> interfaces = getBusinessInterfaces();
+ if (interfaces.size()>0)
+ {
+ en.setInterfaces( interfaces.toArray( new Class[0] ) );
+ }
return (Class<Factory>) en.createClass();
}
1.1 date: 2006/07/26 21:51:04; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/InterceptorType.java
Index: InterceptorType.java
===================================================================
package org.jboss.seam;
public enum InterceptorType
{
CLIENT,
SERVER,
ANY
}
More information about the jboss-cvs-commits
mailing list