Exemplo n.º 1
0
 /**
  * Declare a singleton {@code DynamicItem<T>} with a binder.
  *
  * <p>Items must be defined in a Guice module before they can be bound:
  *
  * <pre>
  *   DynamicSet.itemOf(binder(), new TypeLiteral&lt;Thing&lt;Foo&gt;&gt;() {});
  * </pre>
  *
  * @param binder a new binder created in the module.
  * @param member type of entry to store.
  */
 public static <T> void itemOf(Binder binder, TypeLiteral<T> member) {
   @SuppressWarnings("unchecked")
   Key<DynamicItem<T>> key =
       (Key<DynamicItem<T>>)
           Key.get(Types.newParameterizedType(DynamicItem.class, member.getType()));
   binder.bind(key).toProvider(new DynamicItemProvider<>(member, key)).in(Scopes.SINGLETON);
 }
 public ComputeServiceContext buildComputeServiceContext() {
   // need the generic type information
   return (ComputeServiceContext)
       buildInjector()
           .getInstance(
               Key.get(
                   Types.newParameterizedType(
                       ComputeServiceContextImpl.class, syncClientType, asyncClientType)));
 }
Exemplo n.º 3
0
 @SuppressWarnings("unchecked")
 public <T> T create(Class<T> clazz) {
   return (T)
       create(
           clazz,
           (AsyncRestClientProxy<T>)
               injector.getInstance(
                   Key.get(
                       TypeLiteral.get(
                           Types.newParameterizedType(AsyncRestClientProxy.class, clazz)))));
 }
 private AutoBindProvider getAutoBindProvider(Annotation annotation) {
   AutoBindProvider autoBindProvider = null;
   if (annotation.annotationType().isAnnotationPresent(AutoBind.class)) {
     ParameterizedType parameterizedType =
         Types.newParameterizedType(AutoBindProvider.class, annotation.annotationType());
     autoBindProvider =
         (AutoBindProvider<?>) injector.getInstance(Key.get(TypeLiteral.get(parameterizedType)));
   } else if (annotation.annotationType().isAssignableFrom(AutoBind.class)) {
     autoBindProvider =
         injector.getInstance(Key.get(new TypeLiteral<AutoBindProvider<AutoBind>>() {}));
   }
   return autoBindProvider;
 }
Exemplo n.º 5
0
 @SuppressWarnings({"unchecked"})
 private Key<Collection<Realm>> realmCollectionKey() {
   return (Key<Collection<Realm>>)
       Key.get(Types.newParameterizedType(Collection.class, Realm.class));
 }