Package com.google.inject

Examples of com.google.inject.ProvisionException


                return provided;
              }

              Object providedOrSentinel = (provided == null) ? NULL : provided;
              if (instance != null && instance != providedOrSentinel) {
                throw new ProvisionException(
                    "Provider was reentrant while creating a singleton");
              }

              instance = providedOrSentinel;
            }
View Full Code Here


                                        public Object get() {
                                            try {
                                                return future.get();
                                            } catch (InterruptedException e) {
                                                Thread.currentThread().interrupt();
                                                throw new ProvisionException("interrupted during provision");
                                            } catch (ExecutionException e) {
                                                throw new RuntimeException(e.getCause());
                                            }
                                        }
                                    });
                                }
                            }
                            // All dependencies are now being instantiated in parallel
                           
                            // Fetch the arguments from the futures and put in an array to pass to newInstance
                            List<Object> params = Lists.newArrayListWithCapacity(deps.size());
                            for (Supplier<?> supplier: suppliers) {
                                params.add(supplier.get());
                            }
                           
                            // All dependencies have been initialized
                           
                            // Look for the @Inject constructor and invoke it.
                            try {
                                T obj = (T)constructor.newInstance(params.toArray());
                                long duration = System.nanoTime() - startTime;
                                for (LifecycleListener listener : listeners) {
                                    listener.objectInjected((TypeLiteral<T>)TypeLiteral.get(type), obj, duration, TimeUnit.NANOSECONDS);
                                }
                                return obj;
                            } catch (Exception e) {
                                throw new RuntimeException(e);
                            }
                        }
                        finally {
                            executor.shutdown();
                        }
                    }
                }
               
                try {
                    T obj = type.newInstance();
                    long duration = System.nanoTime() - startTime;
                    for (LifecycleListener listener : listeners) {
                        listener.objectInjected((TypeLiteral<T>)TypeLiteral.get(type), obj, duration, TimeUnit.NANOSECONDS);
                    }
                    return obj;
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new ProvisionException("Error constructing object of type " + type.getName(), e);
                }
            }
           
            private boolean isConcurrent(Constructor<?> constructor, int parameterIndex) {
                Annotation[] annots = constructor.getParameterAnnotations()[parameterIndex];
View Full Code Here

    Annotation bindingAnnotation = null;
    for (Annotation annotation : annotations) {
      if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null
          || annotation.annotationType() == Named.class) {
        if (bindingAnnotation != null) {
          throw new ProvisionException(
              String.format("More than one binding annotation found on %s: %s, %s.",
                   this, annotation, bindingAnnotation));
        }

        bindingAnnotation = annotation;
View Full Code Here

        if (signer == null) {
          FileInputStream privateKeyStream;
          try {
            privateKeyStream = new FileInputStream(privateKey);
          } catch (FileNotFoundException e) {
            throw new ProvisionException("could not read private key", e);
          }

          Iterable<FileInputStream> certStreams =
              Iterables.transform(certs, FILE_OPENER);

          try {
            WaveSigner inner = waveSignerFactory.getSigner(privateKeyStream, certStreams, certDomain);
            signer = new SigningSignatureHandler(inner);
          } catch (SignatureException e) {
            throw new ProvisionException("could not make wave signer", e);
          }
        }
      }
      return signer;
    }
View Full Code Here

      @Override
      public FileInputStream apply(String filename) {
        try {
          return new FileInputStream(filename);
        } catch (FileNotFoundException e) {
          throw new ProvisionException("could not read certificates", e);
        }
      }
View Full Code Here

        try
        {
            Class<?> clazz = classLoader.loadClass( className );
            if ( !service.isAssignableFrom( clazz ) )
            {
                throw new ProvisionException( format( "Provider '%s' is not assignable to Service '%s'",
                                                      className, service.getName() ) );
            }
            return clazz.asSubclass( service );
        }
        catch ( ClassNotFoundException e )
        {
            throw new ProvisionException( format( "Provider '%s' not found: %s", className, e.getMessage() ) );
        }
        catch ( ClassCastException e )
        {
            throw new ProvisionException( format( "Provider '%s' is not assignable to Service '%s'",
                                                  className, service.getName() ) );
        }
    }
View Full Code Here

                Enumeration<URL> serviceResources = classLoader.getResources( fullName );
                serviceClassIterator = new URLServiceNamesIterator<S>( service, classLoader, serviceResources );
            }
            catch ( IOException e )
            {
                throw new ProvisionException( format( "An error occurred while loading '%s' Service resource(s) from classpath: %s",
                                                      fullName, e.getMessage() ) );
            }
        }
    }
View Full Code Here

            bindService( serviceType, serviceImplType );
        }

        if ( !found )
        {
            throw new ProvisionException( format( "No Provider found for Service %s", serviceType.getName() ) );
        }
    }
View Full Code Here

            {
                return moduleClass.newInstance();
            }
            catch ( Exception e )
            {
                throw new ProvisionException( format( "Provider '%s' could not be instantiated",
                                                      moduleClass.getName(), e.getMessage() ) );
            }
        }
View Full Code Here

                //Feed the empty properties to get the code work
                JndiBindings.bindInjectorAndBindings(context, injector, new Properties());
            }
            return context;
        } catch (Exception e) {
            throw new ProvisionException("Failed to create JNDI bindings. Reason: " + e, e);
        }
    }
View Full Code Here

TOP

Related Classes of com.google.inject.ProvisionException

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.