if (pType.getRawType() != ContextResolver.class)
return null;
Type type = pType.getActualTypeArguments()[0];
// TODO check if concrete type
final ContextResolver cr = getResolver(ic, type);
if (cr == null) {
return new Injectable() {
public Object getValue() {
return null;
}
};
} else {
return new Injectable() {
public Object getValue() {
return cr;
}
};
}
}
ContextResolver getResolver(ComponentContext ic, Type type) {
Map<MediaType, ContextResolver> x = resolver.get(type);
if (x == null)
return null;
List<MediaType> ms = getMediaTypes(ic);
if (ms.size() == 1) {
return resolve(type, ms.get(0));
} else {
Set<MediaType> ml = new TreeSet<MediaType>(MediaTypes.MEDIA_TYPE_COMPARATOR);
for (MediaType m : ms) {
if (m.isWildcardType()) {
ml.add(MediaTypes.GENERAL_MEDIA_TYPE);
} else if (m.isWildcardSubtype()) {
ml.add(new MediaType(m.getType(), "*"));
ml.add(MediaTypes.GENERAL_MEDIA_TYPE);
} else {
ml.add(new MediaType(m.getType(), m.getSubtype()));
ml.add(new MediaType(m.getType(), "*"));
ml.add(MediaTypes.GENERAL_MEDIA_TYPE); }
}
List<ContextResolver> crl = new ArrayList<ContextResolver>(ml.size());
for (MediaType m : ms) {
ContextResolver cr = x.get(m);
if (cr != null) crl.add(cr);
}
if (crl.isEmpty())
return null;