use of org.glassfish.jersey.server.model.Parameterized in project jersey by jersey.
the class ParameterValueHelper method createValueProviders.
/**
* Create list of parameter value providers for the given {@link Parameterized
* parameterized} resource model component.
*
* @param injectionManager injection manager.
* @param parameterized parameterized resource model component.
* @return list of parameter value providers for the parameterized component.
*/
public static List<ParamValueFactoryWithSource<?>> createValueProviders(InjectionManager injectionManager, Parameterized parameterized) {
if ((null == parameterized.getParameters()) || (0 == parameterized.getParameters().size())) {
return Collections.emptyList();
}
List<ValueSupplierProvider> valueSupplierProviders = Providers.getProviders(injectionManager, ValueSupplierProvider.class).stream().sorted((o1, o2) -> o2.getPriority().getWeight() - o1.getPriority().getWeight()).collect(Collectors.toList());
boolean entityParamFound = false;
final List<ParamValueFactoryWithSource<?>> providers = new ArrayList<>(parameterized.getParameters().size());
for (final Parameter parameter : parameterized.getParameters()) {
final Parameter.Source parameterSource = parameter.getSource();
entityParamFound = entityParamFound || Parameter.Source.ENTITY == parameterSource;
final Supplier<?> valueSupplier = getParamValueSupplier(valueSupplierProviders, parameter);
if (valueSupplier != null) {
providers.add(wrapParamValueSupplier(valueSupplier, parameterSource));
} else {
providers.add(null);
}
}
if (!entityParamFound && Collections.frequency(providers, null) == 1) {
// Try to find entity if there is one unresolved parameter and the annotations are unknown
final int entityParamIndex = providers.lastIndexOf(null);
final Parameter parameter = parameterized.getParameters().get(entityParamIndex);
if (Parameter.Source.UNKNOWN == parameter.getSource() && !parameter.isQualified()) {
final Parameter overriddenParameter = Parameter.overrideSource(parameter, Parameter.Source.ENTITY);
final Supplier<?> valueSupplier = getParamValueSupplier(valueSupplierProviders, overriddenParameter);
if (valueSupplier != null) {
providers.set(entityParamIndex, wrapParamValueSupplier(valueSupplier, overriddenParameter.getSource()));
} else {
providers.set(entityParamIndex, null);
}
}
}
return providers;
}
Aggregations