This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch dev/2.0.0-M2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit c4985068ea53d24d3c68543953008383b3aa3084
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Sun Oct 29 09:33:17 2017 +0100

    ISIS-1755 JEE 7+ allow coexistence of CDI and Isis' ServiceInjector
---
 .../webapp/jee/IsisCDIBeanScanInterceptor.java     | 97 ++++++++++++++++++++++
 .../services/javax.enterprise.inject.spi.Extension |  1 +
 2 files changed, 98 insertions(+)

diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/IsisCDIBeanScanInterceptor.java
 
b/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/IsisCDIBeanScanInterceptor.java
new file mode 100644
index 0000000..6632a59
--- /dev/null
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/webapp/jee/IsisCDIBeanScanInterceptor.java
@@ -0,0 +1,97 @@
+/*
+ * 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.isis.core.webapp.jee;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.services.metrics.MetricsService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * A CDI inject extension @see <a 
href="https://docs.jboss.org/weld/reference/latest/en-US/html/extend.html";>weld</a>,
+ * that lets CDI ignore certain Beans we declare tabu. 
+ * <p>
+ * This extension is registered as a service provider by creating a file named 
+ * {@code META-INF/services/javax.enterprise.inject.spi.Extension}, 
+ * which contains the name of this extension class.
+ * </p>
+ * 
+ * <p>
+ * Beans declared tabu are managed (meaning instantiation and dependency 
injection) 
+ * by Isis itself. All other Beans are allowed to be managed by CDI.
+ * </p>
+ * 
+ * @author ahu...@apache.org
+ *
+ */
+final class IsisCDIBeanScanInterceptor implements Extension {
+       
+       private static final Logger log = 
LoggerFactory.getLogger(IsisCDIBeanScanInterceptor.class);
+
+       /**
+        * Declaration of Beans that are managed by Isis and should be ignored 
by CDI. 
+        * (in addition to those that have the @DomainService annotation)
+        */
+       private static final Set<String> tabu = new HashSet<>();
+       {
+               tabu.add(MetricsService.class.getName());
+       }
+       
+       void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event) {
+               log.info("beginning the scanning process");
+       }
+
+       <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event) {
+
+               final String className = 
event.getAnnotatedType().getJavaClass().getName();
+               
+               if(isTabu(className, event)) {
+                       log.debug("veto type: " + className);
+                       event.veto();
+               } else {
+                       log.debug("allowing type: " + className);
+               }
+       }
+
+       void afterBeanDiscovery(@Observes AfterBeanDiscovery event) {
+               log.info("finished the scanning process");
+       }
+       
+       // -- HELPER
+       
+       private boolean isTabu(String className, ProcessAnnotatedType<?> event) 
{
+               if(tabu.contains(className))
+                       return true;
+               
if(event.getAnnotatedType().isAnnotationPresent(DomainService.class))
+                       return true;
+               
+               return false;
+       }
+
+}
diff --git 
a/core/runtime/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
 
b/core/runtime/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..1be69b2
--- /dev/null
+++ 
b/core/runtime/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.apache.isis.core.webapp.jee.IsisCDIBeanScanInterceptor
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
ahu...@apache.org.

Reply via email to