Author: nickarls
Date: 2008-12-03 06:46:14 -0500 (Wed, 03 Dec 2008)
New Revision: 392
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java
Log:
fix tests, change exception handling in proxy pool
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-03
11:40:01 UTC (rev 391)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-03
11:46:14 UTC (rev 392)
@@ -28,7 +28,6 @@
import javassist.util.proxy.ProxyObject;
import javax.webbeans.DefinitionException;
-import javax.webbeans.UnproxyableDependencyException;
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
@@ -146,13 +145,25 @@
* @throws IllegalAccessException When the proxy couldn't be created
*/
@SuppressWarnings("unchecked")
- private <T> T createClientProxy(Bean<T> bean, int beanIndex) throws
InstantiationException, IllegalAccessException
+ private <T> T createClientProxy(Bean<T> bean, int beanIndex) throws
RuntimeException
{
ProxyFactory proxyFactory = new ProxyFactory();
TypeInfo typeInfo = getTypeInfo(bean.getTypes());
proxyFactory.setInterfaces(typeInfo.interfaces);
proxyFactory.setSuperclass(typeInfo.superclass);
- T clientProxy = (T) proxyFactory.createClass().newInstance();
+ T clientProxy;
+ try
+ {
+ clientProxy = (T) proxyFactory.createClass().newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException("Could not instantiate client proxy for " +
bean, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException("Could not access bean correctly when creating
client proxy for " + bean, e);
+ }
ProxyMethodHandler proxyMethodHandler = new ProxyMethodHandler(bean, beanIndex,
manager);
((ProxyObject) clientProxy).setHandler(proxyMethodHandler);
return clientProxy;
@@ -172,24 +183,13 @@
Object clientProxy = pool.get(bean);
if (clientProxy == null)
{
- try
+ int beanIndex = manager.getBeans().indexOf(bean);
+ if (beanIndex < 0)
{
- int beanIndex = manager.getBeans().indexOf(bean);
- if (beanIndex < 0)
- {
- throw new DefinitionException(bean + " is not known to the
manager");
- }
- clientProxy = createClientProxy(bean, beanIndex);
+ throw new DefinitionException(bean + " is not known to the
manager");
}
- catch (DefinitionException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- // TODO: What to *really* do here?
- throw new UnproxyableDependencyException("Could not create client proxy
for " + bean.getName(), e);
- }
+ clientProxy = createClientProxy(bean, beanIndex);
+
pool.put(bean, clientProxy);
}
return clientProxy;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java 2008-12-03
11:40:01 UTC (rev 391)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java 2008-12-03
11:46:14 UTC (rev 392)
@@ -27,6 +27,7 @@
public void testReflectionsUsedForNormalScope()
{
Bean<Tuna> tunaBean = BeanFactory.createSimpleBean(Tuna.class, manager);
+ manager.addBean(tunaBean);
Tuna tuna = manager.getInstance(tunaBean);
assert Reflections.isProxy(tuna);
}
@@ -57,6 +58,7 @@
public void testSimpleWebBeanReflectionsIsSerializable() throws IOException,
ClassNotFoundException
{
Bean<TunedTuna> tunaBean = BeanFactory.createSimpleBean(TunedTuna.class,
manager);
+ manager.addBean(tunaBean);
TunedTuna tuna = manager.getInstance(tunaBean);
assert Reflections.isProxy(tuna);
byte[] bytes = serializeBean(tuna);
Show replies by date