Author: struberg
Date: Tue Jun 6 17:17:58 2017
New Revision: 1797813
URL: http://svn.apache.org/viewvc?rev=1797813&view=rev
Log:
OWB-1186 new BeanAttributesConfigurator in ProcessBeanAttributes
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/BeanAttributesConfiguratorImplTest.java
(with props)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanAttributesConfiguratorImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessBeanAttributesImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessBeanAttributes.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanAttributesConfiguratorImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanAttributesConfiguratorImpl.java?rev=1797813&r1=1797812&r2=1797813&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanAttributesConfiguratorImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanAttributesConfiguratorImpl.java
Tue Jun 6 17:17:58 2017
@@ -18,119 +18,181 @@
*/
package org.apache.webbeans.configurator;
+import javax.enterprise.inject.spi.BeanAttributes;
import javax.enterprise.inject.spi.configurator.BeanAttributesConfigurator;
import javax.enterprise.util.TypeLiteral;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.HashSet;
import java.util.Set;
-public class BeanAttributesConfiguratorImpl implements
BeanAttributesConfigurator
+import org.apache.webbeans.component.BeanAttributesImpl;
+import org.apache.webbeans.config.WebBeansContext;
+
+public class BeanAttributesConfiguratorImpl<T> implements
BeanAttributesConfigurator<T>
{
+ private final WebBeansContext webBeansContext;
+
+ private Set<Type> types;
+ private Set<Annotation> qualifiers;
+ private Class<? extends Annotation> scope;
+ private String name;
+ private Set<Class<? extends Annotation>> stereotypes;
+ private boolean alternative;
+
+ public BeanAttributesConfiguratorImpl(WebBeansContext webBeansContext,
BeanAttributes<T> originalBeanAttribute)
+ {
+ this.webBeansContext = webBeansContext;
+
+ this.types = new HashSet<>(originalBeanAttribute.getTypes());
+ this.qualifiers = new HashSet<>(originalBeanAttribute.getQualifiers());
+ this.scope = originalBeanAttribute.getScope();
+ this.name = originalBeanAttribute.getName();
+ this.stereotypes = new
HashSet<>(originalBeanAttribute.getStereotypes());
+ this.alternative = originalBeanAttribute.isAlternative();
+ }
+
@Override
- public BeanAttributesConfigurator addType(Type type)
+ public BeanAttributesConfigurator<T> addType(Type type)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ types.add(type);
+ return this;
}
@Override
- public BeanAttributesConfigurator addType(TypeLiteral typeLiteral)
+ public BeanAttributesConfigurator<T> addType(TypeLiteral typeLiteral)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ types.add(typeLiteral.getType());
+ return this;
}
@Override
- public BeanAttributesConfigurator addTypes(Type... types)
+ public BeanAttributesConfigurator<T> addTypes(Type... types)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ for (Type type : types)
+ {
+ this.types.add(type);
+ }
+ return this;
}
@Override
- public BeanAttributesConfigurator addTypes(Set set)
+ public BeanAttributesConfigurator<T> addTypes(Set set)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ types.addAll(set);
+ return this;
}
@Override
- public BeanAttributesConfigurator addTransitiveTypeClosure(Type type)
+ public BeanAttributesConfigurator<T> addTransitiveTypeClosure(Type type)
{
throw new UnsupportedOperationException("TODO implement CDI 2.0");
}
@Override
- public BeanAttributesConfigurator types(Type... types)
+ public BeanAttributesConfigurator<T> types(Type... types)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.types.clear();
+ addTypes(types);
+ return this;
}
@Override
- public BeanAttributesConfigurator types(Set set)
+ public BeanAttributesConfigurator<T> types(Set<Type> set)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.types.clear();
+ addTypes(set);
+ return this;
}
@Override
- public BeanAttributesConfigurator scope(Class scope)
+ public BeanAttributesConfigurator<T> scope(Class<? extends Annotation>
scope)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.scope = scope;
+ return this;
}
@Override
- public BeanAttributesConfigurator addQualifier(Annotation qualifier)
+ public BeanAttributesConfigurator<T> addQualifier(Annotation qualifier)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ qualifiers.add(qualifier);
+ return this;
}
@Override
- public BeanAttributesConfigurator addQualifiers(Annotation... qualifiers)
+ public BeanAttributesConfigurator<T> addQualifiers(Annotation...
qualifiers)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ for (Annotation qualifier : qualifiers)
+ {
+ addQualifiers(qualifier);
+ }
+ return this;
}
@Override
- public BeanAttributesConfigurator addQualifiers(Set qualifiers)
+ public BeanAttributesConfigurator<T> addQualifiers(Set<Annotation>
qualifiers)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.qualifiers.addAll(qualifiers);
+ return this;
}
@Override
- public BeanAttributesConfigurator qualifiers(Annotation... qualifiers)
+ public BeanAttributesConfigurator<T> qualifiers(Annotation... qualifiers)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.qualifiers.clear();
+ for (Annotation qualifier : qualifiers)
+ {
+ addQualifier(qualifier);
+ }
+ return this;
}
@Override
- public BeanAttributesConfigurator qualifiers(Set qualifiers)
+ public BeanAttributesConfigurator<T> qualifiers(Set<Annotation> qualifiers)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.qualifiers.clear();
+ addQualifiers(qualifiers);
+ return this;
}
@Override
- public BeanAttributesConfigurator addStereotype(Class stereotype)
+ public BeanAttributesConfigurator<T> addStereotype(Class<? extends
Annotation> stereotype)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ stereotypes.add(stereotype);
+ return this;
}
@Override
- public BeanAttributesConfigurator addStereotypes(Set stereotypes)
+ public BeanAttributesConfigurator<T> addStereotypes(Set<Class<? extends
Annotation>> stereotypes)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.stereotypes.addAll(stereotypes);
+ return this;
}
@Override
- public BeanAttributesConfigurator stereotypes(Set stereotypes)
+ public BeanAttributesConfigurator<T> stereotypes(Set<Class<? extends
Annotation>> stereotypes)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.stereotypes.clear();
+ addStereotypes(stereotypes);
+ return this;
}
@Override
- public BeanAttributesConfigurator name(String name)
+ public BeanAttributesConfigurator<T> name(String name)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.name = name;
+ return this;
}
@Override
- public BeanAttributesConfigurator alternative(boolean value)
+ public BeanAttributesConfigurator<T> alternative(boolean value)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ this.alternative = value;
+ return this;
+ }
+
+ public BeanAttributes<T> getBeanAttributes()
+ {
+ return new BeanAttributesImpl<T>(types, qualifiers, scope, name,
false, stereotypes, alternative);
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessBeanAttributesImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessBeanAttributesImpl.java?rev=1797813&r1=1797812&r2=1797813&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessBeanAttributesImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessBeanAttributesImpl.java
Tue Jun 6 17:17:58 2017
@@ -23,16 +23,22 @@ import javax.enterprise.inject.spi.BeanA
import javax.enterprise.inject.spi.ProcessBeanAttributes;
import javax.enterprise.inject.spi.configurator.BeanAttributesConfigurator;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.configurator.BeanAttributesConfiguratorImpl;
+
public class ProcessBeanAttributesImpl<T> extends EventBase implements
ProcessBeanAttributes<T>
{
+ private final WebBeansContext webBeansContext;
private Annotated annotated;
private BeanAttributes<T> attributes;
private boolean veto = false;
private Throwable definitionError = null;
private boolean ignoreFinalMethods = false;
+ private BeanAttributesConfiguratorImpl beanAttributesConfigurator = null;
- public ProcessBeanAttributesImpl(final Annotated annotated, final
BeanAttributes<T> attributes)
+ public ProcessBeanAttributesImpl(WebBeansContext webBeansContext,
Annotated annotated, BeanAttributes<T> attributes)
{
+ this.webBeansContext = webBeansContext;
this.annotated = annotated;
this.attributes = attributes;
}
@@ -56,6 +62,7 @@ public class ProcessBeanAttributesImpl<T
{
checkState();
attributes = tBeanAttributes;
+ beanAttributesConfigurator = null;
}
@Override
@@ -78,15 +85,23 @@ public class ProcessBeanAttributesImpl<T
ignoreFinalMethods = true;
}
- //X TODO OWB-1182 CDI 2.0
@Override
public BeanAttributesConfigurator<T> configureBeanAttributes()
{
- throw new UnsupportedOperationException("CDI 2.0 not yet imlemented");
+ if (beanAttributesConfigurator == null)
+ {
+ beanAttributesConfigurator = new
BeanAttributesConfiguratorImpl(webBeansContext, attributes);
+ }
+
+ return beanAttributesConfigurator;
}
public BeanAttributes<T> getAttributes()
{
+ if (beanAttributesConfigurator != null)
+ {
+ return beanAttributesConfigurator.getBeanAttributes();
+ }
return attributes;
}
@@ -104,4 +119,6 @@ public class ProcessBeanAttributesImpl<T
{
return definitionError;
}
+
+
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessBeanAttributes.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessBeanAttributes.java?rev=1797813&r1=1797812&r2=1797813&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessBeanAttributes.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessBeanAttributes.java
Tue Jun 6 17:17:58 2017
@@ -18,6 +18,7 @@
*/
package org.apache.webbeans.portable.events.generics;
+import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.portable.events.ProcessBeanAttributesImpl;
import javax.enterprise.inject.spi.Annotated;
@@ -27,9 +28,9 @@ public class GProcessBeanAttributes exte
{
private final Class<?> type;
- public GProcessBeanAttributes(final Class<?> type, final Annotated
annotated, final BeanAttributes attributes)
+ public GProcessBeanAttributes(WebBeansContext webBeansContext, final
Class<?> type, final Annotated annotated, final BeanAttributes attributes)
{
- super(annotated, attributes);
+ super(webBeansContext, annotated, attributes);
this.type = type;
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1797813&r1=1797812&r2=1797813&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Tue Jun 6 17:17:58 2017
@@ -150,6 +150,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+
/**
* Contains some utility methods used in the all project.
*/
@@ -1820,7 +1821,7 @@ public final class WebBeansUtil
public <T> ProcessBeanAttributesImpl<T> fireProcessBeanAttributes(final
Annotated annotatedType, final Class<?> type, final BeanAttributes<T> ba)
{
// we don't use bm stack since it is actually quite useless
- final ProcessBeanAttributesImpl event = new
GProcessBeanAttributes(type, annotatedType, ba);
+ final ProcessBeanAttributesImpl event = new
GProcessBeanAttributes(webBeansContext, type, annotatedType, ba);
try
{
webBeansContext.getBeanManagerImpl().fireEvent(event, true,
AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/BeanAttributesConfiguratorImplTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/BeanAttributesConfiguratorImplTest.java?rev=1797813&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/BeanAttributesConfiguratorImplTest.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/BeanAttributesConfiguratorImplTest.java
Tue Jun 6 17:17:58 2017
@@ -0,0 +1,95 @@
+/*
+ * 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 javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessBean;
+import javax.enterprise.inject.spi.ProcessBeanAttributes;
+import java.util.function.Consumer;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class BeanAttributesConfiguratorImplTest extends AbstractUnitTest
+{
+
+ @Test
+ public void testAddScope()
+ {
+ checkBeanAttributes(
+ pba ->
+ {
+ pba.configureBeanAttributes()
+ .scope(ApplicationScoped.class);
+ },
+ pb ->
+ {
+ assertEquals(ApplicationScoped.class, pb.getBean().getScope());
+ },
+ EmptyBean.class);
+ }
+
+ private void checkBeanAttributes(Consumer<ProcessBeanAttributes<Marker>>
beanAttributeConfigurator,
+ Consumer<ProcessBean<Marker>>
beanConsumer,
+ Class<?> classToCheck)
+ {
+ CheckBeanAttributesExtension extension
+ = new CheckBeanAttributesExtension(beanAttributeConfigurator,
beanConsumer);
+ addExtension(extension);
+ startContainer(classToCheck);
+ shutdown();
+ }
+
+ public static class CheckBeanAttributesExtension implements Extension
+ {
+ private final Consumer<ProcessBeanAttributes<Marker>>
beanAttributeConfigurator;
+ private final Consumer<ProcessBean<Marker>> beanConsumer;
+
+ public
CheckBeanAttributesExtension(Consumer<ProcessBeanAttributes<Marker>>
beanAttributeConfigurator, Consumer<ProcessBean<Marker>> beanConsumer)
+ {
+ this.beanAttributeConfigurator = beanAttributeConfigurator;
+ this.beanConsumer = beanConsumer;
+ }
+
+ public void processBeanAttributes(@Observes
ProcessBeanAttributes<Marker> processBeanAttributes)
+ {
+ beanAttributeConfigurator.accept(processBeanAttributes);
+ }
+
+ public void processBean(@Observes ProcessBean<Marker> processBean)
+ {
+ beanConsumer.accept(processBean);
+ }
+ }
+
+ public interface Marker
+ {
+ }
+
+
+ public static class EmptyBean implements Marker
+ {
+
+ }
+
+}
Propchange:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/BeanAttributesConfiguratorImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native