Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.resolution;
 
 import java.util.Set;
 
 
 
 public class ResolvableBuilder {
 
     private static final Class<?>[] FACADE_TYPES = new Class<?>[] { Event.classInstance.classProvider.class };
     private static final Class<?>[] METADATA_TYPES = new Class<?>[] { Interceptor.classDecorator.classBean.class };
     private static final Set<QualifierInstanceANY_SINGLETON = Collections.singleton(.);
 
     protected Class<?> rawType;
     protected final Set<Typetypes;
     protected final Set<QualifierInstancequalifierInstances;
     protected Bean<?> declaringBean;
     private final MetaAnnotationStore store;
     protected boolean delegate;
     protected final Set<Class<? extends Annotation>> annotationTypes;
 
     public ResolvableBuilder(final MetaAnnotationStore store) {
         this. = store;
         this. = new HashSet<Type>();
         this. = new HashSet<QualifierInstance>();
         this. = new HashSet<Class<? extends Annotation>>();
     }
 
     public ResolvableBuilder(BeanManagerImpl manager) {
         this(manager.getServices().get(MetaAnnotationStore.class));
     }
 
     public ResolvableBuilder(Type typefinal BeanManagerImpl beanManager) {
         this(beanManager);
         if (type != null) {
             this. = Reflections.getRawType(type);
             if ( == null || type instanceof TypeVariable<?>) {
                 throw ..cannotExtractRawType(type);
             }
             this..add(type);
         }
     }
 
     public ResolvableBuilder(InjectionPoint injectionPointfinal BeanManagerImpl manager) {
         this(injectionPoint.getType(), manager);
         addQualifiers(injectionPoint.getQualifiers(), injectionPoint);
         setDeclaringBean(injectionPoint.getBean());
         this. = injectionPoint.isDelegate();
     }
 
     public ResolvableBuilder setDeclaringBean(Bean<?> declaringBean) {
         this. = declaringBean;
         return this;
     }
 
     public ResolvableBuilder addType(Type type) {
         this..add(type);
         return this;
     }
 
     public ResolvableBuilder addTypes(Set<Typetypes) {
         this..addAll(types);
        return this;
    }
    public boolean isDelegate() {
        return ;
    }
    public void setDelegate(boolean delegate) {
        this. = delegate;
    }
    public Resolvable create() {
        if (.isEmpty()) {
            this..add(.);
        }
        for (Type type : ) {
            Class<?> rawType = Reflections.getRawType(type);
            for (Class<?> facadeType : ) {
                if (facadeType.equals(rawType)) {
                    return createFacade(facadeType);
                }
            }
            for (Class<?> metadataType : ) {
                if (metadataType.equals(rawType)) {
                    return createMetadataProvider(metadataType);
                }
            }
        }
    }
    private Resolvable createFacade(Class<?> rawType) {
        Set<Typetypes = Collections.<Type>singleton(rawType);
        return new ResolvableImpl(rawTypetypes);
    }
    // just as facade but we keep the qualifiers so that we can recognize Bean from @Intercepted Bean.
    private Resolvable createMetadataProvider(Class<?> rawType) {
        Set<Typetypes = Collections.<Type>singleton(rawType);
        return new ResolvableImpl(rawTypetypes);
    }
    public ResolvableBuilder addQualifier(Annotation qualifier) {
        return addQualifier(qualifiernull);
    }
    private ResolvableBuilder addQualifier(Annotation qualifierInjectionPoint injectionPoint) {
        QualifierInstance qualifierInstance = QualifierInstance.of(qualifier);
        final Class<? extends AnnotationannotationType = qualifierInstance.getAnnotationClass();
        // Handle the @New qualifier special case
        if (annotationType.equals(New.class)) {
            New newQualifier = New.class.cast(qualifier);
            if (newQualifier.value().equals(New.class) &&  == null) {
                throw new IllegalStateException("Cannot transform @New when there is no known raw type");
            } else if (newQualifier.value().equals(New.class)) {
                qualifier = new NewLiteral();
                qualifierInstance = QualifierInstance.of(qualifier);
            }
        } else if (injectionPoint != null && annotationType.equals(Named.class)) {
            Named named = (Namedqualifier;
            if (named.value().equals("")) {
                // WELD-1739
                // This is an injection point with an @Named qualifier, with no value specified, we need to assume the name of the field in the value
                named = new NamedLiteral(injectionPoint.getMember().getName());
                qualifier = named;
                qualifierInstance = QualifierInstance.of(named);
            }
        }
        checkQualifier(qualifierqualifierInstanceannotationType);
        this..add(qualifierInstance);
        this..add(annotationType);
        return this;
    }

    
Adds a given qualifier without any checks. This method should be used with care.
        this..add(qualifier);
        return this;
    }
    public ResolvableBuilder addQualifiers(Annotation[] qualifiers) {
        for (Annotation qualifier : qualifiers) {
            addQualifier(qualifier);
        }
        return this;
    }
    public ResolvableBuilder addQualifiers(Collection<Annotationqualifiers) {
        return addQualifiers(qualifiersnull);
    }
    private ResolvableBuilder addQualifiers(Collection<AnnotationqualifiersInjectionPoint injectionPoint) {
        for (Annotation qualifier : qualifiers) {
            addQualifier(qualifierinjectionPoint);
        }
        return this;
    }
    protected void checkQualifier(Annotation qualifierQualifierInstance qualifierInstanceClass<? extends AnnotationannotationType) {
        if (!.getBindingTypeModel(annotationType).isValid()) {
            throw ..invalidQualifier(qualifier);
        }
        if (.contains(annotationType)) {
            throw ..duplicateQualifiers(qualifier);
        }
    }
    protected static class ResolvableImpl implements Resolvable {
        private final Set<QualifierInstancequalifierInstances;
        private final Set<TypetypeClosure;
        private final Class<?> rawType;
        private final Bean<?> declaringBean;
        private final boolean delegate;
        protected ResolvableImpl(Class<?> rawTypeSet<TypetypeClosureBean<?> declaringBeanfinal Set<QualifierInstancequalifierInstancesboolean delegate) {
            this. = typeClosure;
            this. = rawType;
            this. = declaringBean;
            this. = qualifierInstances;
            this. = delegate;
        }
        @Override
        public Set<QualifierInstancegetQualifiers() {
            return ;
        }
        @Override
        public Set<TypegetTypes() {
            return ;
        }
        @Override
        public Class<?> getJavaClass() {
            return ;
        }
        @Override
        public Bean<?> getDeclaringBean() {
            return ;
        }
        @Override
        public String toString() {
            return "Types: " + getTypes() + "; Bindings: " + getQualifiers();
        }
        @Override
        public int hashCode() {
            int result = 17;
            result = 31 * result + this.getTypes().hashCode();
            result = 31 * result + this..hashCode();
            return result;
        }
        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o instanceof ResolvableImpl) {
                ResolvableImpl r = (ResolvableImplo;
                return this.getTypes().equals(r.getTypes()) && this..equals(r.qualifierInstances);
            }
            return false;
        }
        @Override
        public boolean isDelegate() {
            return ;
        }
    }
        return ;
    }
New to GrepCode? Check out our FAQ X