本文整理汇总了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);
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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);
}
}
}
示例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())
);
}
}
示例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");
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
};
}