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.util;
 
 
A base class for utility classes that represent annotations, classes etc

Author(s):
Pete Muir
 
 public class ApiAbstraction {
 
     private static final Class<DummyAnnotationDUMMY_ANNOTATION = DummyAnnotation.class;
 
     private static final Class<DummyDUMMY_CLASS = Dummy.class;
 
     private ResourceLoader resourceLoader;

    
"Not found" annotation
 
     public @interface DummyAnnotation {
     }

    
"Not found" class
 
     public interface Dummy {
     }

    
"Not found" enumeration value.
 
     public static enum DummyEnum {
         DUMMY_VALUE
     }

    
Constructor

Parameters:
resourceLoader The root resource loaderS
 
     public ApiAbstraction(ResourceLoader resourceLoader) {
         this. = resourceLoader;
     }

    
Initializes an annotation class

Parameters:
name The name of the annotation class
Returns:
The instance of the annotation. Returns a dummy if the class was not found
 
     @SuppressWarnings("unchecked")
     protected Class<? extends AnnotationannotationTypeForName(String name) {
         try {
             return (Class<? extends Annotation>) .classForName(name);
         } catch (ResourceLoadingException cnfe) {
             return ;
         }
     }

    
Initializes a type

Parameters:
name The name of the class
Returns:
The instance of the class. Returns a dummy if the class was not found.
 
     protected Class<?> classForName(String name) {
         try {
             return .classForName(name);
         } catch (ResourceLoadingException cnfe) {
             return ;
         }
     }
 
     protected Object enumValue(Class<?> clazzString memberName) {
         Preconditions.checkArgumentNotNull(memberName"memberName");
        if (!clazz.isEnum()) {
            throw ..classNotEnum(clazz);
        }
        try {
            Field field = clazz.getField(memberName);
            return field.get(null);
        } catch (SecurityException e) {
            return null;
        } catch (NoSuchFieldException e) {
            return null;
        } catch (java.lang.IllegalArgumentException e) {
            return null;
        } catch (IllegalAccessException e) {
            return null;
        }
    }
New to GrepCode? Check out our FAQ X