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


Java ConfigurationException類代碼示例

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


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

示例1: testNotExposed

import com.google.inject.ConfigurationException; //導入依賴的package包/類
@Test
public void testNotExposed() {
  final Injector injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      DuplexBinder.create(this.binder()).install(new DuplexModule() {
        @Override
        protected void configure() {
          this.bind(Thing.class).annotatedWith(Names.named("r0")).toInstance(new Thing("r0"));
        }
      });
    }
  });
  try {
    injector.getInstance(ShouldNotWork.class);
  } catch(final ConfigurationException expected) {
    final String message = expected.getMessage();
    if(message.contains("It was already configured on one or more child injectors or private modules")
      && message.contains("If it was in a PrivateModule, did you forget to expose the binding?")) {
      return;
    }
  }
  fail("should not be exposed");
}
 
開發者ID:KyoriPowered,項目名稱:violet,代碼行數:25,代碼來源:DuplexTest.java

示例2: analyzeImplementation

import com.google.inject.ConfigurationException; //導入依賴的package包/類
private void analyzeImplementation(final TypeLiteral<?> type, boolean ignoreConstructor)
{
	if( !scannedTypes.contains(type) )
	{
		try
		{
			if( (type.getRawType().getModifiers() & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0 )
			{
				analyzeInjectionPoints(InjectionPoint.forInstanceMethodsAndFields(type));
				if( !ignoreConstructor )
				{
					analyzeDependencies(InjectionPoint.forConstructorOf(type).getDependencies());
				}
			}
		}
		catch( ConfigurationException ce )
		{
			errors.merge(ce.getErrorMessages());
		}
		scannedTypes.add(type);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:DependencyAnalyzer.java

示例3: testLoadMap

import com.google.inject.ConfigurationException; //導入依賴的package包/類
@Test
public void testLoadMap() throws Exception {

    Map<String, TestInterface> services = target.loadMap(TestInterface.class);
    assertTrue(services.get("TestImpl1") instanceof TestInterface.TestImpl1);
    assertTrue(services.get("TestImpl3") instanceof TestInterface.TestImpl3);
    assertEquals(services.size(), 2, services.toString());

    for (TestInterface s : services.values()) {

        assertNotNull(s.getInjector());

        assertNotNull(s.getInjector().getInstance(ImmutableConfiguration.class));

        try {
            s.getInjector().getInstance(ServiceFactory.class);
            fail();
        } catch (ConfigurationException e) {
            // Success
        }

    }

}
 
開發者ID:after-the-sunrise,項目名稱:cryptotrader,代碼行數:25,代碼來源:ServiceFactoryImplTest.java

示例4: provideValue

import com.google.inject.ConfigurationException; //導入依賴的package包/類
/**
 * This method produces value for the field. It constructs the context for the creation out of
 * paren't context and the field's own frame info.
 */
@Override
public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) {
  By selector = PageObjectProviderHelper.getSelectorFromPageObject(field);
  ElementLocatorFactory elementLocatorFactory =
      new NestedSelectorScopedLocatorFactory(webDriver, selector,
          context.getElementLocatorFactory(), AnnotationsHelper.isGlobal(field));
  final FramePath framePath = frameMap.get(pageObject);
  contextStack.push(new PageObjectContext(elementLocatorFactory, framePath));
  Object scopedPageObject = null;
  try {
    scopedPageObject = injector.getInstance(field.getType());
  } catch (Exception e) {
    if (e instanceof ConfigurationException) {
      ConfigurationException ce = (ConfigurationException) e;
      throw new BobcatRuntimeException(
          "Configuration exception: " + ce.getErrorMessages().toString(), e);
    }
    throw new BobcatRuntimeException(e.getMessage(), e);
  } finally {
    contextStack.pop();
  }
  return Optional.ofNullable(scopedPageObject);
}
 
開發者ID:Cognifide,項目名稱:bobcat,代碼行數:28,代碼來源:SelectorPageObjectProvider.java

示例5: provideValue

import com.google.inject.ConfigurationException; //導入依賴的package包/類
/**
 * This method produces value for the field. It constructs the context for the creation out of
 * parent's context and the field's own frame info.
 */
@Override
public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) {
  final ElementLocatorFactory elementLocatorFactory = new ScopedElementLocatorFactory(webDriver,
      context.getElementLocatorFactory(), field);
  final FramePath framePath = frameMap.get(pageObject);
  contextStack.push(new PageObjectContext(elementLocatorFactory, framePath));
  Object scopedPageObject = null;
  try {
    scopedPageObject = injector.getInstance(field.getType());
  } catch (Exception e) {
    if (e instanceof ConfigurationException) {
      ConfigurationException ce = (ConfigurationException) e;
      throw new BobcatRuntimeException(
          "Configuration exception: " + ce.getErrorMessages().toString(), e);
    }
    throw new BobcatRuntimeException(e.getMessage(), e);
  } finally {
    contextStack.pop();
  }
  return Optional.ofNullable(scopedPageObject);
}
 
開發者ID:Cognifide,項目名稱:bobcat,代碼行數:26,代碼來源:ScopedPageObjectProvider.java

示例6: getChildAction

import com.google.inject.ConfigurationException; //導入依賴的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

示例7: resolve

import com.google.inject.ConfigurationException; //導入依賴的package包/類
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {

	if (injectee.getRequiredType() instanceof Class) {

		TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
		Errors errors = new Errors(injectee.getParent());
		Key<?> key;
		try {
			key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
					injectee.getParent().getDeclaredAnnotations(), errors);
		} catch (ErrorsException e) {
			errors.merge(e.getErrors());
			throw new ConfigurationException(errors.getMessages());
		}

		return injector.getInstance(key);
	}

	throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}
 
