本文整理汇总了Java中com.google.inject.ProvisionException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java ProvisionException.getCause方法的具体用法?Java ProvisionException.getCause怎么用?Java ProvisionException.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.ProvisionException
的用法示例。
在下文中一共展示了ProvisionException.getCause方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrapException
import com.google.inject.ProvisionException; //导入方法依赖的package包/类
public static <E extends Throwable> E unwrapException(Class<E> type, ProvisionException e) throws E {
if(e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else if(type.isInstance(e.getCause())) {
throw (E) e.getCause();
} else {
throw e;
}
}
示例2: requireThatExceptionIsThrown
import com.google.inject.ProvisionException; //导入方法依赖的package包/类
@Test
public void requireThatExceptionIsThrown() {
try {
TestDriver.newInjectedApplicationInstanceWithoutOsgi(MyApplication.class);
fail();
} catch (ProvisionException e) {
Throwable t = e.getCause();
assertNotNull(t);
assertTrue(t instanceof ApplicationNotReadyException);
}
}
示例3: run
import com.google.inject.ProvisionException; //导入方法依赖的package包/类
/**
* @param runtime runtime started by Bootique.
* @return the outcome of the command execution.
* @deprecated since 0.23. Previously this method existed to catch and process run exceptions, but it doesn't
* have wide enough scope for this, so exception processing was moved to {@link #exec()}.
*/
@Deprecated
private CommandOutcome run(BQRuntime runtime) {
try {
return runtime.getRunner().run();
}
// handle startup Guice exceptions
catch (ProvisionException e) {
// TODO: a dependency on JOPT OptionException shouldn't be here
return (e.getCause() instanceof OptionException) ? CommandOutcome.failed(1, e.getCause().getMessage())
: CommandOutcome.failed(1, e);
}
}
示例4: get
import com.google.inject.ProvisionException; //导入方法依赖的package包/类
@Override
public String get() {
String canonicalUrl = super.get();
if (canonicalUrl != null) {
return canonicalUrl;
}
if (requestProvider != null) {
// No canonical URL configured? Maybe we can get a reasonable
// guess from the incoming HTTP request, if we are currently
// inside of an HTTP request scope.
//
final HttpServletRequest req;
try {
req = requestProvider.get();
} catch (ProvisionException noWeb) {
if (noWeb.getCause() instanceof OutOfScopeException) {
// We can't obtain the request as we are not inside of
// an HTTP request scope. Callers must handle null.
//
return null;
}
throw noWeb;
}
return CanonicalWebUrl.computeFromRequest(req);
}
// We have no way of guessing our HTTP url.
//
return null;
}
示例5: providing
import com.google.inject.ProvisionException; //导入方法依赖的package包/类
/** @since 4.0 */
@SuppressWarnings("unchecked") // safe because this is the cxtor of the literal
public ScopedBindingBuilder providing(TypeLiteral<? extends T> cxtorLiteral) {
// Find a constructor that has @ThrowingInject.
Constructor<? extends T> cxtor =
CheckedProvideUtils.findThrowingConstructor(cxtorLiteral, binder);
final Provider<T> typeProvider;
final Key<? extends T> typeKey;
// If we found an injection point, then bind the cxtor to a unique key
if (cxtor != null) {
// Validate the exceptions are consistent with the CheckedProvider interface.
CheckedProvideUtils.validateExceptions(
binder, cxtorLiteral.getExceptionTypes(cxtor), exceptionTypes, interfaceType);
typeKey = Key.get(cxtorLiteral, UniqueAnnotations.create());
binder.bind(typeKey).toConstructor((Constructor) cxtor).in(Scopes.NO_SCOPE);
typeProvider = binder.getProvider((Key<T>) typeKey);
} else {
// never used, but need it assigned.
typeProvider = null;
typeKey = null;
}
// Create a CheckedProvider that calls our cxtor
CheckedProvider<T> checkedProvider =
new CheckedProviderWithDependencies<T>() {
@Override
public T get() throws Exception {
try {
return typeProvider.get();
} catch (ProvisionException pe) {
// Rethrow the provision cause as the actual exception
if (pe.getCause() instanceof Exception) {
throw (Exception) pe.getCause();
} else if (pe.getCause() instanceof Error) {
throw (Error) pe.getCause();
} else {
// If this failed because of multiple reasons (ie, more than
// one dependency failed due to scoping errors), then
// the ProvisionException won't have a cause, so we need
// to rethrow it as-is.
throw pe;
}
}
}
@Override
public Set<Dependency<?>> getDependencies() {
return ImmutableSet.<Dependency<?>>of(Dependency.get(typeKey));
}
};
Key<CheckedProvider<?>> targetKey =
Key.get(CHECKED_PROVIDER_TYPE, UniqueAnnotations.create());
binder.bind(targetKey).toInstance(checkedProvider);
return toInternal(targetKey);
}
示例6: providing
import com.google.inject.ProvisionException; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // safe because this is the cxtor of the literal
public ScopedBindingBuilder providing(TypeLiteral<? extends T> cxtorLiteral) {
// Find a constructor that has @ThrowingInject.
Constructor<? extends T> cxtor =
CheckedProvideUtils.findThrowingConstructor(cxtorLiteral, binder);
final Provider<T> typeProvider;
final Key<? extends T> typeKey;
// If we found an injection point, then bind the cxtor to a unique key
if (cxtor != null) {
// Validate the exceptions are consistent with the CheckedProvider interface.
CheckedProvideUtils.validateExceptions(
binder, cxtorLiteral.getExceptionTypes(cxtor), exceptionTypes, interfaceType);
typeKey = Key.get(cxtorLiteral, UniqueAnnotations.create());
binder.bind(typeKey).toConstructor((Constructor) cxtor).in(Scopes.NO_SCOPE);
typeProvider = binder.getProvider((Key<T>) typeKey);
} else {
// never used, but need it assigned.
typeProvider = null;
typeKey = null;
}
// Create a CheckedProvider that calls our cxtor
CheckedProvider<T> checkedProvider = new CheckedProviderWithDependencies<T>() {
@Override
public T get() throws Exception {
try {
return typeProvider.get();
} catch (ProvisionException pe) {
// Rethrow the provision cause as the actual exception
if (pe.getCause() instanceof Exception) {
throw (Exception) pe.getCause();
} else if (pe.getCause() instanceof Error) {
throw (Error) pe.getCause();
} else {
// If this failed because of multiple reasons (ie, more than
// one dependency failed due to scoping errors), then
// the ProvisionException won't have a cause, so we need
// to rethrow it as-is.
throw pe;
}
}
}
@Override
public Set<Dependency<?>> getDependencies() {
return ImmutableSet.<Dependency<?>>of(Dependency.get(typeKey));
}
};
Key<CheckedProvider> targetKey = Key.get(CheckedProvider.class, UniqueAnnotations.create());
binder.bind(targetKey).toInstance(checkedProvider);
return toInternal(targetKey);
}