This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/deltaspike.git
The following commit(s) were added to refs/heads/master by this push:
new f883d7b5d workaround BeanConfigurator
f883d7b5d is described below
commit f883d7b5dd22d3fdb3785e7511bdd9aa55cd5126
Author: tandraschko <[email protected]>
AuthorDate: Thu Jan 11 20:36:34 2024 +0100
workaround BeanConfigurator
---
.../core/util/BeanConfiguratorUtils.java | 84 ++++++++++++++++++++++
.../core/impl/message/MessageBundleExtension.java | 75 ++++++++-----------
.../impl/PartialBeanBindingExtension.java | 14 +---
3 files changed, 115 insertions(+), 58 deletions(-)
diff --git
a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/BeanConfiguratorUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/BeanConfiguratorUtils.java
new file mode 100644
index 000000000..8bd42c9c3
--- /dev/null
+++
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/BeanConfiguratorUtils.java
@@ -0,0 +1,84 @@
+/*
+ * 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.deltaspike.core.util;
+
+import jakarta.enterprise.inject.Default;
+import jakarta.enterprise.inject.spi.AnnotatedType;
+import jakarta.enterprise.inject.spi.BeanManager;
+import jakarta.enterprise.inject.spi.configurator.BeanConfigurator;
+import jakarta.inject.Named;
+
+import java.beans.Introspector;
+import java.lang.annotation.Annotation;
+
+
+public class BeanConfiguratorUtils
+{
+ private BeanConfiguratorUtils()
+ {
+ }
+
+ public static <T> BeanConfigurator<T> read(BeanManager beanManager,
+ BeanConfigurator<T>
beanConfigurator,
+ AnnotatedType<T> type)
+ {
+ // Weld doesnt support interfaces...
+ if (!type.getJavaClass().isInterface())
+ {
+ return beanConfigurator.read(type);
+ }
+
+ boolean qualifierAdded = false;
+
+ for (Annotation annotation : type.getAnnotations())
+ {
+ if (beanManager.isQualifier(annotation.annotationType()))
+ {
+ beanConfigurator.addQualifier(annotation);
+ qualifierAdded = true;
+ }
+ else if (beanManager.isScope(annotation.annotationType()))
+ {
+ beanConfigurator.scope(annotation.annotationType());
+ }
+ else if (beanManager.isStereotype(annotation.annotationType()))
+ {
+ beanConfigurator.addStereotype(annotation.annotationType());
+ }
+ if (annotation instanceof Named)
+ {
+ String name = ((Named) annotation).value();
+ if (name == null || name.isBlank())
+ {
+ name =
Introspector.decapitalize(type.getJavaClass().getSimpleName());
+ }
+ beanConfigurator.name(name);
+ }
+ }
+
+ if (!qualifierAdded)
+ {
+ beanConfigurator.addQualifier(Default.Literal.INSTANCE);
+ }
+
+ return beanConfigurator;
+ }
+
+
+}
diff --git
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java
index 7f627761e..cf0e9af20 100644
---
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java
+++
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java
@@ -18,36 +18,23 @@
*/
package org.apache.deltaspike.core.impl.message;
-import java.beans.Introspector;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Default;
-import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
-import jakarta.enterprise.inject.spi.AfterDeploymentValidation;
-import jakarta.enterprise.inject.spi.AnnotatedType;
-import jakarta.enterprise.inject.spi.Bean;
-import jakarta.enterprise.inject.spi.BeanManager;
-import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
-import jakarta.enterprise.inject.spi.Extension;
-import jakarta.enterprise.inject.spi.ProcessAnnotatedType;
-
+import jakarta.enterprise.inject.spi.*;
import jakarta.enterprise.inject.spi.configurator.BeanConfigurator;
-import jakarta.inject.Named;
import org.apache.deltaspike.core.api.message.Message;
import org.apache.deltaspike.core.api.message.MessageBundle;
import org.apache.deltaspike.core.api.message.MessageTemplate;
-import org.apache.deltaspike.core.util.ClassUtils;
import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.BeanConfiguratorUtils;
import org.apache.deltaspike.core.util.ClassDeactivationUtils;
+import org.apache.deltaspike.core.util.ClassUtils;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.*;
/**
* Extension for handling {@link MessageBundle}s.
@@ -139,36 +126,30 @@ public class MessageBundleExtension implements Extension,
Deactivatable
return;
}
- for (AnnotatedType<?> mbType : messageBundleTypes)
+ for (AnnotatedType<?> type : messageBundleTypes)
{
- BeanConfigurator<?> beanConfigurator = abd.addBean()
- .createWith(cc ->
- {
- final Bean<?> invocationHandlerBean =
beanManager.resolve(
-
beanManager.getBeans(MessageBundleInvocationHandler.class));
-
- return
createMessageBundleProxy(mbType.getJavaClass(),
- (MessageBundleInvocationHandler)
-
beanManager.getReference(invocationHandlerBean,
MessageBundleInvocationHandler.class, cc));
- })
- .types(mbType.getJavaClass(), Object.class,
Serializable.class)
- .addQualifier(Default.Literal.INSTANCE)
- .scope(ApplicationScoped.class) // needs to be a
normalscope due to a bug in older Weld versions
- .id("MessageBundleBean#" +
mbType.getJavaClass().getName());
-
- Named named = mbType.getJavaClass().getAnnotation(Named.class);
- if (named != null)
- {
- String name = named.value();
- if (name == null || name.isBlank())
- {
- name =
Introspector.decapitalize(mbType.getJavaClass().getSimpleName());
- }
- beanConfigurator.name(name);
- }
+ addAsBean(abd, beanManager, type);
}
}
+ protected <T> void addAsBean(AfterBeanDiscovery abd, BeanManager
beanManager, AnnotatedType<T> type)
+ {
+ BeanConfigurator<T> beanConfigurator = abd.addBean()
+ .createWith(cc ->
+ {
+ final Bean<?> invocationHandlerBean =
beanManager.resolve(
+
beanManager.getBeans(MessageBundleInvocationHandler.class));
+
+ return createMessageBundleProxy(type.getJavaClass(),
+ (MessageBundleInvocationHandler)
+
beanManager.getReference(invocationHandlerBean,
MessageBundleInvocationHandler.class, cc));
+ });
+ BeanConfiguratorUtils.read(beanManager, beanConfigurator, type)
+ .types(type.getJavaClass(), Object.class, Serializable.class)
+ .addQualifier(Default.Literal.INSTANCE)
+ .scope(ApplicationScoped.class) // needs to be a normalscope
due to a bug in older Weld versions
+ .id("MessageBundleBean#" + type.getJavaClass().getName());
+ }
@SuppressWarnings("UnusedDeclaration")
protected void cleanup(@Observes AfterDeploymentValidation
afterDeploymentValidation)
diff --git
a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanBindingExtension.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanBindingExtension.java
index 7b392b6ac..7c7658070 100644
---
a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanBindingExtension.java
+++
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanBindingExtension.java
@@ -41,10 +41,7 @@ import
jakarta.enterprise.inject.spi.configurator.BeanConfigurator;
import org.apache.deltaspike.core.api.provider.BeanProvider;
import org.apache.deltaspike.core.spi.activation.Deactivatable;
-import org.apache.deltaspike.core.util.AnnotationUtils;
-import org.apache.deltaspike.core.util.BeanUtils;
-import org.apache.deltaspike.core.util.ClassDeactivationUtils;
-import org.apache.deltaspike.core.util.ReflectionUtils;
+import org.apache.deltaspike.core.util.*;
import org.apache.deltaspike.partialbean.api.PartialBeanBinding;
import org.apache.deltaspike.proxy.api.DeltaSpikeProxyBeanConfigurator;
@@ -173,10 +170,9 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
AnnotatedType<T> annotatedType =
beanManager.createAnnotatedType(beanClass);
- BeanConfigurator<T> beanConfigurator = afterBeanDiscovery.addBean()
- .read(annotatedType)
+ BeanConfigurator<T> beanConfigurator = afterBeanDiscovery.addBean();
+ BeanConfiguratorUtils.read(beanManager, beanConfigurator,
annotatedType)
.beanClass(beanClass);
- // .passivationCapable(true)
new DeltaSpikeProxyBeanConfigurator(beanClass,
descriptor.getHandler(),
@@ -241,9 +237,6 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
Class<?> producerResultType =
currentMethod.getReturnType();
- boolean passivationCapable =
-
Serializable.class.isAssignableFrom(producerResultType) ||
producerResultType.isPrimitive();
-
Set<Annotation> qualifiers =
extractQualifiers(currentMethod.getDeclaredAnnotations(), beanManager);
final Class partialBeanClass = currentClass;
@@ -252,7 +245,6 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
.beanClass(producerResultType)
.types(Object.class, producerResultType)
.qualifiers(qualifiers)
- // .passivationCapable(passivationCapable)
.scope(scopeClass)
.id(createPartialProducerId(currentClass,
currentMethod, qualifiers))
.produceWith(e ->