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 e282e6c77 fixed PartialBean + Proxy module
e282e6c77 is described below
commit e282e6c77a1bb5ce08f244619224e0e909c3b665
Author: Thomas Andraschko <[email protected]>
AuthorDate: Thu Mar 30 14:24:38 2023 +0200
fixed PartialBean + Proxy module
---
.../deltaspike/core/util/AnnotationUtils.java | 172 +++++++++++++
.../deltaspike/data/impl/RepositoryExtension.java | 272 ++++++++++-----------
.../impl/DeltaSpikePartialProducerLifecycle.java | 52 ----
.../impl/PartialBeanBindingExtension.java | 89 +++----
.../partialbean/impl/PartialBeanDescriptor.java | 164 ++++++-------
...ion => jakarta.enterprise.inject.spi.Extension} | 0
.../partialbean/uc001/TestPartialBeanHandler.java | 128 +++++-----
deltaspike/modules/pom.xml | 2 +
...e.java => DeltaSpikeProxyBeanConfigurator.java} | 27 +-
.../api/src/main/resources/META-INF/beans.xml | 4 +-
10 files changed, 516 insertions(+), 394 deletions(-)
diff --git
a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java
new file mode 100644
index 000000000..ce873eaa1
--- /dev/null
+++
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java
@@ -0,0 +1,172 @@
+/*
+ * 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.Typed;
+import jakarta.enterprise.inject.spi.BeanManager;
+import jakarta.enterprise.util.Nonbinding;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+
+@Typed()
+public abstract class AnnotationUtils
+{
+ private AnnotationUtils()
+ {
+ // prevent instantiation
+ }
+
+ public static <T extends Annotation> T extractAnnotationFromMethodOrClass(
+ BeanManager beanManager, Method targetMethod, Class targetClass,
Class<T> targetAnnotationType)
+ {
+ T result = extractAnnotationFromMethod(beanManager, targetMethod,
targetAnnotationType);
+
+ if (result == null)
+ {
+ //see DELTASPIKE-517
+ Class unproxiedTargetClass =
ProxyUtils.getUnproxiedClass(targetClass);
+
+ // and if not found search on the class
+ result = findAnnotation(beanManager,
unproxiedTargetClass.getAnnotations(), targetAnnotationType);
+ }
+ return result;
+ }
+
+ public static <T extends Annotation> T extractAnnotationFromMethod(
+ BeanManager beanManager, Method targetMethod, Class<T>
targetAnnotationType)
+ {
+ return findAnnotation(beanManager, targetMethod.getAnnotations(),
targetAnnotationType);
+ }
+
+ public static <T extends Annotation> T findAnnotation(
+ BeanManager beanManager, Annotation[] annotations, Class<T>
targetAnnotationType)
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (targetAnnotationType.equals(annotation.annotationType()))
+ {
+ return (T) annotation;
+ }
+ if (beanManager.isStereotype(annotation.annotationType()))
+ {
+ T result = findAnnotation(
+ beanManager,
annotation.annotationType().getAnnotations(), targetAnnotationType);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ }
+ return null;
+ }
+
+ //based on org.apache.webbeans.container.BeanCacheKey#getQualifierHashCode
+ public static int getQualifierHashCode(Annotation annotation)
+ {
+ Class annotationClass = annotation.annotationType();
+
+ int hashCode = getTypeHashCode(annotationClass);
+
+ for (Method member : annotationClass.getDeclaredMethods())
+ {
+ if (member.isAnnotationPresent(Nonbinding.class))
+ {
+ continue;
+ }
+
+ final Object annotationMemberValue =
ReflectionUtils.invokeMethod(annotation, member, Object.class, true);
+
+ final int arrayValue;
+ if (annotationMemberValue == null /*possible with literals*/)
+ {
+ arrayValue = 0;
+ }
+ else if (annotationMemberValue.getClass().isArray())
+ {
+ Class<?> annotationMemberType =
annotationMemberValue.getClass().getComponentType();
+ if (annotationMemberType.isPrimitive())
+ {
+ if (Long.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((long[])
annotationMemberValue);
+ }
+ else if (Integer.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((int[])
annotationMemberValue);
+ }
+ else if (Short.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((short[])
annotationMemberValue);
+ }
+ else if (Double.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((double[])
annotationMemberValue);
+ }
+ else if (Float.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((float[])
annotationMemberValue);
+ }
+ else if (Boolean.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((boolean[])
annotationMemberValue);
+ }
+ else if (Byte.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((byte[])
annotationMemberValue);
+ }
+ else if (Character.TYPE == annotationMemberType)
+ {
+ arrayValue = Arrays.hashCode((char[])
annotationMemberValue);
+ }
+ else
+ {
+ arrayValue = 0;
+ }
+ }
+ else
+ {
+ arrayValue = Arrays.hashCode((Object[])
annotationMemberValue);
+ }
+ }
+ else
+ {
+ arrayValue = annotationMemberValue.hashCode();
+ }
+
+ hashCode = 29 * hashCode + arrayValue;
+ hashCode = 29 * hashCode + member.getName().hashCode();
+ }
+
+ return hashCode;
+ }
+
+ private static int getTypeHashCode(Type type)
+ {
+ int typeHash = type.hashCode();
+ if (typeHash == 0 && type instanceof Class)
+ {
+ return ((Class)type).getName().hashCode();
+ }
+
+ return typeHash;
+ }
+}
diff --git
a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
index cd68725a1..0807ef0f2 100755
---
a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
+++
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
@@ -1,136 +1,136 @@
-/*
- * 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.data.impl;
-
-import java.lang.reflect.InvocationHandler;
-import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import jakarta.enterprise.event.Observes;
-import jakarta.enterprise.inject.spi.AnnotatedType;
-import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
-import jakarta.enterprise.inject.spi.BeforeShutdown;
-import jakarta.enterprise.inject.spi.Extension;
-import jakarta.enterprise.inject.spi.ProcessAnnotatedType;
-
-import org.apache.deltaspike.core.spi.activation.Deactivatable;
-import org.apache.deltaspike.core.util.ClassDeactivationUtils;
-import org.apache.deltaspike.data.api.AbstractEntityRepository;
-import org.apache.deltaspike.data.api.AbstractFullEntityRepository;
-import org.apache.deltaspike.data.api.Repository;
-
-/**
- * The main extension class for Repositories, based on PartialBeans. Handles
following events:<br/>
- * <br/>
- * <b>{@code @Observes BeforeBeanDiscovery}</b>:
- * Scans the classpath for <code>persistence.xml</code> and extracts
relevant information out of it.
- * This includes mainly entity definitions (type, primary keys) which are
not declared with annotations.<br/>
- * <br/>
- * <b>{@code @Observes ProcessAnnotatedType<X>}</b>:
- * Looks for types annotated with {@link Repository}. Repositories are
validated and preprocessed -
- * all the methods on the repository are checked and analyzed for better
runtime performance.<br/>
- * <br/>
- * <b>{@code @Observes AfterBeanDiscovery<X>}</b>:
- * Raises any definition errors discovered before.
- */
-public class RepositoryExtension implements Extension, Deactivatable
-{
- private static final Logger LOG =
Logger.getLogger(RepositoryExtension.class.getName());
-
- // TODO: Hack still required?
- private static final ArrayList<Class<?>> REPOSITORY_CLASSES = new
ArrayList<Class<?>>();
-
- private final ArrayList<Class<?>> repositoryClasses = new
ArrayList<Class<?>>();
-
- private Boolean isActivated = true;
-
- void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
- {
- isActivated = ClassDeactivationUtils.isActivated(getClass());
- }
-
- @SuppressWarnings("unchecked")
- <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event)
- {
- if (!isActivated)
- {
- return;
- }
-
- if (isVetoed(event.getAnnotatedType()))
- {
- event.veto();
- }
- else if (isRepository(event.getAnnotatedType()))
- {
- Class<X> repositoryClass = event.getAnnotatedType().getJavaClass();
-
- LOG.log(Level.FINER, "getHandlerClass: Repository annotation
detected on {0}",
- event.getAnnotatedType());
- if (Deactivatable.class.isAssignableFrom(repositoryClass)
- && !ClassDeactivationUtils.isActivated((Class<? extends
Deactivatable>) repositoryClass))
- {
- LOG.log(Level.FINER, "Class {0} is Deactivated",
repositoryClass);
- return;
- }
-
- repositoryClasses.add(repositoryClass);
- REPOSITORY_CLASSES.add(repositoryClass);
- }
- }
-
- private <X> boolean isRepository(AnnotatedType<X> annotatedType)
- {
- return (annotatedType.isAnnotationPresent(Repository.class) ||
-
annotatedType.getJavaClass().isAnnotationPresent(Repository.class)) &&
-
!InvocationHandler.class.isAssignableFrom(annotatedType.getJavaClass());
- }
-
- private <X> boolean isVetoed(AnnotatedType<X> annotated)
- {
- Class<X> javaClass = annotated.getJavaClass();
- return javaClass.equals(AbstractEntityRepository.class) ||
- javaClass.equals(AbstractFullEntityRepository.class);
- }
-
- public ArrayList<Class<?>> getRepositoryClasses()
- {
- ArrayList<Class<?>> result = new ArrayList<Class<?>>();
-
- if (repositoryClasses.isEmpty() && !REPOSITORY_CLASSES.isEmpty())
- {
- result.addAll(REPOSITORY_CLASSES);
- }
-
- if (!repositoryClasses.isEmpty())
- {
- result.addAll(repositoryClasses);
- }
-
- return result;
- }
-
- protected void cleanup(@Observes BeforeShutdown beforeShutdown)
- {
- //we can reset it in any case,
- //because every application produced a copy as application-scoped bean
(see RepositoryComponentsFactory)
- REPOSITORY_CLASSES.clear();
- }
-}
+/*
+ * 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.data.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import jakarta.enterprise.event.Observes;
+import jakarta.enterprise.inject.spi.AnnotatedType;
+import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
+import jakarta.enterprise.inject.spi.BeforeShutdown;
+import jakarta.enterprise.inject.spi.Extension;
+import jakarta.enterprise.inject.spi.ProcessAnnotatedType;
+
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
+import org.apache.deltaspike.data.api.AbstractEntityRepository;
+import org.apache.deltaspike.data.api.AbstractFullEntityRepository;
+import org.apache.deltaspike.data.api.Repository;
+
+/**
+ * The main extension class for Repositories, based on PartialBeans. Handles
following events:<br/>
+ * <br/>
+ * <b>{@code @Observes BeforeBeanDiscovery}</b>:
+ * Scans the classpath for <code>persistence.xml</code> and extracts
relevant information out of it.
+ * This includes mainly entity definitions (type, primary keys) which are
not declared with annotations.<br/>
+ * <br/>
+ * <b>{@code @Observes ProcessAnnotatedType<X>}</b>:
+ * Looks for types annotated with {@link Repository}. Repositories are
validated and preprocessed -
+ * all the methods on the repository are checked and analyzed for better
runtime performance.<br/>
+ * <br/>
+ * <b>{@code @Observes AfterBeanDiscovery<X>}</b>:
+ * Raises any definition errors discovered before.
+ */
+public class RepositoryExtension implements Extension, Deactivatable
+{
+ private static final Logger LOG =
Logger.getLogger(RepositoryExtension.class.getName());
+
+ // TODO: Hack still required?
+ private static final ArrayList<Class<?>> REPOSITORY_CLASSES = new
ArrayList<Class<?>>();
+
+ private final ArrayList<Class<?>> repositoryClasses = new
ArrayList<Class<?>>();
+
+ private Boolean isActivated = true;
+
+ void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
+ {
+ isActivated = ClassDeactivationUtils.isActivated(getClass());
+ }
+
+ @SuppressWarnings("unchecked")
+ <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event)
+ {
+ if (!isActivated)
+ {
+ return;
+ }
+
+ if (isVetoed(event.getAnnotatedType()))
+ {
+ event.veto();
+ }
+ else if (isRepository(event.getAnnotatedType()))
+ {
+ Class<X> repositoryClass = event.getAnnotatedType().getJavaClass();
+
+ LOG.log(Level.FINER, "getHandlerClass: Repository annotation
detected on {0}",
+ event.getAnnotatedType());
+ if (Deactivatable.class.isAssignableFrom(repositoryClass)
+ && !ClassDeactivationUtils.isActivated((Class<? extends
Deactivatable>) repositoryClass))
+ {
+ LOG.log(Level.FINER, "Class {0} is Deactivated",
repositoryClass);
+ return;
+ }
+
+ repositoryClasses.add(repositoryClass);
+ REPOSITORY_CLASSES.add(repositoryClass);
+ }
+ }
+
+ private <X> boolean isRepository(AnnotatedType<X> annotatedType)
+ {
+ return (annotatedType.isAnnotationPresent(Repository.class) ||
+
annotatedType.getJavaClass().isAnnotationPresent(Repository.class)) &&
+
!InvocationHandler.class.isAssignableFrom(annotatedType.getJavaClass());
+ }
+
+ private <X> boolean isVetoed(AnnotatedType<X> annotated)
+ {
+ Class<X> javaClass = annotated.getJavaClass();
+ return javaClass.equals(AbstractEntityRepository.class) ||
+ javaClass.equals(AbstractFullEntityRepository.class);
+ }
+
+ public ArrayList<Class<?>> getRepositoryClasses()
+ {
+ ArrayList<Class<?>> result = new ArrayList<Class<?>>();
+
+ if (repositoryClasses.isEmpty() && !REPOSITORY_CLASSES.isEmpty())
+ {
+ result.addAll(REPOSITORY_CLASSES);
+ }
+
+ if (!repositoryClasses.isEmpty())
+ {
+ result.addAll(repositoryClasses);
+ }
+
+ return result;
+ }
+
+ protected void cleanup(@Observes BeforeShutdown beforeShutdown)
+ {
+ //we can reset it in any case,
+ //because every application produced a copy as application-scoped bean
(see RepositoryComponentsFactory)
+ REPOSITORY_CLASSES.clear();
+ }
+}
diff --git
a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/DeltaSpikePartialProducerLifecycle.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/DeltaSpikePartialProducerLifecycle.java
deleted file mode 100644
index a65f273f6..000000000
---
a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/DeltaSpikePartialProducerLifecycle.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.partialbean.impl;
-
-import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.core.util.ReflectionUtils;
-import org.apache.deltaspike.core.util.metadata.builder.ContextualLifecycle;
-
-import jakarta.enterprise.context.spi.CreationalContext;
-import jakarta.enterprise.inject.spi.Bean;
-import java.lang.reflect.Method;
-
-public class DeltaSpikePartialProducerLifecycle<T> implements
ContextualLifecycle<T>
-{
- private final Class targetPartialBeanClass;
- private final Method producerMethod;
-
- public DeltaSpikePartialProducerLifecycle(Class targetPartialBeanClass,
Method producerMethod)
- {
- this.targetPartialBeanClass = targetPartialBeanClass;
- this.producerMethod = producerMethod;
- }
-
- @Override
- public T create(Bean<T> bean, CreationalContext<T> creationalContext)
- {
- Object partialBean =
BeanProvider.getContextualReference(this.targetPartialBeanClass);
- return (T)ReflectionUtils.invokeMethod(partialBean,
this.producerMethod, Object.class, false);
- }
-
- @Override
- public void destroy(Bean<T> bean, T instance, CreationalContext<T>
creationalContext)
- {
- //we don't need to support disposer-methods for now (because it's just
about exposing injectable values)
- }
-}
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 284736044..b7e06baca 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
@@ -23,32 +23,30 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.event.Observes;
+import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
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.configurator.BeanConfigurator;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.core.api.literal.DefaultLiteral;
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.bean.BeanBuilder;
-import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
+import org.apache.deltaspike.core.util.ReflectionUtils;
import org.apache.deltaspike.partialbean.api.PartialBeanBinding;
-import org.apache.deltaspike.proxy.api.DeltaSpikeProxyContextualLifecycle;
+import org.apache.deltaspike.proxy.api.DeltaSpikeProxyBeanConfigurator;
public class PartialBeanBindingExtension implements Extension, Deactivatable
{
@@ -147,18 +145,10 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
{
for (Class partialBeanClass : descriptor.getClasses())
{
- Bean partialBean = createPartialBean(partialBeanClass,
descriptor, afterBeanDiscovery, beanManager);
- if (partialBean != null)
+ boolean added = createPartialBean(partialBeanClass,
descriptor, afterBeanDiscovery, beanManager);
+ if (added)
{
- afterBeanDiscovery.addBean(partialBean);
-
- List<Bean> partialProducerBeans =
- createPartialProducersDefinedIn(partialBean,
afterBeanDiscovery, beanManager);
-
- for (Bean partialProducerBean : partialProducerBeans)
- {
- afterBeanDiscovery.addBean(partialProducerBean);
- }
+ createPartialProducersDefinedIn(afterBeanDiscovery,
beanManager, partialBeanClass);
}
}
}
@@ -167,7 +157,7 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
this.descriptors.clear();
}
- protected <T> Bean<T> createPartialBean(Class<T> beanClass,
PartialBeanDescriptor descriptor,
+ protected <T> boolean createPartialBean(Class<T> beanClass,
PartialBeanDescriptor descriptor,
AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager)
{
if (descriptor.getHandler() == null)
@@ -178,22 +168,25 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
+ " is needed as a handler for " + beanClass.getName()
+ ". See the documentation about @" +
PartialBeanBinding.class.getName() + "."));
- return null;
+ return false;
}
- AnnotatedType<T> annotatedType = new
AnnotatedTypeBuilder<T>().readFromType(beanClass).create();
+ AnnotatedType<T> annotatedType =
beanManager.createAnnotatedType(beanClass);
- DeltaSpikeProxyContextualLifecycle lifecycle = new
DeltaSpikeProxyContextualLifecycle(beanClass,
+ BeanConfigurator<T> beanConfigurator = afterBeanDiscovery.addBean()
+ .read(annotatedType)
+ .beanClass(beanClass);
+ // .passivationCapable(true)
+
+ new DeltaSpikeProxyBeanConfigurator(beanClass,
descriptor.getHandler(),
PartialBeanProxyFactory.getInstance(),
- beanManager);
-
- BeanBuilder<T> beanBuilder = new BeanBuilder<T>(beanManager)
- .readFromType(annotatedType)
- .passivationCapable(true)
- .beanLifecycle(lifecycle);
+ beanManager,
+ beanConfigurator)
+ .delegateCreateWith()
+ .delegateDestroyWith();
- return beanBuilder.create();
+ return true;
}
protected <X> Class<? extends Annotation>
extractBindingClass(ProcessAnnotatedType<X> pat)
@@ -213,18 +206,9 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
* logic for partial-producers
*/
- protected List<Bean> createPartialProducersDefinedIn(
- Bean partialBean, AfterBeanDiscovery afterBeanDiscovery, BeanManager
beanManager)
- {
- Class currentClass = partialBean.getBeanClass();
- return createPartialProducersDefinedIn(partialBean,
afterBeanDiscovery, beanManager, currentClass);
- }
-
- private List<Bean> createPartialProducersDefinedIn(
- Bean partialBean, AfterBeanDiscovery afterBeanDiscovery, BeanManager
beanManager, Class currentClass)
+ private void createPartialProducersDefinedIn(
+ AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager,
Class currentClass)
{
- List<Bean> result = new ArrayList<Bean>();
-
while (currentClass != null &&
!Object.class.getName().equals(currentClass.getName()))
{
for (Class interfaceClass : currentClass.getInterfaces())
@@ -233,8 +217,8 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
{
continue;
}
- result.addAll(
- createPartialProducersDefinedIn(partialBean,
afterBeanDiscovery, beanManager, interfaceClass));
+
+ createPartialProducersDefinedIn(afterBeanDiscovery,
beanManager, interfaceClass);
}
for (Method currentMethod : currentClass.getDeclaredMethods())
@@ -250,9 +234,6 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
currentMethod.toString() + " in " +
currentClass.getName()));
}
- DeltaSpikePartialProducerLifecycle lifecycle =
- new
DeltaSpikePartialProducerLifecycle(partialBean.getBeanClass(), currentMethod);
-
Class<? extends Annotation> scopeClass =
extractScope(currentMethod.getDeclaredAnnotations(),
beanManager);
@@ -263,23 +244,25 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
Set<Annotation> qualifiers =
extractQualifiers(currentMethod.getDeclaredAnnotations(), beanManager);
- BeanBuilder<?> beanBuilder = new BeanBuilder(beanManager)
+ final Class partialBeanClass = currentClass;
+
+ afterBeanDiscovery.addBean()
.beanClass(producerResultType)
.types(Object.class, producerResultType)
.qualifiers(qualifiers)
- .passivationCapable(passivationCapable)
+ // .passivationCapable(passivationCapable)
.scope(scopeClass)
.id(createPartialProducerId(currentClass,
currentMethod, qualifiers))
- .beanLifecycle(lifecycle);
-
- result.add(beanBuilder.create());
+ .produceWith(e ->
+ {
+ Object instance =
BeanProvider.getContextualReference(partialBeanClass);
+ return
ReflectionUtils.invokeMethod(instance, currentMethod, Object.class, false);
+ });
}
}
currentClass = currentClass.getSuperclass();
}
-
- return result;
}
private Set<Annotation> extractQualifiers(Annotation[] annotations,
BeanManager beanManager)
@@ -288,7 +271,7 @@ public class PartialBeanBindingExtension implements
Extension, Deactivatable
if (result.isEmpty())
{
- result.add(new DefaultLiteral());
+ result.add(Default.Literal.INSTANCE);
}
return result;
}
diff --git
a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanDescriptor.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanDescriptor.java
index 056f4be96..9af7da44e 100644
---
a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanDescriptor.java
+++
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/PartialBeanDescriptor.java
@@ -1,82 +1,82 @@
-/*
- * 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.partialbean.impl;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationHandler;
-import java.util.HashSet;
-import java.util.Set;
-
-public class PartialBeanDescriptor
-{
- private Class<? extends Annotation> binding;
- private Class<? extends InvocationHandler> handler;
- private Set<Class<?>> classes;
-
- public PartialBeanDescriptor(Class<? extends Annotation> binding)
- {
- this.binding = binding;
- this.classes = new HashSet<Class<?>>();
- }
-
- public PartialBeanDescriptor(Class<? extends Annotation> binding,
- Class<? extends InvocationHandler> handler)
- {
- this(binding);
- this.handler = handler;
- }
-
- public PartialBeanDescriptor(Class<? extends Annotation> binding,
- Class<? extends InvocationHandler> handler,
- Class<?> clazz)
- {
- this(binding, handler);
- this.classes.add(clazz);
- }
-
- public Class<? extends Annotation> getBinding()
- {
- return binding;
- }
-
- public void setBinding(Class<? extends Annotation> binding)
- {
- this.binding = binding;
- }
-
- public Class<? extends InvocationHandler> getHandler()
- {
- return handler;
- }
-
- public void setHandler(Class<? extends InvocationHandler> handler)
- {
- this.handler = handler;
- }
-
- public Set<Class<?>> getClasses()
- {
- return classes;
- }
-
- public void setClasses(Set<Class<?>> classes)
- {
- this.classes = classes;
- }
-}
+/*
+ * 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.partialbean.impl;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.util.HashSet;
+import java.util.Set;
+
+public class PartialBeanDescriptor
+{
+ private Class<? extends Annotation> binding;
+ private Class<? extends InvocationHandler> handler;
+ private Set<Class<?>> classes;
+
+ public PartialBeanDescriptor(Class<? extends Annotation> binding)
+ {
+ this.binding = binding;
+ this.classes = new HashSet<>();
+ }
+
+ public PartialBeanDescriptor(Class<? extends Annotation> binding,
+ Class<? extends InvocationHandler> handler)
+ {
+ this(binding);
+ this.handler = handler;
+ }
+
+ public PartialBeanDescriptor(Class<? extends Annotation> binding,
+ Class<? extends InvocationHandler> handler,
+ Class<?> clazz)
+ {
+ this(binding, handler);
+ this.classes.add(clazz);
+ }
+
+ public Class<? extends Annotation> getBinding()
+ {
+ return binding;
+ }
+
+ public void setBinding(Class<? extends Annotation> binding)
+ {
+ this.binding = binding;
+ }
+
+ public Class<? extends InvocationHandler> getHandler()
+ {
+ return handler;
+ }
+
+ public void setHandler(Class<? extends InvocationHandler> handler)
+ {
+ this.handler = handler;
+ }
+
+ public Set<Class<?>> getClasses()
+ {
+ return classes;
+ }
+
+ public void setClasses(Set<Class<?>> classes)
+ {
+ this.classes = classes;
+ }
+}
diff --git
a/deltaspike/modules/partial-bean/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
b/deltaspike/modules/partial-bean/impl/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension
similarity index 100%
rename from
deltaspike/modules/partial-bean/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
rename to
deltaspike/modules/partial-bean/impl/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension
diff --git
a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java
b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java
index df5f3774c..fb20ca966 100644
---
a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java
+++
b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java
@@ -1,63 +1,65 @@
-/*
- * 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.test.core.api.partialbean.uc001;
-
-import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean;
-import
org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware;
-import
org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding;
-
-import jakarta.annotation.PostConstruct;
-import jakarta.annotation.PreDestroy;
-import jakarta.enterprise.context.Dependent;
-import jakarta.inject.Inject;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-@TestPartialBeanBinding
-@Dependent //normal-scopes are possible as well
-public class TestPartialBeanHandler implements InvocationHandler, /*just
needed for testing interceptors: */TestInterceptorAware
-{
- @Inject
- private TestBean testBean;
-
- private String value;
- private boolean intercepted;
-
- @PostConstruct
- protected void onCreate()
- {
- this.value = "partial";
- }
-
- @PreDestroy
- protected void onDestroy()
- {
- //TODO check in a test
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable
- {
- return this.value + "-" + this.testBean.getValue() + "-" +
this.intercepted;
- }
-
- public void setIntercepted(boolean intercepted)
- {
- this.intercepted = intercepted;
- }
-}
+/*
+ * 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.test.core.api.partialbean.uc001;
+
+import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean;
+import
org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware;
+import
org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.Dependent;
+import jakarta.inject.Inject;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+@TestPartialBeanBinding
+@Dependent //normal-scopes are possible as well
+public class TestPartialBeanHandler implements InvocationHandler, /*just
needed for testing interceptors: */TestInterceptorAware
+{
+ @Inject
+ private TestBean testBean;
+
+ private String value;
+ private boolean intercepted;
+
+ @PostConstruct
+ protected void onCreate()
+ {
+ this.value = "partial";
+ }
+
+ @PreDestroy
+ protected void onDestroy()
+ {
+ //TODO check in a test
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable
+ {
+ return this.value + "-" + this.testBean.getValue() + "-" +
this.intercepted;
+ }
+
+ @Override
+ public void setIntercepted(boolean intercepted)
+ {
+ this.intercepted = intercepted;
+ }
+}
diff --git a/deltaspike/modules/pom.xml b/deltaspike/modules/pom.xml
index 056446a4d..05f639ebe 100644
--- a/deltaspike/modules/pom.xml
+++ b/deltaspike/modules/pom.xml
@@ -40,7 +40,9 @@
<module>security</module>
<module>jpa</module>
<module>jsf</module>
+ -->
<module>partial-bean</module>
+<!--
<module>data</module>
<module>scheduler</module>
-->
diff --git
a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyContextualLifecycle.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyBeanConfigurator.java
similarity index 88%
rename from
deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyContextualLifecycle.java
rename to
deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyBeanConfigurator.java
index 6f4599265..4ac92ab2f 100644
---
a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyContextualLifecycle.java
+++
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyBeanConfigurator.java
@@ -28,6 +28,7 @@ import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.InjectionTarget;
import jakarta.enterprise.inject.spi.PassivationCapable;
+import jakarta.enterprise.inject.spi.configurator.BeanConfigurator;
import org.apache.deltaspike.core.api.provider.BeanProvider;
import org.apache.deltaspike.core.util.ExceptionUtils;
import org.apache.deltaspike.proxy.spi.DeltaSpikeProxy;
@@ -43,13 +44,14 @@ import
org.apache.deltaspike.proxy.spi.invocation.DeltaSpikeProxyInvocationHandl
* @param <T> The class of the original class.
* @param <H> The class of the delegate {@link InvocationHandler}.
*/
-public class DeltaSpikeProxyContextualLifecycle<T, H extends InvocationHandler>
+public class DeltaSpikeProxyBeanConfigurator<T, H extends InvocationHandler>
{
private final Class<T> proxyClass;
private final Class<H> delegateInvocationHandlerClass;
private final Method[] delegateMethods;
private final Class<T> targetClass;
private final BeanManager beanManager;
+ private final BeanConfigurator<T> beanConfigurator;
private volatile DeltaSpikeProxyInvocationHandler
deltaSpikeProxyInvocationHandler;
@@ -57,10 +59,11 @@ public class DeltaSpikeProxyContextualLifecycle<T, H
extends InvocationHandler>
private volatile Bean<H> handlerBean;
private volatile CreationalContext<?> creationalContextOfDependentHandler;
- public DeltaSpikeProxyContextualLifecycle(Class<T> targetClass,
+ public DeltaSpikeProxyBeanConfigurator(Class<T> targetClass,
Class<H>
delegateInvocationHandlerClass,
DeltaSpikeProxyFactory
proxyFactory,
- BeanManager beanManager)
+ BeanManager beanManager,
+ BeanConfigurator<T>
beanConfigurator)
{
this.targetClass = targetClass;
this.delegateInvocationHandlerClass = delegateInvocationHandlerClass;
@@ -73,9 +76,23 @@ public class DeltaSpikeProxyContextualLifecycle<T, H extends
InvocationHandler>
AnnotatedType<T> annotatedType =
beanManager.createAnnotatedType(this.targetClass);
this.injectionTarget =
beanManager.getInjectionTargetFactory(annotatedType).createInjectionTarget(null);
}
+
+ this.beanConfigurator = beanConfigurator;
+ }
+
+ public DeltaSpikeProxyBeanConfigurator delegateCreateWith()
+ {
+ beanConfigurator.createWith((c) -> create(c));
+ return this;
+ }
+
+ public DeltaSpikeProxyBeanConfigurator delegateDestroyWith()
+ {
+ beanConfigurator.destroyWith((i, c) -> destroy(i, c));
+ return this;
}
- public T create(Bean bean, CreationalContext creationalContext)
+ protected T create(CreationalContext creationalContext)
{
try
{
@@ -111,7 +128,7 @@ public class DeltaSpikeProxyContextualLifecycle<T, H
extends InvocationHandler>
return null;
}
- public void destroy(Bean<T> bean, T instance, CreationalContext<T>
creationalContext)
+ protected void destroy(T instance, CreationalContext<T> creationalContext)
{
if (this.injectionTarget != null)
{
diff --git a/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
b/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
index 0d2c1529d..08594392c 100644
--- a/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
+++ b/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
@@ -20,7 +20,5 @@
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
- <interceptors>
-
<class>org.apache.deltaspike.proxy.util.EnableInterceptorsInterceptor</class>
- </interceptors>
+
</beans>