Java Code Examples for javax.annotation.Priority#value()

The following examples show how to use javax.annotation.Priority#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyFilterComparator.java    From incubator-tamaya with Apache License 2.0 6 votes vote down vote up
/**
 * Compare 2 filters for ordering the filter chain.
 *
 * @param filter1 the first filter
 * @param filter2 the second filter
 * @return the comparison result
 */
private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
    int ord1 = 0;
    int ord2 = 0;

    if(ServiceContext.PRIORITY_ANNOTATION_AVAILABLE) {
        Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
        Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
        if(prio1!=null) {
            ord1 = prio1.value();
        }
        if(prio2!=null) {
            ord2 = prio2.value();
        }
    }
    if (ord1 < ord2) {
        return -1;
    } else if (ord1 > ord2) {
        return 1;
    } else {
        return filter1.getClass().getName().compareTo(filter2.getClass().getName());
    }
}
 
Example 2
Source File: PriorityAwareServiceProvider.java    From javamoney-lib with Apache License 2.0 6 votes vote down vote up
public static int compareServices(Object o1, Object o2) {
    int prio1 = 0;
    int prio2 = 0;
    Priority prio1Annot = o1.getClass().getAnnotation(Priority.class);
    if (prio1Annot != null) {
        prio1 = prio1Annot.value();
    }
    Priority prio2Annot = o2.getClass().getAnnotation(Priority.class);
    if (prio2Annot != null) {
        prio2 = prio2Annot.value();
    }
    if (prio1 < prio2) {
        return 1;
    }
    if (prio2 < prio1) {
        return -1;
    }
    return o2.getClass().getSimpleName().compareTo(o1.getClass().getSimpleName());
}
 
Example 3
Source File: PriorityAwareServiceProvider.java    From jsr354-ri with Apache License 2.0 6 votes vote down vote up
public static int compareServices(Object o1, Object o2) {
    int prio1 = 0;
    int prio2 = 0;
    Priority prio1Annot = o1.getClass().getAnnotation(Priority.class);
    if (prio1Annot != null) {
        prio1 = prio1Annot.value();
    }
    Priority prio2Annot = o2.getClass().getAnnotation(Priority.class);
    if (prio2Annot != null) {
        prio2 = prio2Annot.value();
    }
    if (prio1 < prio2) {
        return 1;
    }
    if (prio2 < prio1) {
        return -1;
    }
    return o2.getClass().getSimpleName().compareTo(o1.getClass().getSimpleName());
}
 
Example 4
Source File: SmallRyeConfigBuilder.java    From smallrye-config with Apache License 2.0 5 votes vote down vote up
private static int getPriority(Converter<?> converter) {
    int priority = 100;
    Priority priorityAnnotation = converter.getClass().getAnnotation(Priority.class);
    if (priorityAnnotation != null) {
        priority = priorityAnnotation.value();
    }
    return priority;
}
 
Example 5
Source File: ServiceLoaders.java    From krazo with Apache License 2.0 5 votes vote down vote up
private int getPriority(Object o) {
    Priority priority = o.getClass().getAnnotation(Priority.class);
    if (priority != null) {
        return priority.value();
    } else {
        return 0;
    }
}
 
Example 6
Source File: Filter.java    From redkale with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Object o) {
    if (!(o instanceof Filter)) return 1;
    Priority p1 = this.getClass().getAnnotation(Priority.class);
    Priority p2 = o.getClass().getAnnotation(Priority.class);
    return (p2 == null ? 0 : p2.value()) - (p1 == null ? 0 : p1.value());
}
 
Example 7
Source File: ServiceContext.java    From incubator-tamaya with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the given instance for a @Priority annotation. If present the annotation's value is evaluated. If no such
 * annotation is present, a default priority of {@code 1} is returned.
 * @param o the instance, not {@code null}.
 * @return a priority, by default 1.
 */
static int getPriority(Object o){
    int prio = 1;
    if(PRIORITY_ANNOTATION_AVAILABLE) {
        Priority priority = o.getClass().getAnnotation(Priority.class);
        if (priority != null) {
            prio = priority.value();
        }
    }
    return prio;
}
 
Example 8
Source File: PriorityServiceComparator.java    From incubator-tamaya with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the given type optionally annotated with a @Priority. If present the annotation's createValue is evaluated.
 * If no such annotation is present, a default priority {@code 1} is returned.
 *
 * @param type the type, not {@code null}.
 * @return a priority, by default 1.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static int getPriority(Class type) {
    int prio = 1;
    if(ServiceContext.PRIORITY_ANNOTATION_AVAILABLE) {
        Priority priority = (Priority) type.getAnnotation(Priority.class);
        if (priority != null) {
            prio = priority.value();
        }
    }
    return prio;
}
 
Example 9
Source File: DefaultServiceContext.java    From incubator-tamaya with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the given instance for a @Priority annotation. If present the annotation's createValue is evaluated. If no such
 * annotation is present, a default priority of {@code 1} is returned.
 * @param o the instance, not {@code null}.
 * @return a priority, by default 1.
 */
public static int getPriority(Object o){
    int prio = 1;
    if(ServiceContext.PRIORITY_ANNOTATION_AVAILABLE) {
        Priority priority = o.getClass().getAnnotation(Priority.class);
        if (priority != null) {
            prio = priority.value();
        }
    }
    return prio;
}
 
Example 10
Source File: OSGIServiceComparator.java    From incubator-tamaya with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the given type optionally annotated with a @Priority. If present the annotation's createValue is evaluated.
 * If no such annotation is present, a default priority {@code 1} is returned.
 *
 * @param type the type, not {@code null}.
 * @return a priority, by default 1.
 */
public static int getPriority(Class<? extends Object> type) {
    int prio = 1;
    if(ServiceContext.PRIORITY_ANNOTATION_AVAILABLE) {
        Priority priority = type.getAnnotation(Priority.class);
        if (priority != null) {
            prio = priority.value();
        }
    }
    return prio;
}
 
Example 11
Source File: PriorityServiceComparator.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
/**
   * Checks the given type optionally annotated with a @Priority. If present the annotation's value is evaluated.
   * If no such annotation is present, a default priority {@code 1} is returned.
   *
   * @param type the type, not {@code null}.
   * @return a priority, by default 1.
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public static int getPriority(Class type) {
      int prio = 1;
Priority priority = (Priority)type.getAnnotation(Priority.class);
      if (priority != null) {
          prio = priority.value();
      }
      return prio;
  }
 
Example 12
Source File: OSGIServiceComparator.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the given type optionally annotated with a @Priority. If present the annotation's value is evaluated.
 * If no such annotation is present, a default priority {@code 1} is returned.
 *
 * @param type the type, not {@code null}.
 * @return a priority, by default 1.
 */
public static int getPriority(Class<?> type) {
    int prio = 1;
    Priority priority = type.getAnnotation(Priority.class);
    if (priority != null) {
        prio = priority.value();
    }
    return prio;
}
 
Example 13
Source File: ModuleBinder.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
private Integer rank(Class<?> type) {
    Priority priority = type.getDeclaredAnnotation(Priority.class);
    return priority == null ? null : 10000 - priority.value();
}
 
Example 14
Source File: RestClientBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static int getPriorityFromClass(Class<?> providerClass, int defaultValue) {
    Priority p = providerClass.getAnnotation(Priority.class);
    return p != null ? p.value() : defaultValue;
}
 
Example 15
Source File: DefaultConverters.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private int getConverterPriority(Class<? extends Converter<?>> converter) {
	Priority priority = converter.getAnnotation(Priority.class);
	return priority == null ? 0 : priority.value();
}