org.jboss.weld.metadata.cache.MetaAnnotationStore Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weld-osgi-bundle Show documentation
Show all versions of weld-osgi-bundle Show documentation
Weld runtime packaged as an OSGi bundle
/*
* 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.getCastCacheValue;
import java.lang.annotation.Annotation;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.resources.ClassTransformer;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
/**
* 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);
}
public StereotypeModel load(Class from) {
return new StereotypeModel(from, getClassTransformer());
}
}
private static class ScopeFunction extends AbstractMetaAnnotationFunction> {
public ScopeFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
public ScopeModel load(Class from) {
return new ScopeModel(from, getClassTransformer());
}
}
private static class QualifierFunction extends AbstractMetaAnnotationFunction> {
public QualifierFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
public QualifierModel load(Class from) {
return new QualifierModel(from, getClassTransformer());
}
}
private static class InterceptorBindingFunction extends AbstractMetaAnnotationFunction> {
public InterceptorBindingFunction(ClassTransformer classTransformer) {
super(classTransformer);
}
public InterceptorBindingModel load(Class from) {
return new InterceptorBindingModel(from, getClassTransformer());
}
}
// The stereotype models
private LoadingCache, StereotypeModel> stereotypes;
// The scope models
private LoadingCache, ScopeModel> scopes;
// The binding type models
private LoadingCache, QualifierModel> qualifiers;
// the interceptor bindings
private LoadingCache, InterceptorBindingModel> interceptorBindings;
public MetaAnnotationStore(ClassTransformer classTransformer) {
CacheBuilder