use of javax.annotation.Priority in project jersey by jersey.
the class ComponentBag method modelFor.
/**
* Create a contract provider for a given component class.
*
* @param componentClass component class to create contract provider model for.
* @param defaultPriority default component priority. If {@value ContractProvider#NO_PRIORITY},
* the value from the component class {@link javax.annotation.Priority} annotation will be used
* (if any).
* @param contractMap map of contracts and their binding priorities. If {@code null}, the contracts will
* gathered by introspecting the component class. Content of the contract map
* may be modified during the registration processing.
* @param modelEnhancer custom contract provider model enhancer.
* @return contract provider model for the class.
*/
private static ContractProvider modelFor(final Class<?> componentClass, final int defaultPriority, final Map<Class<?>, Integer> contractMap, final Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) {
Map<Class<?>, Integer> contracts = contractMap;
if (contracts == null) {
// introspect
contracts = asMap(Providers.getProviderContracts(componentClass));
} else {
// filter custom contracts
final Iterator<Class<?>> it = contracts.keySet().iterator();
while (it.hasNext()) {
final Class<?> contract = it.next();
if (contract == null) {
it.remove();
continue;
}
boolean failed = false;
if (!Providers.isSupportedContract(contract)) {
Errors.error(LocalizationMessages.CONTRACT_NOT_SUPPORTED(contract, componentClass), Severity.WARNING);
failed = true;
}
if (!contract.isAssignableFrom(componentClass)) {
Errors.error(LocalizationMessages.CONTRACT_NOT_ASSIGNABLE(contract, componentClass), Severity.WARNING);
failed = true;
}
if (failed) {
it.remove();
}
}
}
final ContractProvider.Builder builder = ContractProvider.builder(componentClass).addContracts(contracts).defaultPriority(defaultPriority);
// Process annotations (priority, name bindings, scope)
final boolean useAnnotationPriority = defaultPriority == ContractProvider.NO_PRIORITY;
for (Annotation annotation : componentClass.getAnnotations()) {
if (annotation instanceof Priority) {
if (useAnnotationPriority) {
builder.defaultPriority(((Priority) annotation).value());
}
} else {
for (Annotation metaAnnotation : annotation.annotationType().getAnnotations()) {
if (metaAnnotation instanceof NameBinding) {
builder.addNameBinding(annotation.annotationType());
}
if (metaAnnotation instanceof Scope) {
builder.scope(annotation.annotationType());
}
}
}
}
return modelEnhancer.apply(builder);
}
use of javax.annotation.Priority in project Payara by payara.
the class PayaraConfig method getPriority.
private int getPriority(Converter converter) {
int result = 100;
Priority annotation = converter.getClass().getAnnotation(Priority.class);
if (annotation != null) {
result = annotation.value();
}
return result;
}
use of javax.annotation.Priority in project core by weld.
the class ObserverMethodConfiguratorImpl method read.
@Override
public ObserverMethodConfigurator<T> read(Method method) {
checkArgumentNotNull(method);
Set<Parameter> eventParameters = Configurators.getAnnotatedParameters(method, Observes.class, ObservesAsync.class);
checkEventParams(eventParameters, method);
Parameter eventParameter = eventParameters.iterator().next();
Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
if (observesAnnotation != null) {
reception(observesAnnotation.notifyObserver());
transactionPhase(observesAnnotation.during());
} else {
reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
}
Priority priority = method.getAnnotation(Priority.class);
if (priority != null) {
priority(priority.value());
}
beanClass(eventParameter.getDeclaringExecutable().getDeclaringClass());
observedType(eventParameter.getType());
qualifiers(Configurators.getQualifiers(eventParameter));
return this;
}
use of javax.annotation.Priority in project core by weld.
the class ObserverMethodConfiguratorImpl method read.
@Override
public ObserverMethodConfigurator<T> read(AnnotatedMethod<?> method) {
checkArgumentNotNull(method);
Set<AnnotatedParameter<?>> eventParameters = method.getParameters().stream().filter((p) -> p.isAnnotationPresent(Observes.class) || p.isAnnotationPresent(ObservesAsync.class)).collect(Collectors.toSet());
checkEventParams(eventParameters, method.getJavaMember());
AnnotatedParameter<?> eventParameter = eventParameters.iterator().next();
Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
if (observesAnnotation != null) {
reception(observesAnnotation.notifyObserver());
transactionPhase(observesAnnotation.during());
} else {
reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
}
Priority priority = method.getAnnotation(Priority.class);
if (priority != null) {
priority(priority.value());
}
beanClass(eventParameter.getDeclaringCallable().getDeclaringType().getJavaClass());
observedType(eventParameter.getBaseType());
qualifiers(Configurators.getQualifiers(eventParameter));
return this;
}
use of javax.annotation.Priority in project jsr354-ri by JavaMoney.
the class PriorityAwareServiceProvider method compareServices.
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());
}
Aggregations