[webbeans-commits] Webbeans SVN: r3337 - ri/trunk/impl/src/main/java/org/jboss/webbeans/bean and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Jul 28 19:43:43 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-07-28 19:43:43 -0400 (Tue, 28 Jul 2009)
New Revision: 3337
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/DecoratorProxyMethodHandler.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/BasicLogger.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/InjectableReferenceTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/TimestampLogger.java
Log:
Fix storage of decorator bean instances, fix up test to actually test what it needs to, support non-public classes in RI
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-07-28 23:41:42 UTC (rev 3336)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -549,6 +549,7 @@
public void addDecorator(DecoratorBean<?> bean)
{
decorators.add(bean);
+ riBeans.put(bean.getId(), bean);
decoratorResolver.clear();
}
@@ -742,7 +743,8 @@
}
/**
- * The beans registered with the Web Bean manager. For internal use
+ * The beans registered with the Web Bean manager which are resolvable. Does
+ * not include interceptor and decorator beans
*
* @return The list of known beans
*/
@@ -756,6 +758,18 @@
return Collections.unmodifiableList(decorators);
}
+ /**
+ * Get all the spec defined beans, including interceptor beans and decorator
+ * beans. This is behavior is different to getBeans() which returns only
+ * resolvable beans.
+ *
+ * TODO Rename method, merge into whatever we use for passivation capable or
+ * split out decorators
+ *
+ * WARNING, method will go away!
+ *
+ * @return
+ */
public Map<String, RIBean<?>> getRiBeans()
{
return Collections.unmodifiableMap(riBeans);
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java 2009-07-28 23:41:42 UTC (rev 3336)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.webbeans.bean;
-
-import java.io.Serializable;
-
-import org.jboss.webbeans.BeanManagerImpl;
-
-public class SerializableBeanInstance<T extends RIBean<I>, I> implements Serializable
-{
-
- private static final long serialVersionUID = 7341389081613003687L;
-
- private final BeanManagerImpl manager;
- private final String beanId;
- private final I instance;
-
- public SerializableBeanInstance(T bean, I instance)
- {
- this.manager = bean.getManager();
- this.beanId = bean.getId();
- this.instance = instance;
- }
-
- @SuppressWarnings("unchecked")
- public T getBean()
- {
- return (T) manager.getRiBeans().get(beanId);
- }
-
- public I getInstance()
- {
- return instance;
- }
-
-}
\ No newline at end of file
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SerializableBeanInstance.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean;
+
+import java.io.Serializable;
+
+import org.jboss.webbeans.BeanManagerImpl;
+
+public class SerializableBeanInstance<T extends RIBean<I>, I> implements Serializable
+{
+
+ private static final long serialVersionUID = 7341389081613003687L;
+
+ private final BeanManagerImpl manager;
+ private final String beanId;
+ private final I instance;
+
+ public SerializableBeanInstance(T bean, I instance)
+ {
+ this.manager = bean.getManager();
+ this.beanId = bean.getId();
+ this.instance = instance;
+ }
+
+ @SuppressWarnings("unchecked")
+ public T getBean()
+ {
+ return (T) manager.getRiBeans().get(beanId);
+ }
+
+ protected BeanManagerImpl getManager()
+ {
+ return manager;
+ }
+
+ protected String getBeanId()
+ {
+ return beanId;
+ }
+
+ public I getInstance()
+ {
+ return instance;
+ }
+
+}
\ No newline at end of file
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/DecoratorProxyMethodHandler.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/DecoratorProxyMethodHandler.java 2009-07-28 23:41:42 UTC (rev 3336)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/DecoratorProxyMethodHandler.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -16,6 +16,8 @@
*/
package org.jboss.webbeans.bean.proxy;
+import static org.jboss.webbeans.util.Reflections.ensureAccessible;
+
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.List;
@@ -83,7 +85,8 @@
return decoratorMethod.invokeOnInstance(beanInstance.getInstance(), args);
}
}
- return method.invoke(instance, args);
+
+ return ensureAccessible(method).invoke(instance, args);
}
}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/BasicLogger.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/BasicLogger.java 2009-07-28 23:41:42 UTC (rev 3336)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/BasicLogger.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -1,20 +1,11 @@
package org.jboss.jsr299.tck.tests.lookup.injectionpoint;
-import javax.enterprise.inject.Current;
-import javax.enterprise.inject.spi.InjectionPoint;
class BasicLogger implements Logger
{
- @Current
- private InjectionPoint injectionPoint;
private static String message;
- public InjectionPoint getInjectionPoint()
- {
- return injectionPoint;
- }
-
public String getMessage()
{
return message;
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/InjectableReferenceTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/InjectableReferenceTest.java 2009-07-28 23:41:42 UTC (rev 3336)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/InjectableReferenceTest.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -69,13 +69,28 @@
// WBRI-296
public void testGetInjectableReferenceReturnsDelegateForDelegateInjectionPoint()
{
- // Get the consumer of the logger and work back from there to get the injection point
- LoggerConsumer loggerConsumer = getInstanceByType(LoggerConsumer.class);
- loggerConsumer.doSomething();
- BasicLogger delegateLogger = (BasicLogger) TimestampLogger.getLogger();
- InjectionPoint loggerInjectionPoint = delegateLogger.getInjectionPoint();
+ // Get hold of the correct IP by inspecting the ones the container created for LoggerConsumer
+ assert getBeans(LoggerConsumer.class).size() == 1;
+ Bean<LoggerConsumer> bean = getBeans(LoggerConsumer.class).iterator().next();
+ InjectionPoint loggerInjectionPoint = null;
+ for (InjectionPoint ip : bean.getInjectionPoints())
+ {
+ if (ip.getAnnotated().getTypeClosure().contains(Logger.class) && ip.getBindings().size() == 1 && ip.getBindings().contains(new CurrentLiteral()))
+ {
+ loggerInjectionPoint = ip;
+ }
+ }
+
+ // Now lookup an injectable reference and check that it is of type Logger
CreationalContext<Logger> creationalContext = getCurrentManager().createCreationalContext((Bean<Logger>)loggerInjectionPoint.getBean());
Object injectedDelegateLogger = getCurrentManager().getInjectableReference(loggerInjectionPoint, creationalContext);
- assert injectedDelegateLogger instanceof BasicLogger;
+ assert injectedDelegateLogger instanceof Logger;
+ Logger logger = (Logger) injectedDelegateLogger;
+
+ // User the logger
+ String message = "foo123";
+ TimestampLogger.reset();
+ logger.log(message);
+ assert message.equals(TimestampLogger.getLoggedMessage());
}
}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/TimestampLogger.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/TimestampLogger.java 2009-07-28 23:41:42 UTC (rev 3336)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/injectionpoint/TimestampLogger.java 2009-07-28 23:43:43 UTC (rev 3337)
@@ -12,10 +12,13 @@
private Logger logger;
private static Logger staticLogger;
+
+ private static String loggedMessage;
public void log(String message)
{
staticLogger = logger;
+ loggedMessage = message;
logger.log(new Date().toString() + ": " + message);
}
@@ -23,5 +26,19 @@
{
return staticLogger;
}
+
+ /**
+ * @return the loggedMessage
+ */
+ public static String getLoggedMessage()
+ {
+ return loggedMessage;
+ }
+
+ public static void reset()
+ {
+ loggedMessage = null;
+ staticLogger = null;
+ }
}
More information about the weld-commits
mailing list