Search in sources :

Example 1 with Priority

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);
}
Also used : Scope(javax.inject.Scope) ContractProvider(org.glassfish.jersey.model.ContractProvider) Priority(javax.annotation.Priority) NameBinding(javax.ws.rs.NameBinding) Annotation(java.lang.annotation.Annotation)

Example 2 with Priority

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;
}
Also used : Priority(javax.annotation.Priority)

Example 3 with Priority

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;
}
Also used : Observes(javax.enterprise.event.Observes) Priority(javax.annotation.Priority) Parameter(java.lang.reflect.Parameter) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter)

Example 4 with Priority

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;
}
Also used : EventLogger(org.jboss.weld.logging.EventLogger) Preconditions.checkArgumentNotNull(org.jboss.weld.util.Preconditions.checkArgumentNotNull) ObserverMethod(javax.enterprise.inject.spi.ObserverMethod) ObservesAsync(javax.enterprise.event.ObservesAsync) HashSet(java.util.HashSet) Reception(javax.enterprise.event.Reception) Parameter(java.lang.reflect.Parameter) Observes(javax.enterprise.event.Observes) Formats(org.jboss.weld.util.reflection.Formats) EventContext(javax.enterprise.inject.spi.EventContext) Method(java.lang.reflect.Method) SyntheticObserverMethod(org.jboss.weld.event.SyntheticObserverMethod) CovariantTypes(org.jboss.weld.resolution.CovariantTypes) ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) Extension(javax.enterprise.inject.spi.Extension) Set(java.util.Set) ObserverException(javax.enterprise.event.ObserverException) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) Collectors(java.util.stream.Collectors) Priority(javax.annotation.Priority) Type(java.lang.reflect.Type) ObserverMethodConfigurator(javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator) Annotation(java.lang.annotation.Annotation) Collections(java.util.Collections) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) TransactionPhase(javax.enterprise.event.TransactionPhase) ObservesAsync(javax.enterprise.event.ObservesAsync) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) Observes(javax.enterprise.event.Observes) Priority(javax.annotation.Priority)

Example 5 with Priority

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());
}
Also used : Priority(javax.annotation.Priority)

Aggregations

Priority (javax.annotation.Priority)14 Annotation (java.lang.annotation.Annotation)2 Parameter (java.lang.reflect.Parameter)2 Observes (javax.enterprise.event.Observes)2 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)2 MandatoryDocumentInitializer (com.xpn.xwiki.doc.MandatoryDocumentInitializer)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ObserverException (javax.enterprise.event.ObserverException)1 ObservesAsync (javax.enterprise.event.ObservesAsync)1 Reception (javax.enterprise.event.Reception)1 TransactionPhase (javax.enterprise.event.TransactionPhase)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 EventContext (javax.enterprise.inject.spi.EventContext)1 Extension (javax.enterprise.inject.spi.Extension)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1