当前位置: 首页>>代码示例>>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;未经允许,请勿转载。