protected AbstractPropertyConfiguration(final Class<T> baseClass, final LogContextConfigurationImpl configuration, final Map<String, T> refs, final Map<String, C> configs, final String name, final String moduleName, final String className, final String[] constructorProperties) { super(name, configuration, refs, configs); this.moduleName = moduleName; this.className = className; if (className == null) { throw new IllegalArgumentException("className is null"); } this.constructorProperties = constructorProperties; final ClassLoader classLoader; if (moduleName != null) try { classLoader = ModuleFinder.getClassLoader(moduleName); } catch (Throwable e) { throw new IllegalArgumentException(String.format("Failed to load module \"%s\" for %s \"%s\"", moduleName, getDescription(), name), e); } else { classLoader = getClass().getClassLoader(); } final Class<? extends T> actualClass; try { actualClass = Class.forName(className, true, classLoader).asSubclass(baseClass); } catch (Exception e) { throw new IllegalArgumentException(String.format("Failed to load class \"%s\" for %s \"%s\"", className, getDescription(), name), e); } this.actualClass = actualClass; }
public ObjectProducer validate() throws IllegalArgumentException { final Class<?> propertyType = getPropertyType(actualClass, propertyName); if (propertyType == null) { throw new IllegalArgumentException(String.format("No property \"%s\" type could be determined for %s \"%s\"", propertyName, getDescription(), getName())); } return getDefaultValue(propertyType); }
@Override public void setPropertyValueExpression(final String propertyName, final String expression) { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot set property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); } if (propertyName == null) { throw new IllegalArgumentException("propertyName is null"); } setPropertyValueExpression(propertyName, ValueExpression.STRING_RESOLVER.resolve(expression)); }
@Override public void setPropertyValueExpression(final String propertyName, final String expression, final String value) { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot set property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); } if (propertyName == null) { throw new IllegalArgumentException("propertyName is null"); } setPropertyValueExpression(propertyName, new ValueExpressionImpl<String>(expression, value)); }
public void setPropertyValueString(final String propertyName, final String value) throws IllegalArgumentException { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot set property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); } if (propertyName == null) { throw new IllegalArgumentException("propertyName is null"); } setPropertyValueExpression(propertyName, ValueExpression.STRING_RESOLVER.resolve(value)); }
public ObjectProducer validate() throws IllegalArgumentException { if (setter == null) { return ObjectProducer.NULL_PRODUCER; } final Class<?> propertyType = getPropertyType(actualClass, propertyName); if (propertyType == null) { throw new IllegalArgumentException(String.format("No property \"%s\" type could be determined for %s \"%s\"", propertyName, getDescription(), getName())); } return getConfiguration().getValue(actualClass, propertyName, propertyType, expression, false); }
public boolean removeProperty(final String propertyName) { if (isRemoved()) { throw new IllegalArgumentException(String.format("Cannot remove property \"%s\" on %s \"%s\" (removed)", propertyName, getDescription(), getName())); throw new IllegalArgumentException(String.format("No property \"%s\" setter found for %s \"%s\"", propertyName, getDescription(), getName()));
final Method setter = getPropertySetter(actualClass, propertyName); if (setter == null && ! constructorProp) { throw new IllegalArgumentException(String.format("No property \"%s\" setter found for %s \"%s\"", propertyName, getDescription(), getName()));
if (propertyType == null) { StandardOutputStreams.printError("No property \"%s\" type could be determined for %s \"%s\"", propertyName, getDescription(), getName()); return;
public void rollback() { // We need to once again determine the property type final Class<?> propertyType = getPropertyType(actualClass, propertyName); if (propertyType == null) { // We don't want the rest of the rollback to fail so we'll just log a message StandardOutputStreams.printError("No property \"%s\" type could be determined for %s \"%s\"", propertyName, getDescription(), getName()); return; } // Get the reference instance, the old value and reset to the old value final T instance = getRefs().get(getName()); final ObjectProducer producer = getConfiguration().getValue(actualClass, propertyName, propertyType, oldValue, true); try { setter.invoke(instance, producer.getObject()); } catch (Throwable e) { StandardOutputStreams.printError(e, "Failed to invoke setter %s with value %s%n.", setter.getName(), producer.getObject()); } } });