All Downloads are FREE. Search and download functionalities are using the official Maven repository.

restx.endpoint.EndpointParameterMapperRegistry Maven / Gradle / Ivy

There is a newer version: 1.2.0-rc2
Show newest version
package restx.endpoint;

import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import restx.endpoint.mappers.EndpointParameterMapper;
import restx.endpoint.mappers.EndpointParameterMapperFactory;
import restx.factory.Component;

@Component
public class EndpointParameterMapperRegistry {
  private final Iterable factories;

  public EndpointParameterMapperRegistry(Iterable factories) {
    this.factories = factories;
  }

  public  EndpointParameterMapper getEndpointParameterMapperFor(EndpointParamDef endpointParamDef) {
    for (EndpointParameterMapperFactory factory : factories) {
      Optional mapper = factory.getEndpointParameterMapperFor(endpointParamDef);
      if (mapper.isPresent()) {
        return mapper.get();
      }
    }

    throw new IllegalStateException(String.format(
            "no mapper found for parameter %s !%nAvailable factories: %s",
            endpointParamDef,
            Iterables.toString(factories)));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy