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.metadata.cache;
 
 import java.util.Set;
 
 
Abstract representation of an annotation model

Author(s):
Pete Muir
 
 public abstract class AnnotationModel<T extends Annotation> {
 
     // The underlying annotation
     private final AnnotatedType<T> annotatedAnnotation;
     // Is the data valid?
     protected boolean valid;

    
Constructor

Parameters:
type The annotation type
 
     public AnnotationModel(EnhancedAnnotation<T> enhancedAnnotatedAnnotation) {
         this. = enhancedAnnotatedAnnotation.slim();
         init(enhancedAnnotatedAnnotation);
     }

    
Initializes the type and validates it
 
     protected void init(EnhancedAnnotation<T> annotatedAnnotation) {
         initType(annotatedAnnotation);
         initValid(annotatedAnnotation);
         check(annotatedAnnotation);
     }

    
Initializes the type
 
     protected void initType(EnhancedAnnotation<T> annotatedAnnotation) {
         if (!Annotation.class.isAssignableFrom(getRawType())) {
         }
     }

    
Validates the data for correct annotation
 
     protected void initValid(EnhancedAnnotation<T> annotatedAnnotation) {
         this. = false;
         for (Class<? extends AnnotationannotationType : getMetaAnnotationTypes()) {
             if (annotatedAnnotation.isAnnotationPresent(annotationType)) {
                 this. = true;
             }
         }
     }
 
     protected void check(EnhancedAnnotation<T> annotatedAnnotation) {
         if ( && (!annotatedAnnotation.isAnnotationPresent(Retention.class) || annotatedAnnotation.isAnnotationPresent(Retention.class) && !annotatedAnnotation.getAnnotation(Retention.class).value().equals(.))) {
             this. = false;
             ..missingRetention(annotatedAnnotation);
         }
     }

    
Gets the type of the annotation

Returns:
The type
 
     public Class<T> getRawType() {
         return .getJavaClass();
     }

    
Gets the meta-annotation that should be present

Returns:
    protected abstract Set<Class<? extends Annotation>> getMetaAnnotationTypes();

    
Indicates if the annotation is valid

Returns:
True if valid, false otherwise
    public boolean isValid() {
        return ;
    }

    
Gets the annotated annotation

Returns:
The annotation
    public AnnotatedType<T> getAnnotatedAnnotation() {
        return ;
    }

    
Gets a string representation of the annotation model

Returns:
The string representation
    @Override
    public String toString() {
        return (isValid() ? "Valid" : "Invalid") + " annotation model for " + getRawType();
    }
New to GrepCode? Check out our FAQ X