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.
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.weld.bootstrap;
import static org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue;
import static org.jboss.weld.util.reflection.Reflections.cast;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.enterprise.inject.spi.Bean;
import org.jboss.weld.bean.AbstractBean;
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.AbstractProducerBean;
import org.jboss.weld.bean.ProducerMethod;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bootstrap.api.helpers.AbstractBootstrapService;
import org.jboss.weld.manager.BeanManagerImpl;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multisets;
/**
* Holds information about specialized beans.
*
* @author Jozef Hartinger
*
*/
public class SpecializationAndEnablementRegistry extends AbstractBootstrapService {
private class SpecializedBeanResolverForBeanManager extends CacheLoader {
@Override
public SpecializedBeanResolver load(BeanManagerImpl manager) {
return new SpecializedBeanResolver(buildAccessibleBeanDeployerEnvironments(manager));
}
private Set buildAccessibleBeanDeployerEnvironments(BeanManagerImpl manager) {
Set result = new HashSet();
result.add(environmentByManager.get(manager));
buildAccessibleBeanDeployerEnvironments(manager, result);
return result;
}
private void buildAccessibleBeanDeployerEnvironments(BeanManagerImpl manager, Collection result) {
for (BeanManagerImpl accessibleManager : manager.getAccessibleManagers()) {
BeanDeployerEnvironment environment = environmentByManager.get(accessibleManager);
if (!result.contains(environment)) {
result.add(environment);
buildAccessibleBeanDeployerEnvironments(accessibleManager, result);
}
}
}
}
private class BeansSpecializedByBean extends CacheLoader, Set extends AbstractBean, ?>>> {
@Override
public Set extends AbstractBean, ?>> load(Bean> specializingBean) {
Set extends AbstractBean, ?>> result = null;
if (specializingBean instanceof AbstractClassBean>) {
result = apply((AbstractClassBean>) specializingBean);
}
if (specializingBean instanceof ProducerMethod, ?>) {
result = apply((ProducerMethod, ?>) specializingBean);
}
if (result != null) {
if (isEnabledInAnyBeanDeployment(specializingBean)) {
specializedBeansSet.addAll(result);
}
return result;
}
throw new IllegalArgumentException("Unsupported bean type " + specializingBean);
}
private Set> apply(AbstractClassBean> bean) {
return getSpecializedBeanResolver(bean).resolveSpecializedBeans(bean);
}
private Set> apply(ProducerMethod, ?> bean) {
return getSpecializedBeanResolver(bean).resolveSpecializedBeans(bean);
}
private SpecializedBeanResolver getSpecializedBeanResolver(RIBean> bean) {
return getCacheValue(specializedBeanResolvers, bean.getBeanManager());
}
}
private final LoadingCache specializedBeanResolvers;
private final Map environmentByManager = new ConcurrentHashMap();
// maps specializing beans to the set of specialized beans
private final LoadingCache, Set extends AbstractBean, ?>>> specializedBeans;
// fast lookup structure that allows us to figure out if a given bean is specialized in any of the bean deployments
private final Multiset> specializedBeansSet = ConcurrentHashMultiset.create();
public SpecializationAndEnablementRegistry() {
CacheBuilder