Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.openejb.cdi;
import org.apache.openejb.BeanContext;
import org.apache.openejb.BeanType;
import org.apache.openejb.InterfaceType;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.OpenEJBRuntimeException;
import org.apache.openejb.core.ivm.IntraVmProxy;
import org.apache.openejb.util.proxy.ProxyManager;
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.OwbBean;
import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.config.WebBeansFinder;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.event.ObserverMethodImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
import org.apache.webbeans.portable.events.generics.GProcessSessionBean;
import org.apache.webbeans.proxy.NormalScopeProxyFactory;
import org.apache.webbeans.spi.ResourceInjectionService;
import org.apache.webbeans.spi.SecurityService;
import org.apache.webbeans.spi.TransactionService;
import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
import org.apache.webbeans.util.WebBeansUtil;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.ObserverMethod;
import javax.enterprise.inject.spi.PassivationCapable;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.Producer;
import javax.enterprise.inject.spi.SessionBeanType;
import javax.inject.Provider;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
public class CdiPlugin extends AbstractOwbPlugin implements OpenWebBeansJavaEEPlugin, OpenWebBeansEjbPlugin {
private Map, BeanContext> beans;
private WebBeansContext webBeansContext;
private CdiAppContextsService contexsServices;
private ClassLoader classLoader;
private Map, Object> cacheProxies;
public void setWebBeansContext(final WebBeansContext webBeansContext) {
this.webBeansContext = webBeansContext;
if (!WebappWebBeansContext.class.isInstance(webBeansContext)) {
cacheProxies = new ConcurrentHashMap, Object>();
} else { // share cache of proxies between the whole app otherwise hard to share an EJB between a webapp and the lib part of the app
cacheProxies = CdiPlugin.class.cast(WebappWebBeansContext.class.cast(webBeansContext).getParent().getPluginLoader().getEjbPlugin()).cacheProxies;
}
}
public void setClassLoader(final ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
public void shutDown() {
super.shutDown();
// this plugin may have been installed in a non-ejb lifecycle???
if (beans != null) {
this.beans.clear();
}
}
public void configureDeployments(final List ejbDeployments) {
beans = new WeakHashMap, BeanContext>();
for (final BeanContext deployment : ejbDeployments) {
if (deployment.getComponentType().isSession()) {
if (deployment.isLocalbean() && !deployment.isDynamicallyImplemented()) {
beans.put(deployment.get(BeanContext.ProxyClass.class).getProxy(), deployment);
}
beans.put(deployment.getBeanClass(), deployment);
}
}
}
public CdiAppContextsService getContexsServices() {
return contexsServices;
}
public void startup() {
this.contexsServices = (CdiAppContextsService) webBeansContext.getContextsService();
this.contexsServices.init(null);
}
public void stop() throws OpenEJBException {
final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
// Setting context class loader for cleaning
Thread.currentThread().setContextClassLoader(classLoader);
// Fire shut down
webBeansContext.getBeanManagerImpl().fireEvent(new BeforeShutdownImpl());
// Destroys context
this.contexsServices.destroy(null);
// Free all plugin resources
webBeansContext.getPluginLoader().shutDown();
// Clear extensions
webBeansContext.getExtensionLoader().clear();
// Delete Resolutions Cache
webBeansContext.getBeanManagerImpl().getInjectionResolver().clearCaches();
// Delete AnnotateTypeCache
webBeansContext.getAnnotatedElementFactory().clear();
// Clear the resource injection service
final CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class);
injectionServices.clear();
// Clear singleton list
WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
} catch (final Exception e) {
throw new OpenEJBException(e);
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}
@Override
public T getSupportedService(final Class serviceClass) {
return supportService(serviceClass) ? serviceClass.cast(this) : null;
}
@Override
public void isManagedBean(final Class> clazz) {
}
@Override
public boolean supportService(final Class> serviceClass) {
return serviceClass == TransactionService.class || serviceClass == SecurityService.class;
}
@Override
public Object getSessionBeanProxy(final Bean> inBean, final Class> interfce, final CreationalContext> creationalContext) {
Object instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
synchronized (inBean) { // singleton for the app so safe to sync on it
instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
final Class extends Annotation> scopeClass = inBean.getScope();
final CdiEjbBean