開發者ID:bootique,項目名稱:bootique-jersey-client,代碼行數:22,代碼來源:ClientGuiceInjectInjector.java

示例8: getResourceServiceProviderById

import com.google.inject.ConfigurationException; //導入依賴的package包/類
/**
 * Finds the {@link IResourceServiceProvider} for a language by given its id.
 *
 * @param languageId
 *          the language id (grammar name)
 * @return the {@link IResourceServiceProvider} for the given language id
 */
public IResourceServiceProvider getResourceServiceProviderById(final String languageId) {
  ImmutableMap<Map<String, Object>, ? extends Function<String, IResourceServiceProvider>> resourceProvidersMap = getProviderMaps();
  for (Map.Entry<Map<String, Object>, ? extends Function<String, IResourceServiceProvider>> mapEntry : resourceProvidersMap.entrySet()) {
    Map<String, Object> map = mapEntry.getKey();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
      try {
        IResourceServiceProvider resourceServiceProvider = mapEntry.getValue().apply(entry.getKey());
        if (resourceServiceProvider == null) {
          continue;
        }
        IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
        if (grammarAccess != null && grammarAccess.getGrammar().getName().equals(languageId)) {
          return resourceServiceProvider;
        }
        // CHECKSTYLE:OFF
      } catch (ConfigurationException ex) {
        // CHECKSTYLE:ON
        // ignore
      }
    }
  }
  return null;
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:31,代碼來源:ResourceServiceProviderLocator.java

示例9: getAllLanguages

import com.google.inject.ConfigurationException; //導入依賴的package包/類
/**
 * Gets the all languages available in the workbench.
 *
 * @return set of all languages
 */
