You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2018/12/18 06:58:05 UTC
svn commit: r1849151 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/configurator/
main/java/org/apache/webbeans/util/
test/java/org/apache/webbeans/test/configurator/
test/java/org/apache/webbeans/test/events/container/
Author: rmannibucau
Date: Tue Dec 18 06:58:05 2018
New Revision: 1849151
URL: http://svn.apache.org/viewvc?rev=1849151&view=rev
Log:
OWB-1273 OWB-1274 OWB-1275 enhance configurator (passivationid and scope implicitly when relevant) + ensure we filter container event even on Parameterized types
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/DefaultQualifierTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/container/WildcardExtensionMatchingTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java?rev=1849151&r1=1849150&r2=1849151&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java Tue Dec 18 06:58:05 2018
@@ -40,6 +40,8 @@ import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
+import org.apache.webbeans.annotation.AnyLiteral;
+import org.apache.webbeans.annotation.DefaultLiteral;
import org.apache.webbeans.component.OwbBean;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.component.creation.BeanAttributesBuilder;
@@ -319,6 +321,22 @@ public class BeanConfiguratorImpl<T> imp
public Bean<?> getBean()
{
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(DefaultLiteral.INSTANCE);
+ qualifiers.add(AnyLiteral.INSTANCE);
+ }
+ if (scope != null && webBeansContext.getBeanManagerImpl().isPassivatingScope(scope) && passivationId == null)
+ {
+ final StringBuilder sb = new StringBuilder("CONFIGURATOR#");
+ sb.append(beanClass != null ? beanClass : typeClosures.stream().filter(Class.class::isInstance).findFirst()
+ .orElse(Object.class)).append('#');
+ for (final Annotation qualifier : qualifiers)
+ {
+ sb.append(qualifier.toString()).append(',');
+ }
+ passivationId = sb.toString();
+ }
return new ConstructedBean();
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1849151&r1=1849150&r2=1849151&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Tue Dec 18 06:58:05 2018
@@ -638,25 +638,25 @@ public final class ClassUtil
if(clazzUpperBoundTypeArg != Object.class)
{
if(!clazzUpperBoundTypeArg.isAssignableFrom(clazzBeanTypeArg))
- {
+ {
return false;
}
}
-
+
//Check lower bounds
if(lowerBoundRequiredTypeArgs.length > 0 && lowerBoundRequiredTypeArgs[0] instanceof Class)
{
Class<?> clazzLowerBoundTypeArg = (Class<?>)lowerBoundRequiredTypeArgs[0];
-
+
if(clazzLowerBoundTypeArg != Object.class)
{
if(!clazzBeanTypeArg.isAssignableFrom(clazzLowerBoundTypeArg))
{
return false;
- }
+ }
}
}
- }
+ }
}
else if(isTypeVariable(beanTypeArg))
{
@@ -694,6 +694,35 @@ public final class ClassUtil
}
}
}
+ else if (beanTypeArg instanceof ParameterizedType)
+ {
+ final ParameterizedType pt = (ParameterizedType) beanTypeArg;
+ if(pt.getRawType() instanceof Class && upperBoundRequiredTypeArg instanceof Class)
+ {
+ final Class<?> beanRawClass = (Class) pt.getRawType();
+
+ //Check upper bounds
+ Class<?> clazzUpperBoundTypeArg = (Class<?>)upperBoundRequiredTypeArg;
+ if(clazzUpperBoundTypeArg != Object.class)
+ {
+ if(!clazzUpperBoundTypeArg.isAssignableFrom(beanRawClass))
+ {
+ return false;
+ }
+ }
+
+ //Check lower bounds
+ if(lowerBoundRequiredTypeArgs.length > 0 && lowerBoundRequiredTypeArgs[0] instanceof Class)
+ {
+ Class<?> clazzLowerBoundTypeArg = (Class<?>)lowerBoundRequiredTypeArgs[0];
+
+ if(clazzLowerBoundTypeArg != Object.class && !beanRawClass.isAssignableFrom(clazzLowerBoundTypeArg))
+ {
+ return false;
+ }
+ }
+ }
+ }
return true;
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/DefaultQualifierTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/DefaultQualifierTest.java?rev=1849151&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/DefaultQualifierTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/DefaultQualifierTest.java Tue Dec 18 06:58:05 2018
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.test.configurator;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+public class DefaultQualifierTest extends AbstractUnitTest {
+ @Test
+ public void start() {
+ addExtension(new Extension() {
+ void addBean(@Observes final AfterBeanDiscovery afterBeanDiscovery) {
+ afterBeanDiscovery.addBean()
+ .addTransitiveTypeClosure(String.class)
+ .createWith(cc -> null)
+ .scope(Dependent.class);
+ }
+ });
+ startContainer();
+ final Bean<String> bean = getBean(String.class);
+ assertEquals(2, bean.getQualifiers().size());
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/container/WildcardExtensionMatchingTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/container/WildcardExtensionMatchingTest.java?rev=1849151&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/container/WildcardExtensionMatchingTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/container/WildcardExtensionMatchingTest.java Tue Dec 18 06:58:05 2018
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.webbeans.test.events.container;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.junit.Assert.assertEquals;
+
+import java.lang.annotation.Retention;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Intercepted;
+import javax.enterprise.inject.literal.NamedLiteral;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.ProcessInjectionPoint;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBinding;
+import javax.interceptor.InvocationContext;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+public class WildcardExtensionMatchingTest extends AbstractUnitTest {
+ @Test
+ public void injectionPoint() {
+ final Collection<InjectionPoint> points = new ArrayList<>();
+ addExtension(new Extension() {
+ void add(@Observes final AfterBeanDiscovery afterBeanDiscovery) {
+ afterBeanDiscovery.addBean()
+ .id("v1")
+ .types(String.class, Object.class)
+ .createWith(c -> "ok")
+ .beanClass(MyBean.class)
+ .qualifiers(NamedLiteral.of("v1"))
+ .scope(Dependent.class);
+ afterBeanDiscovery.addBean()
+ .id("v2")
+ .types(Boolean.class, Object.class)
+ .createWith(c -> 1)
+ .beanClass(MyBean.class)
+ .qualifiers(NamedLiteral.of("v2"))
+ .scope(Dependent.class);
+ }
+
+ private void processInjectionPoint(@Observes final ProcessInjectionPoint<?, ? extends String> event) {
+ points.add(event.getInjectionPoint());
+ }
+ });
+ addInterceptor(MyInterceptor.class);
+ startContainer(MyBean.class);
+ assertEquals(1, points.size());
+ }
+
+ @InterceptorBinding
+ @Retention(RUNTIME)
+ public @interface Foo {}
+
+ @Interceptor
+ @Foo
+ public static class MyInterceptor {
+ @Inject
+ @Intercepted
+ private Bean<?> bean;
+
+ @AroundInvoke
+ public Object call(final InvocationContext context) throws Exception {
+ return context.proceed();
+ }
+ }
+
+ public static class MyBean {
+ @Inject
+ @Named("v1")
+ private String v1;
+
+ @Inject
+ @Named("v2")
+ private Boolean v2;
+ }
+}