Package org.apache.uima.fit.descriptor

Examples of org.apache.uima.fit.descriptor.ExternalResource


    for (Field field : cls.getDeclaredFields()) {
      if (!ReflectionUtil.isAnnotationPresent(field, ExternalResource.class)) {
        continue;
      }
     
      ExternalResource era = ReflectionUtil.getAnnotation(field, ExternalResource.class);

      // Get the resource key. If it is a nested resource, also get the prefix.
      String key = era.key();
      if (key.length() == 0) {
        key = field.getName();
      }
      if (object instanceof ExternalResourceAware) {
        String prefix = ((ExternalResourceAware) object).getResourceName();
        if (prefix != null) {
          key = prefix + PREFIX_SEPARATOR + key;
        }
      }

      // Obtain the resource
      Object value = getResourceObject(context, key);
      if (value instanceof ExternalResourceLocator) {
        value = ((ExternalResourceLocator) value).getResource();
      }

      // Sanity checks
      if (value == null && era.mandatory()) {
        throw new ResourceInitializationException(new IllegalStateException("Mandatory resource ["
                + key + "] is not set on [" + baseCls + "]"));
      }

      // Now record the setting and optionally apply it to the given
View Full Code Here


   * Creates an ExternalResourceDependency for a field annotated with
   * {@link org.apache.uima.fit.descriptor.ExternalResource}.
   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public static ExternalResourceDependency createExternalResourceDependency(Field field) {
    ExternalResource era = ReflectionUtil.getAnnotation(field, ExternalResource.class);

    // Get the binding key for the specified field. If no key is set, use the field name as key.
    String key = era.key();
    if (key.length() == 0) {
      key = field.getName();
    }

    // Get the type of class/interface a resource has to implement to bind to the annotated field.
    // If no API is set, get it from the annotated field type.
    Class<? extends Resource> api = era.api();
    // If no api is specified, look at the annotated field
    if (api == Resource.class) {
      if (Resource.class.isAssignableFrom(field.getType())
              || SharedResourceObject.class.isAssignableFrom(field.getType())) {
        // If no API is set, check if the field type is already a resource type
        api = (Class<? extends Resource>) field.getType();
      } else {
        // If the field does not have a resource type, assume whatever. This allows to use
        // a resource locator without having to specify the api parameter. It also allows
        // to directly inject Java objects - yes, I know that Object does not extend
        // Resource - REC, 2011-03-25
        api = (Class) Object.class;
      }
    }

    return ExternalResourceFactory.createExternalResourceDependency(key, api, !era.mandatory(),
            era.description());
  }
View Full Code Here

   *          the field to analyze
   * @return a external resource dependency
   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public static ExternalResourceDependency createExternalResourceDependency(Field field) {
    ExternalResource era = ReflectionUtil.getAnnotation(field, ExternalResource.class);

    // Get the binding key for the specified field. If no key is set, use the field name as key.
    String key = era.key();
    if (key.length() == 0) {
      key = field.getName();
    }

    // Get the type of class/interface a resource has to implement to bind to the annotated field.
    // If no API is set, get it from the annotated field type.
    Class<? extends Resource> api = era.api();
    // If no api is specified, look at the annotated field
    if (api == Resource.class) {
      if (Resource.class.isAssignableFrom(field.getType())
              || SharedResourceObject.class.isAssignableFrom(field.getType())) {
        // If no API is set, check if the field type is already a resource type
        api = (Class<? extends Resource>) field.getType();
      } else {
        // If the field does not have a resource type, assume whatever. This allows to use
        // a resource locator without having to specify the api parameter. It also allows
        // to directly inject Java objects - yes, I know that Object does not extend
        // Resource - REC, 2011-03-25
        api = (Class) Object.class;
      }
    }

    return ExternalResourceFactory.createExternalResourceDependency(key, api, !era.mandatory(),
            era.description());
  }
View Full Code Here

TOP

Related Classes of org.apache.uima.fit.descriptor.ExternalResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.