public Set<String> getAllLanguages() {
  Set<String> languages = new HashSet<String>();
  for (String extension : Registry.INSTANCE.getExtensionToFactoryMap().keySet()) {
    final URI dummyUri = URI.createURI("foo:/foo." + extension);
    IResourceServiceProvider resourceServiceProvider = Registry.INSTANCE.getResourceServiceProvider(dummyUri);
    // By checking that description manager is AbstractCachingResourceDescriptionManager we exclude technical languages of the framework
    if (resourceServiceProvider != null && resourceServiceProvider.getResourceDescriptionManager() instanceof AbstractCachingResourceDescriptionManager) {
      try {
        IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
        if (grammarAccess != null && grammarAccess.getGrammar() != null) {
          languages.add(grammarAccess.getGrammar().getName());
        }
      } catch (ConfigurationException e) {
        // Will happen if no binding for IGrammarAccess was present.
      }
    }
  }
  return languages;
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:25,代碼來源:CheckCfgUtil.java

示例10: getCurrentTestLogFileName

import com.google.inject.ConfigurationException; //導入依賴的package包/類
private Optional<String> getCurrentTestLogFileName()
{
    Optional<TestContext> testContext = testContextIfSet();
    try {
        String testName = "SUITE";
        if (testContext.isPresent()) {
            Optional<TestMetadata> testMetadata = testContext.get().getOptionalDependency(TestMetadata.class);
            if (testMetadata.isPresent()) {
                testName = testMetadata.get().testName;
            }
        }
        return Optional.of(logsDirectory + "/" + testName);
    }
    catch (ConfigurationException e) {
        System.err.append("Could not load TestMetadata from guice context");
        return Optional.empty();
    }
}
 
開發者ID:prestodb,項目名稱:tempto,代碼行數:19,代碼來源:TestFrameworkLoggingAppender.java

示例11: main

import com.google.inject.ConfigurationException; //導入依賴的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

示例12: createBindingsForFactories

import com.google.inject.ConfigurationException; //導入依賴的package包/類
private void createBindingsForFactories(GinjectorBindings bindings) {
  for (final FactoryModule<?> factoryModule : bindings.getFactoryModules()) {
    FactoryBinding binding;
    try {
      binding = bindingFactory.getFactoryBinding(
          factoryModule.getBindings(),
          factoryModule.getFactoryType(),
          Context.forText(factoryModule.getSource()));
    } catch (ConfigurationException e) {
      errorManager.logError("Factory %s could not be created", e, factoryModule.getFactoryType());
      continue;
    }

    bindings.addBinding(factoryModule.getFactoryType(), binding);
  }
}
 
開發者ID:google-code-export,項目名稱:google-gin,代碼行數:17,代碼來源:BindingsProcessor.java

示例13: buildTestWrapperInstance

import com.google.inject.ConfigurationException; //導入依賴的package包/類
private static TestWrapper buildTestWrapperInstance(Injector injector) {
  TestWrapper result = NoOpTestScopeListener.NO_OP_INSTANCE;
  try {
    boolean hasTestScopeListenerBinding = hasTestScopeListenerBinding(injector);
    boolean hasDeprecatedTestScopeListenerBinding = hasDeprecatedTestScopeListenerBinding(injector);
    if (hasTestScopeListenerBinding && hasDeprecatedTestScopeListenerBinding) {
      throw new RuntimeException(
        "Your GuiceBerry Env has bindings for both the new TestScopeListener and the deprecated one. Please fix.");
    } else if (hasTestScopeListenerBinding) {
      result = injector.getInstance(TestWrapper.class);
    } else if (hasDeprecatedTestScopeListenerBinding) {
      result = adapt(
          injector.getInstance(com.google.inject.testing.guiceberry.TestScopeListener.class),
          injector.getInstance(TearDownAccepter.class));
    }
  } catch (ConfigurationException e) {
    String msg = String.format("Error while creating a TestWrapper: '%s'.",
      e.getMessage());
    throw new RuntimeException(msg, e); 
  }
  return result;
}
 
開發者ID:zorzella,項目名稱:guiceberry,代碼行數:23,代碼來源:GuiceBerryUniverse.java

示例14: testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingTestBinding

import com.google.inject.ConfigurationException; //導入依賴的package包/類
/**
 * This test makes sure that if the test has a missing binding, GuiceBerry
 * will fail before it runs the {@link GuiceBerryEnvMain#run()} method.
 */
@Test public void testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingTestBinding() {
  GuiceBerryEnvSelector guiceBerryEnvSelector = 
    DefaultEnvSelector.of(MyGuiceBerryEnvWithGuiceBerryEnvMainThatThrows.class);
  TestDescription testDescription = new TestDescription(new ClassWithUnsatisfiedDependency(), "bogus test case");
  GuiceBerryUniverse.TestCaseScaffolding testCaseScaffolding = 
    new GuiceBerryUniverse.TestCaseScaffolding(testDescription, guiceBerryEnvSelector, universe);
    
  try {
    testCaseScaffolding.runBeforeTest();
    Assert.fail("The test has an unsatisfied injection, and the GuiceBerryEnvMain "
        + "throws an Exception. Either of these reasons should have prevented the "
        + "test from having gotten here.");
  } catch (MyGuiceBerryEnvWithGuiceBerryEnvMainThatThrows.GuiceBerryEnvMainWasExecutedException toThrow) {
    throw toThrow;
  } catch (RuntimeException maybeExpected) {
    Assert.assertEquals(ConfigurationException.class, maybeExpected.getCause().getClass());
  }
    
  testCaseScaffolding.runAfterTest();
}
 
開發者ID:zorzella,項目名稱:guiceberry,代碼行數:25,代碼來源:GuiceBerryUniverseTest.java

示例15: testGbeThatHasMissingBindingsThrowsException

import com.google.inject.ConfigurationException; //導入依賴的package包/類
public void testGbeThatHasMissingBindingsThrowsException() {   
  try {
    TestWithGbeThatHasMissingBindings test = 
      TestWithGbeThatHasMissingBindings.createInstance();
    instance().doSetUp(test);
    fail();
  } catch (RuntimeException expectedActualException) {
    //TODO: we should assert expected's cause is ConfigurationException, but 
    //that exception is private
    Throwable actualCause = expectedActualException.getCause();
    assertEquals(ConfigurationException.class, actualCause.getClass());
    assertEquals(String.format(
      "Binding error in the GuiceBerry Env '%s': '%s'.", 
      GuiceBerryEnvWithoutBindingsForFooOrBar.GUICE_BERRY_ENV_WITHOUT_BINDINGS_FOR_FOO_OR_BAR,
      actualCause.getMessage()),
      expectedActualException.getMessage());
    String configurationExceptionMeat = String.format(
      "No implementation for %s was bound.", BarService.class.getName());
    assertTrue(actualCause.getMessage().contains(configurationExceptionMeat));
  }
}
 
開發者ID:zorzella,項目名稱:guiceberry,代碼行數:22,代碼來源:GuiceBerryJunit3Test.java


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