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

net.stickycode.resource.StickyResourceCodecRegistry Maven / Gradle / Ivy

package net.stickycode.resource;

import java.util.Set;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.stickycode.coercion.CoercionTarget;
import net.stickycode.stereotype.component.StickyRepository;

@StickyRepository
public class StickyResourceCodecRegistry
    implements ResourceCodecRegistry {

  private Logger log = LoggerFactory.getLogger(getClass());

  @SuppressWarnings("rawtypes")
  @Inject
  private Set codecs;

  @Override
  public  ResourceCodec find(CoercionTarget target) {
    log.info("find a codec for {}", target);
    ResourceCodec lookup = lookup(target);
    log.info("found {}", lookup);
    return lookup;
  }

  @SuppressWarnings("unchecked")
  private  ResourceCodec lookup(CoercionTarget target) {
    for (ResourceCodec r : codecs) {
      if (r.isApplicableTo(target))
        return (ResourceCodec) r;
    }

    throw new ResourceCodecNotFoundException(target, codecs);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy