當前位置: 首頁>>代碼示例>>Java>>正文


Java ProvisionException類代碼示例

本文整理匯總了Java中com.google.inject.ProvisionException的典型用法代碼示例。如果您正苦於以下問題:Java ProvisionException類的具體用法?Java ProvisionException怎麽用?Java ProvisionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ProvisionException類屬於com.google.inject包,在下文中一共展示了ProvisionException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bindClass

import com.google.inject.ProvisionException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
protected <T> void bindClass(TypeLiteral<T> key, String property)
{
	String value = Strings.nullToEmpty(getPropString(property)).trim();
	if( !Check.isEmpty(value) )
	{
		try
		{
			Class<?> clazz = getClass().getClassLoader().loadClass(value);
			bind(key).annotatedWith(Names.named(property)).toInstance((T) clazz);
		}
		catch( ClassNotFoundException e )
		{
			throw new ProvisionException("Class not found in property: " + property);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:PropertiesModule.java

示例2: bindNewInstance

import com.google.inject.ProvisionException; //導入依賴的package包/類
protected <T> void bindNewInstance(String property, Class<T> type)
{
	String value = Strings.nullToEmpty(getPropString(property)).trim();
	if( !Check.isEmpty(value) )
	{
		try
		{
			bind(type).annotatedWith(Names.named(property)).toInstance(
				type.cast(getClass().getClassLoader().loadClass(value).newInstance()));
		}
		// In the interests of diagnostics, we'll allow an explicit catch of
		// generic exception
		catch( Exception e ) // NOSONAR
		{
			throw new ProvisionException("Class not found in property: " + property);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:PropertiesModule.java

示例3: ifCommmandIsInvalidExceptionIsThrown

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Test
public void ifCommmandIsInvalidExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        RequestFilter instance = injector.getInstance(
                Key.get(new TypeLiteral<IOProvider<RequestFilter>>() {})).get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:23,代碼來源:DefaultModuleTest.java

示例4: ifCommmandIsInvalidResponseExceptionIsThrown

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Test
public void ifCommmandIsInvalidResponseExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        IOProvider<ResponseFilter> instance = injector.getInstance(new Key<IOProvider<ResponseFilter>>() {});
        instance.get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:23,代碼來源:DefaultModuleTest.java

示例5: getChildAction

import com.google.inject.ProvisionException; //導入依賴的package包/類
/**
 * @param args   the arguments
 * @param parser the command line parser containing usage information
 * @return a child Command for the given args, or <code>null</code> if not found
 */
protected Command getChildAction(List<String> args, CmdLineParser parser) {
    final String commandName = args.get(0);

    // find implementation
    final Class<? extends Command> commandClass = commandMap.get(commandName);
    if (null != commandClass) {
        try {
            final Command command = InjectionUtil.getInjector().getInstance(commandClass);
            command.setParent(this);
            command.setCommandName(commandName);

            return command;
        } catch (ProvisionException | ConfigurationException e) {
            throw new CommandException(String.format("Error getting child command for args: %s", args), e);
        }
    }
    return null;
}
 
開發者ID:apiman,項目名稱:apiman-cli,代碼行數:24,代碼來源:AbstractCommand.java

示例6: provideObjectFromNamedBindingOrJndi

import com.google.inject.ProvisionException; //導入依賴的package包/類
protected Object provideObjectFromNamedBindingOrJndi(
        TypeLiteral<?> requiredType, String name) {
    Binding<?> binding = Injectors.getBinding(injector,
            Key.get(requiredType, Names.named(name)));
    if (binding != null) {
        return binding.getProvider().get();
    }

    // TODO we may want to try avoid the dependency on JNDI classes
    // for better operation in GAE?
    try {
        if (context == null) {
            context = new InitialContext();
        }
        return context.lookup(name);
    } catch (NamingException e) {
        throw new ProvisionException("Failed to find name '" + name
                + "' in JNDI. Cause: " + e, e);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:NamedProviderSupport.java

示例7: getCurrentThreadClientInfo

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Override
@Nullable
public ClientInfo getCurrentThreadClientInfo() {
  try {
    HttpServletRequest request = httpRequestProvider.get();
    return new ClientInfo(
        UserIdHelper.get(),
        request.getRemoteAddr(),
        request.getHeader(HttpHeaders.USER_AGENT)
    );
  }
  catch (ProvisionException | OutOfScopeException e) {
    // ignore; this happens when called out of scope of http request
    return null;
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:17,代碼來源:ClientInfoProviderImpl.java

示例8: startServiceIfApplicable

import com.google.inject.ProvisionException; //導入依賴的package包/類
private <T, S> void startServiceIfApplicable(T instance, ServiceLifecycleActions<S> withActions) {
    if (services.contains(instance)) {
        return;
    }
    if (withActions == null) {
        services.add(instance);
        return;
    }
    S service = withActions.castIfActionable(instance);
    if (service != null) {
        try {
            withActions.onStart(service);
            services.add(service);
        } catch (Exception e) {
            try {
                stopServices(withActions, e);
            } catch (Exception e1) {
                e = e1;
            }
            throw new ProvisionException("While starting service " + instance.getClass(), e);
        }
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:24,代碼來源:Guicer.java

示例9: errorOnStartup

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Test
public void errorOnStartup() throws Exception {
    Guicer guicer = messageGuicer(
            bind(DummyInterfaces.Alpha.class, DummyErroringServices.ErroringAlpha.class, true),
            bind(DummyInterfaces.Beta.class, DummyErroringServices.ErroringBeta.class, false),
            bind(DummyInterfaces.Gamma.class, DummyErroringServices.ErroringGamma.class, false)
    );
    try{
        startRequiredServices(guicer);
        fail("should have caught ErroringException");
    } catch (ProvisionException e) {
        assertEventualCause(e, DummyErroringServices.ErroringException.class);
        assertEquals(
                "messages",
                joined(
                        "starting ErroringAlpha",
                        "starting ErroringBeta",
                        "starting ErroringGamma",
                        "started ErroringGamma",
                        "stopping ErroringGamma",
                        "stopped ErroringGamma"
                ),
                Strings.join(DummyInterfaces.messages())
        );
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:27,代碼來源:GuicerTest.java

示例10: testDoesNotAllowCircularDependencies

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Test
public void testDoesNotAllowCircularDependencies()
        throws Exception
{
    Bootstrap bootstrap = new Bootstrap(new Module()
    {
        @Override
        public void configure(Binder binder)
        {
            binder.bind(InstanceA.class);
            binder.bind(InstanceB.class);
        }
    });

    try {
        bootstrap.initialize().getInstance(InstanceA.class);
        Assert.fail("should not allow circular dependencies");
    }
    catch (ProvisionException e) {
        assertContains(e.getErrorMessages().iterator().next().getMessage(), "circular proxies are disabled");
    }
}
 
開發者ID:embulk,項目名稱:guice-bootstrap,代碼行數:23,代碼來源:TestBootstrap.java

示例11: CiDataSourceProvider

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Inject
protected CiDataSourceProvider(SitePaths site,
    @PluginName String pluginName,
    @Nullable MetricMaker metrics,
    Context ctx,
    CiDataSourceType dst) {
  File file = site.gerrit_config.toFile();
  FileBasedConfig cfg = new FileBasedConfig(file, FS.DETECTED);
  try {
    cfg.load();
  } catch (IOException | ConfigInvalidException e) {
    throw new ProvisionException(e.getMessage(), e);
  }
  this.config = new PluginConfig(pluginName, cfg);
  this.metrics = metrics;
  this.ctx = ctx;
  this.dst = dst;
}
 
開發者ID:davido,項目名稱:gerrit-ci-plugin,代碼行數:19,代碼來源:CiDataSourceProvider.java

示例12: main

import com.google.inject.ProvisionException; //導入依賴的package包/類
public static void main(String... args) {
  WSFRealtimeMain m = new WSFRealtimeMain();

  ArgumentParser parser = ArgumentParsers.newArgumentParser("wsf-gtfsrealtime");
  parser.description("Produces a GTFS-realtime feed from the Washington State Ferries API");
  parser.addArgument("--" + ARG_CONFIG_FILE).type(File.class).help("configuration file path");
  Namespace parsedArgs;

  try {
    parsedArgs = parser.parseArgs(args);
    File configFile = parsedArgs.get(ARG_CONFIG_FILE);
    m.run(configFile);
  } catch (CreationException | ConfigurationException | ProvisionException e) {
    _log.error("Error in startup:", e);
    System.exit(-1);
  } catch (ArgumentParserException ex) {
    parser.handleError(ex);
  }
}
 
開發者ID:kurtraschke,項目名稱:wsf-gtfsrealtime,代碼行數:20,代碼來源:WSFRealtimeMain.java

示例13: getBindingAnnotation

import com.google.inject.ProvisionException; //導入依賴的package包/類
protected Annotation getBindingAnnotation(Annotation[] annotations) {
  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;

      // Keep going so we can find any rogue additional binding annotations
    }
  }

  return bindingAnnotation;
}
 
開發者ID:google-code-export,項目名稱:google-gin,代碼行數:20,代碼來源:MemberLiteral.java

示例14: get

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Override
public T get() {
    final ServiceLoader<T> loader = ServiceLoader.load(this.service);
    final Iterator<T> iterator = loader.iterator();

    if (!iterator.hasNext()) {
        throw LoggerUtils2.exception(this.logger, ProvisionException.class,
                "No implementations are registered for the class {}.",
                this.service
        );
    }

    final T obj = iterator.next();

    if (iterator.hasNext()) {
        throw LoggerUtils2.exception(this.logger, ProvisionException.class,
                "Multiple implementations are registered for the class {}.",
                this.service
        );
    }

    return obj;
}
 
開發者ID:metaborg,項目名稱:spoofax-intellij,代碼行數:24,代碼來源:JavaServiceProvider.java

示例15: get

import com.google.inject.ProvisionException; //導入依賴的package包/類
@Override
public PublicKeyStore get() {
  final Repository repo;
  try {
    repo = repoManager.openRepository(allUsers);
  } catch (IOException e) {
    throw new ProvisionException("Cannot open " + allUsers, e);
  }
  return new PublicKeyStore(repo) {
    @Override
    public void close() {
      try {
        super.close();
      } finally {
        repo.close();
      }
    }
  };
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:20,代碼來源:SignedPushModule.java


注:本文中的com.google.inject.ProvisionException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。