Fix PropertyBindings bugs
This commit is contained in:
parent
ba024fcdc9
commit
41bb712dc6
|
@ -23,13 +23,7 @@ public class AssociativeScriptObject extends GroovyObjectSupport implements Iter
|
|||
|
||||
@Override
|
||||
public Object getProperty(String name) {
|
||||
Object value = properties.get(name);
|
||||
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return super.getProperty(name); // throw MissingPropertyException
|
||||
return properties.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,11 +6,11 @@ public class BindingException extends RuntimeException {
|
|||
super(message, cause);
|
||||
}
|
||||
|
||||
public BindingException(String binding, String innerMessage) {
|
||||
public BindingException(Object binding, String innerMessage) {
|
||||
this(binding, innerMessage, null);
|
||||
}
|
||||
|
||||
public BindingException(String binding, String innerMessage, Throwable cause) {
|
||||
public BindingException(Object binding, String innerMessage, Throwable cause) {
|
||||
this(String.format("Binding \"%s\": %s", binding, innerMessage), cause);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ExpressionBindings extends AbstractMap<String, Object> implements B
|
|||
if (e.getCause() instanceof BindingException) {
|
||||
throw (BindingException) e.getCause();
|
||||
}
|
||||
throw new BindingException(key.toString(), getRootCauseMessage(e), e);
|
||||
throw new BindingException(key, getRootCauseMessage(e), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
package net.filebot.format;
|
||||
|
||||
import static net.filebot.util.ExceptionUtilities.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.AbstractMap;
|
||||
|
@ -9,7 +10,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
/*
|
||||
* Used to create a map view of the properties of an Object
|
||||
*/
|
||||
|
@ -18,12 +18,8 @@ public class PropertyBindings extends AbstractMap<String, Object> {
|
|||
private final Object object;
|
||||
private final Map<String, Object> properties = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private final Object defaultValue;
|
||||
|
||||
|
||||
public PropertyBindings(Object object, Object defaultValue) {
|
||||
public PropertyBindings(Object object) {
|
||||
this.object = object;
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
// get method bindings
|
||||
for (Method method : object.getClass().getMethods()) {
|
||||
|
@ -34,14 +30,13 @@ public class PropertyBindings extends AbstractMap<String, Object> {
|
|||
}
|
||||
|
||||
// boolean properties
|
||||
if (method.getName().length() > 2 && method.getName().substring(0, 3).equalsIgnoreCase("is")) {
|
||||
if (method.getName().length() > 2 && method.getName().substring(0, 2).equalsIgnoreCase("is")) {
|
||||
properties.put(method.getName().substring(2), method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
Object value = properties.get(key);
|
||||
|
@ -50,55 +45,44 @@ public class PropertyBindings extends AbstractMap<String, Object> {
|
|||
if (value instanceof Method) {
|
||||
try {
|
||||
value = ((Method) value).invoke(object);
|
||||
|
||||
if (value == null) {
|
||||
value = defaultValue;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new BindingException(key, getRootCauseMessage(e), e);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
return properties.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object remove(Object key) {
|
||||
return properties.remove(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return properties.containsKey(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return properties.keySet();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return properties.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return properties.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
Set<Entry<String, Object>> entrySet = new HashSet<Entry<String, Object>>();
|
||||
|
@ -111,13 +95,11 @@ public class PropertyBindings extends AbstractMap<String, Object> {
|
|||
return key;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return get(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object setValue(Object value) {
|
||||
return put(key, value);
|
||||
|
|
Loading…
Reference in New Issue