Martin Peřina has uploaded a new change for review. Change subject: core: Add @Vetoed implementation for CDI 1.0 ......................................................................
core: Add @Vetoed implementation for CDI 1.0 1. Adds @Vetoed annotation which marks classes not to be instantiated by CDI container 2. Adds VetoExtension which listens for ProcessAnnotatedType events and vetoes processed class if it's annotated with @Vetoed This code should be removed when we will move to CDI 1.1+ container Change-Id: I95aaacbcb2e44e791e540235e3b9f3a4e193dee9 Bug-Url: https://bugzilla.redhat.com/1121327 Signed-off-by: Martin Perina <mper...@redhat.com> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/VetoExtension.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/Vetoed.java A backend/manager/modules/common/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 3 files changed, 47 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/40458/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/VetoExtension.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/VetoExtension.java new file mode 100644 index 0000000..4a045fa --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/VetoExtension.java @@ -0,0 +1,29 @@ +package org.ovirt.engine.core.common.utils.cdi; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TODO: This extension can be removed when we will used CDI 1.1+, becuse {@code @Vetoed} is a part of CDI 1.1+ + */ +public class VetoExtension implements Extension { + private static final Logger log = LoggerFactory.getLogger(VetoExtension.class); + + /** + * CDI observer method, listens to the {@link ProcessAnnotatedType} event to apply a veto to all beans marked with + * {@code Vetoed} annotation + * + * @param annotatedType + * Payload of the bootstrap event. + */ + public void vetoBeans(@Observes ProcessAnnotatedType annotatedType) { + if (annotatedType.getAnnotatedType().getAnnotation(Vetoed.class) != null) { + annotatedType.veto(); + log.debug("Vetoed class: {}", annotatedType.getAnnotatedType().getJavaClass()); + } + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/Vetoed.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/Vetoed.java new file mode 100644 index 0000000..1998392 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/cdi/Vetoed.java @@ -0,0 +1,17 @@ +package org.ovirt.engine.core.common.utils.cdi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(value = ElementType.TYPE) +@Retention(value = RetentionPolicy.RUNTIME) +/** + * Annotation is used to mark classes which shouldn't be instantiated by CDI processor. + * + * TODO: When we will move to CDI 1.1+, we should replace this annotation with standard implementation + * TODO: {@code javax.enterprise.inject.Vetoed} + */ +public @interface Vetoed { +} diff --git a/backend/manager/modules/common/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/backend/manager/modules/common/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension new file mode 100644 index 0000000..f17bb22 --- /dev/null +++ b/backend/manager/modules/common/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension @@ -0,0 +1 @@ +org.ovirt.engine.core.common.utils.cdi.VetoExtension -- To view, visit https://gerrit.ovirt.org/40458 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I95aaacbcb2e44e791e540235e3b9f3a4e193dee9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Peřina <mper...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches