Package com.google.inject

Examples of com.google.inject.Key$SimpleKey


            binder.bind( providerType ).in( Scopes.SINGLETON );

            final Named bindingName = getBindingName( providerType );
            final Class<?>[] types = getBindingTypes( providerType );

            final Key key = getBindingKey( args[0], bindingName );
            final ScopedBindingBuilder sbb = binder.bind( key ).toProvider( providerType );
            if ( isEagerSingleton( providerType ) )
            {
                sbb.asEagerSingleton();
            }
            else if ( isSingleton( providerType ) )
            {
                sbb.in( Scopes.SINGLETON );
            }

            if ( null != types )
            {
                for ( final Class bindingType : types )
                {
                    binder.bind( key.ofType( bindingType ) ).to( key );
                }
            }
        }
    }
View Full Code Here


        final Named bindingName = getBindingName( qualifiedType );
        final Class<?>[] types = getBindingTypes( qualifiedType );

        if ( null != types )
        {
            final Key key = getBindingKey( OBJECT_TYPE_LITERAL, bindingName );
            for ( final Class bindingType : types )
            {
                binder.bind( key.ofType( bindingType ) ).to( qualifiedType );
            }
        }
        else
        {
            binder.bind( new WildcardKey( qualifiedType, bindingName ) ).to( qualifiedType );
View Full Code Here

    // ----------------------------------------------------------------------

    @SuppressWarnings( { "unchecked", "rawtypes" } )
    public <T> Binding<T> get( final TypeLiteral<T> type )
    {
        final Key implicitKey = TypeArguments.implicitKey( type.getRawType() );
        for ( final BindingPublisher p : publishers )
        {
            if ( p instanceof InjectorPublisher )
            {
                // first round: check for any re-written implicit bindings
                final Injector i = ( (InjectorPublisher) p ).getInjector();
                final Binding binding = i.getBindings().get( implicitKey );
                if ( null != binding )
                {
                    Logs.trace( "Using implicit binding: {} from: <>", binding, i );
                    return binding;
                }
            }
        }

        final Key justInTimeKey = Key.get( type );
        for ( final BindingPublisher p : publishers )
        {
            if ( p instanceof InjectorPublisher )
            {
                // second round: fall back to just-in-time binding lookup
View Full Code Here

        // Bind beans
        for (BeanBinding<?> beanBinding : bootstrap.bindings) {

          // Get a binding key
          Key key;
          if (beanBinding.qualifiers != null && beanBinding.qualifiers.size() > 0) {
            Iterator<Annotation> i = beanBinding.qualifiers.iterator();
            // Construction to make compiler happy
//            b = a.annotatedWith(i.next());
//            while (i.hasNext()) {
//              b = a.annotatedWith(i.next());
//            }
            key = Key.get(beanBinding.type, i.next());
          }
          else {
            key = Key.get(beanBinding.type);
          }
          LinkedBindingBuilder b = bind(key);

          //
          ScopedBindingBuilder c;
          if (beanBinding instanceof BeanBinding.ToInstance) {
            BeanBinding.ToInstance d = (BeanBinding.ToInstance)beanBinding;
            b.toInstance(d.instance);
            c = b;
          }
          else if (beanBinding instanceof BeanBinding.ToProviderInstance) {
            BeanBinding.ToProviderInstance d = (BeanBinding.ToProviderInstance)beanBinding;
            c = b.toProvider(d);
            if (beanBinding.scopeType != null) {
              c.in(beanBinding.scopeType);
            }
          }
          else {
            if (beanBinding instanceof BeanBinding.ToProviderType) {
              BeanBinding.ToProviderType d = (BeanBinding.ToProviderType)beanBinding;
              c = b.toProvider(d.provider);
            }
            else {
              BeanBinding.ToType d = (BeanBinding.ToType)beanBinding;
              if (d.qualifiers != null) {
                if (d.implementationType != null) {
                  c = b.to(d.implementationType);
                  // Guice trick : need to bind alias so the implementation type will be bound with the qualifier
                  bind(Key.get(d.implementationType, key.getAnnotation())).toProvider(new BeanAlias(key));
                }
                else {
                  c = b.to(beanBinding.type);
                }
              }
              else {
                if (d.implementationType != null) {
                  c = b.to(d.implementationType);
                }
                else {
                  c = b;
                }
              }
            }
            if (beanBinding.scopeType != null) {
              c.in(beanBinding.scopeType);
            }
          }
        }

        // Bind the manager itself
        bind(InjectionContext.class).toInstance(GuiceContext.this);
      }

      private <T> void bind(Class<T> clazz, T instance) {
        bind(clazz).toInstance(instance);
      }
    };

    //
    Map<String, Key<?>> nameMap = new HashMap<String, Key<?>>();
    Injector injector = Guice.createInjector(module);
    for (Key<?> key : injector.getBindings().keySet()) {
      Class<? extends Annotation> annotationType = key.getAnnotationType();
      if (annotationType != null && Named.class.isAssignableFrom(annotationType)) {
        Named named = (Named)key.getAnnotation();
        nameMap.put(named.value(), key);
      }
    }

    //
View Full Code Here

  {
    if (paramBindingImpl.getScoping().isEagerSingleton(paramStage))
      return true;
    if ((paramBindingImpl instanceof LinkedBindingImpl))
    {
      Key localKey = ((LinkedBindingImpl)paramBindingImpl).getLinkedKey();
      return isEagerSingleton(paramInjectorImpl, paramInjectorImpl.getBinding(localKey), paramStage);
    }
    return false;
  }
View Full Code Here

  {
    Type localType1 = paramKey.getTypeLiteral().getType();
    if (!(localType1 instanceof ParameterizedType))
      throw paramErrors.cannotInjectRawProvider().toException();
    Type localType2 = ((ParameterizedType)localType1).getActualTypeArguments()[0];
    Key localKey = paramKey.ofType(localType2);
    return localKey;
  }
View Full Code Here

  }

  private BindingImpl createProviderBinding(Key paramKey, Errors paramErrors)
    throws ErrorsException
  {
    Key localKey = getProvidedKey(paramKey, paramErrors);
    BindingImpl localBindingImpl = getBindingOrThrow(localKey, paramErrors, JitLimitation.NO_JIT);
    return new ProviderBindingImpl(this, paramKey, localBindingImpl);
  }
View Full Code Here

  }

  private BindingImpl convertConstantStringBinding(Key paramKey, Errors paramErrors)
    throws ErrorsException
  {
    Key localKey = paramKey.ofType(STRING_TYPE);
    BindingImpl localBindingImpl = this.state.getExplicitBinding(localKey);
    if ((localBindingImpl == null) || (!localBindingImpl.isConstant()))
      return null;
    String str = (String)localBindingImpl.getProvider().get();
    Object localObject1 = localBindingImpl.getSource();
View Full Code Here

  void initializeJitBinding(BindingImpl paramBindingImpl, Errors paramErrors)
    throws ErrorsException
  {
    if ((paramBindingImpl instanceof ConstructorBindingImpl))
    {
      Key localKey = paramBindingImpl.getKey();
      this.jitBindings.put(localKey, paramBindingImpl);
      int i = 0;
      ConstructorBindingImpl localConstructorBindingImpl = (ConstructorBindingImpl)paramBindingImpl;
      try
      {
View Full Code Here

    Set localSet = getInternalDependencies(paramBindingImpl);
    Iterator localIterator = localSet.iterator();
    while (localIterator.hasNext())
    {
      Dependency localDependency = (Dependency)localIterator.next();
      Key localKey = localDependency.getKey();
      InjectionPoint localInjectionPoint = localDependency.getInjectionPoint();
      if (paramSet.add(localKey))
      {
        BindingImpl localBindingImpl = (BindingImpl)this.jitBindings.get(localKey);
        if (localBindingImpl != null)
View Full Code Here

TOP

Related Classes of com.google.inject.Key$SimpleKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.