org.jboss.weld.metadata.cache.MetaAnnotationStore Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, 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.metadata.cache;
import static org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue;
import static org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;
import javax.enterprise.inject.spi.Bean;
import javax.inject.Named;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.resolution.QualifierInstance;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet;
/**
* Metadata singleton for holding EJB metadata, scope models etc.
*
* @author Pete Muir
*/
public class MetaAnnotationStore implements Service {
private abstract static class AbstractMetaAnnotationFunction> extends
CacheLoader, M> {
private final ClassTransformer classTransformer;
private AbstractMetaAnnotationFunction(ClassTransformer classTransformer) {
this.classTransformer = classTransformer;
}
public ClassTransformer getClassTransformer() {
return classTransformer;
}
}
private static class StereotypeFunction extends AbstractMetaAnnotationFunction> {
public StereotypeFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
@Override
public StereotypeModel load(Class from) {
return new StereotypeModel(getClassTransformer().getEnhancedAnnotation(from));
}
}
private static class ScopeFunction extends AbstractMetaAnnotationFunction> {
public ScopeFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
@Override
public ScopeModel load(Class from) {
return new ScopeModel(getClassTransformer().getEnhancedAnnotation(from));
}
}
private static class QualifierFunction extends AbstractMetaAnnotationFunction> {
public QualifierFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
@Override
public QualifierModel load(Class from) {
return new QualifierModel(getClassTransformer().getEnhancedAnnotation(from));
}
}
private static class InterceptorBindingFunction extends AbstractMetaAnnotationFunction> {
public InterceptorBindingFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
@Override
public InterceptorBindingModel load(Class from) {
return new InterceptorBindingModel(getClassTransformer().getEnhancedAnnotation(from));
}
}
private static class QualifierInstanceFunction extends CacheLoader {
private final MetaAnnotationStore metaAnnotationStore;
private QualifierInstanceFunction(MetaAnnotationStore metaAnnotationStore) {
super();
this.metaAnnotationStore = metaAnnotationStore;
}
@Override
public QualifierInstance load(Annotation key) throws Exception {
return QualifierInstance.of(key, metaAnnotationStore);
}
}
// The stereotype models
private final LoadingCache, StereotypeModel> stereotypes;
// The scope models
private final LoadingCache, ScopeModel> scopes;
// The binding type models
private final LoadingCache, QualifierModel> qualifiers;
// the interceptor bindings
private final LoadingCache, InterceptorBindingModel> interceptorBindings;
private final LoadingCache qualifierInstanceCache;
private final SharedObjectCache sharedObjectCache;
public MetaAnnotationStore(ClassTransformer classTransformer) {
CacheBuilder
© 2015 - 2025 Weber Informatics LLC | Privacy Policy