Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, 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.Map;
 import java.util.Set;
 
 
 
Optimized representation of a qualifier. JDK annotation proxies are slooow, this class provides significantly faster equals/hashCode methods, that also correctly handle non binding attributes. Note that Weld is using this representation for interceptor bindings as well. See also org.jboss.weld.manager.BeanManagerImpl.resolveInterceptors(javax.enterprise.inject.spi.InterceptionType,java.util.Collection)

Author(s):
Stuart Douglas
Martin Kouba
 
 public class QualifierInstance {
 
     public static final QualifierInstance ANY = new QualifierInstance(Any.class);
     public static final QualifierInstance DEFAULT = new QualifierInstance(Default.class);
 
     private final Class<? extends AnnotationannotationClass;
     private final Map<AnnotatedMethod<?>, Objectvalues;
     private final int hashCode;
 
     public static Set<QualifierInstanceof(Set<AnnotationqualifiersMetaAnnotationStore store) {
         if (qualifiers.isEmpty()) {
             return Collections.emptySet();
         }
         final Set<QualifierInstanceret = new ArraySet<QualifierInstance>();
         for (Annotation a : qualifiers) {
             ret.add(QualifierInstance.of(astore));
         }
         return WeldCollections.immutableSet(ret);
     }
 
     public static Set<QualifierInstanceof(Bean<?> beanMetaAnnotationStore store) {
         if (bean instanceof RIBean<?>) {
             return ((RIBean<?>) bean).getQualifierInstances();
         }
         return of(bean.getQualifiers(), store);
     }

    

Parameters:
annotation
store
Returns:
a new qualifier instance for the given annotation
 
     public static QualifierInstance of(Annotation annotationMetaAnnotationStore store) {
         final Class<? extends AnnotationannotationClass = annotation.annotationType();
         return new QualifierInstance(annotationClasscreateValues(annotationannotationClassstore));
     }
 
     private QualifierInstance(final Class<? extends AnnotationannotationClass) {
         this(annotationClass, Collections.<AnnotatedMethod<?>, Object>emptyMap());
     }
 
     private QualifierInstance(Class<? extends AnnotationannotationClassMap<AnnotatedMethod<?>, Objectvalues) {
         this. = annotationClass;
         this. = values;
         this. = Objects.hashCode(annotationClassvalues);
     }
 
     private static Map<AnnotatedMethod<?>, ObjectcreateValues(final Annotation annotationInstancefinal Class<? extends AnnotationannotationClassfinal MetaAnnotationStore store) {
        final QualifierModel<? extends Annotationmodel = store.getBindingTypeModel(annotationClass);
        if(model.getAnnotatedAnnotation().getMethods().size() == 0) {
            return Collections.emptyMap();
        }
        final ImmutableMap.Builder<AnnotatedMethod<?>, Objectbuilder = ImmutableMap.builder();
        for (final AnnotatedMethod<?> method : model.getAnnotatedAnnotation().getMethods()) {
            if(!model.getNonBindingMembers().contains(method)) {
                try {
                    if (System.getSecurityManager() != null) {
                        AccessController.doPrivileged(SetAccessibleAction.of(method.getJavaMember()));
                    } else {
                        method.getJavaMember().setAccessible(true);
                    }
                    builder.put(methodmethod.getJavaMember().invoke(annotationInstance));
                } catch (IllegalAccessException e) {
                    throw new WeldException(e);
                } catch (InvocationTargetException e) {
                    throw new WeldException(e);
                }
            }
        }
        return builder.build();
    }
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final QualifierInstance that = (QualifierInstanceo;
        if (!.equals(that.annotationClass)) {
            return false;
        }
        if (!.equals(that.values)) {
            return false;
        }
        return true;
    }
    public Class<? extends AnnotationgetAnnotationClass() {
        return ;
    }
    @Override
    public int hashCode() {
        return ;
    }
    @Override
    public String toString() {
        return "QualifierInstance{" +
                "annotationClass=" +  +
                ", values=" +  +
                ", hashCode=" +  +
                '}';
    }
New to GrepCode? Check out our FAQ X