Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Commit

Permalink
Enforced ordering of string readers
Browse files Browse the repository at this point in the history
Change-Id: Ia6559315b14189854b56050f4a9e15132da11f2a
  • Loading branch information
japod committed Jun 18, 2012
1 parent 2c20917 commit c22c705
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ public class ParameterInjectionModule extends AbstractModule {
@Override
public void configure() {
// String reader providers
bind(StringValueReaderProvider.class).to(StringReaderProviders.TypeFromStringEnum.class).in(Singleton.class);
bind(StringValueReaderProvider.class).to(StringReaderProviders.TypeValueOf.class).in(Singleton.class);
bind(StringValueReaderProvider.class).to(StringReaderProviders.TypeFromString.class).in(Singleton.class);
bind(StringValueReaderProvider.class).to(StringReaderProviders.StringConstructor.class).in(Singleton.class);
bind(StringValueReaderProvider.class).to(StringReaderProviders.DateProvider.class).in(Singleton.class);
bind(StringValueReaderProvider.class).to(JaxbStringReaderProvider.RootElementProvider.class);
bind(StringValueReaderProvider.class).to(StringReaderProviders.AggregatedProvider.class).in(Singleton.class);
bind().to(StringReaderFactory.class).in(Singleton.class);

// Parameter injection value extractor providers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
import java.util.Date;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;

import org.glassfish.hk2.inject.Injector;
import org.glassfish.jersey.internal.ExtractorException;
import org.glassfish.jersey.internal.ProcessingException;
import org.glassfish.jersey.internal.util.ReflectionHelper;
Expand Down Expand Up @@ -182,4 +184,31 @@ public T fromString(String value) {
};
}
}

public static class AggregatedProvider implements StringValueReaderProvider {

final StringValueReaderProvider[] providers;

public AggregatedProvider(@Context Injector injector) {
providers = new StringValueReaderProvider[]{
injector.inject(TypeFromStringEnum.class),
injector.inject(TypeValueOf.class),
injector.inject(TypeFromString.class),
injector.inject(StringConstructor.class),
injector.inject(DateProvider.class),
injector.inject(JaxbStringReaderProvider.RootElementProvider.class)
};
}

@Override
public <T> StringValueReader<T> getStringReader(Class<T> type, Type genericType, Annotation[] annotations) {
for (StringValueReaderProvider p : providers) {
final StringValueReader<T> reader = p.getStringReader(type, genericType, annotations);
if (reader != null) {
return reader;
}
}
return null;
}
}
}

0 comments on commit c22c705

Please sign in to comment.