当前位置: 首页>>代码示例>>Java>>正文


Java ProvisionException.getCause方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:10,代码来源:Injection.java

示例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);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:12,代码来源:ApplicationNotReadyTestCase.java

示例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);
    }
}
 
开发者ID:bootique,项目名称:bootique,代码行数:20,代码来源:Bootique.java

示例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;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:32,代码来源:HttpCanonicalWebUrlProvider.java

示例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);
}
 
开发者ID:google,项目名称:guice,代码行数:59,代码来源:ThrowingProviderBinder.java

示例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);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:56,代码来源:ThrowingProviderBinder.java


注:本文中的com.google.inject.ProvisionException.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。