/** Returns a copy of this configuration exception with the specified partial value. */ public ConfigurationException withPartialValue(Object partialValue) { checkState(this.partialValue == null, "Can't clobber existing partial value %s with %s", this.partialValue, partialValue); ConfigurationException result = new ConfigurationException(messages); result.partialValue = partialValue; return result; }
public void throwConfigurationExceptionIfErrorsExist() { if (!hasErrors()) { return; } throw new ConfigurationException(getMessages()); }
/** * Throws a ConfigurationException with an NullPointerExceptions as the cause if the given * reference is {@code null}. */ static <T> T checkNotNull(T reference, String name) { if (reference != null) { return reference; } NullPointerException npe = new NullPointerException(name); throw new ConfigurationException(ImmutableSet.of(new Message(npe.toString(), npe))); }
/** * Throws a ConfigurationException with a formatted {@link Message} if this condition is {@code * false}. */ static void checkConfiguration(boolean condition, String format, Object... args) { if (condition) { return; } throw new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); }
/** * Returns all static method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} of * the valid injection points. */ public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral<?> type) { Errors errors = new Errors(); Set<InjectionPoint> result; if (type.getRawType().isInterface()) { errors.staticInjectionOnInterface(type.getRawType()); result = null; } else { result = getInjectionPoints(type, true, errors); } if (errors.hasErrors()) { throw new ConfigurationException(errors.getMessages()).withPartialValue(result); } return result; }
if (!isFullySpecified(type)) { Errors errors = new Errors().keyNotFullySpecified(typeLiteral); throw new ConfigurationException(errors.getMessages());
@Override public <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral) { Errors errors = new Errors(typeLiteral); try { return membersInjectorStore.get(typeLiteral, errors); } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }
/** Returns the binding for {@code key} */ @Override public <T> BindingImpl<T> getBinding(Key<T> key) { Errors errors = new Errors(key); try { BindingImpl<T> result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT); errors.throwConfigurationExceptionIfErrorsExist(); return result; } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }
&& !Modifier.isPrivate(rawType.getModifiers())) { errors.missingConstructor(rawType); throw new ConfigurationException(errors.getMessages()); } catch (NoSuchMethodException e) { errors.missingConstructor(rawType); throw new ConfigurationException(errors.getMessages());
/** * Returns all instance method and field injection points on {@code type}. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} of * the valid injection points. */ public static Set<InjectionPoint> forInstanceMethodsAndFields(TypeLiteral<?> type) { Errors errors = new Errors(); Set<InjectionPoint> result = getInjectionPoints(type, false, errors); if (errors.hasErrors()) { throw new ConfigurationException(errors.getMessages()).withPartialValue(result); } return result; }
@Override public <T> Provider<T> getProvider(final Key<T> key) { Errors errors = new Errors(key); try { Provider<T> result = getProviderOrThrow(Dependency.get(key), errors); errors.throwIfNewErrors(0); return result; } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }
throw new ConfigurationException(e.getErrors().getMessages());
@Test public void testPropertySetting() throws Exception { IMocksControl control = createControl(); TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class); Provider<Injector> injectorProvider = control.createMock(Provider.class); Injector injector = control.createMock(Injector.class); expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider); expect(injectorProvider.get()).andReturn(injector).anyTimes(); Capture<MembersInjector<SomeInjectableBean>> capture = new Capture<MembersInjector<SomeInjectableBean>>(); encounter.register(and(anyObject(MembersInjector.class), capture(capture))); SecurityManager securityManager = control.createMock(SecurityManager.class); String property = "myPropertyValue"; expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty")))) .andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!")))); expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes(); control.replay(); BeanTypeListener underTest = new BeanTypeListener(); underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter); SomeInjectableBean bean = new SomeInjectableBean(); capture.getValue().injectMembers(bean); assertSame(securityManager, bean.securityManager); assertSame(property, bean.myProperty); assertNull(bean.unavailableProperty); control.verify(); }
private ConfigurationException getException() { ImmutableList<Message> messages = new ImmutableList.Builder<Message>() .addAll(errors) .addAll(warnings) .build(); return new ConfigurationException(messages); }
private ConfigurationException getException() { ImmutableList<Message> messages = new ImmutableList.Builder<Message>() .addAll(errors) .addAll(warnings) .build(); return new ConfigurationException(messages); }
private ConfigurationException getException() { ImmutableList<Message> messages = new ImmutableList.Builder<Message>() .addAll(errors) .addAll(warnings) .build(); return new ConfigurationException(messages); }
/** Returns a copy of this configuration exception with the specified partial value. */ public ConfigurationException withPartialValue(Object partialValue) { checkState(this.partialValue == null, "Can't clobber existing partial value %s with %s", this.partialValue, partialValue); ConfigurationException result = new ConfigurationException(messages); result.partialValue = partialValue; return result; }
public BindingCollector addBinding(Key<?> key, TypeLiteral<?> target) { if (bindings.containsKey(key)) { throw new ConfigurationException(ImmutableSet.of( new Message("Only one implementation can be specified for " + key))); } bindings.put(key, target); return this; }
public void throwConfigurationExceptionIfErrorsExist() { if (!hasErrors()) { return; } throw new ConfigurationException(getMessages()); }
/** Returns the binding for {@code key} */ public <T> BindingImpl<T> getBinding(Key<T> key) { Errors errors = new Errors(key); try { BindingImpl<T> result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT); errors.throwConfigurationExceptionIfErrorsExist(); return result; } catch (ErrorsException e) { throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); } }