* refactor {model} and {self} bindings

This commit is contained in:
Reinhard Pointner 2014-08-09 07:35:22 +00:00
parent 95f84fb6fa
commit 30bda0e902
1 changed files with 17 additions and 8 deletions

View File

@ -777,17 +777,16 @@ public class MediaBindingBean {
return di == 0 ? null : di; return di == 0 ? null : di;
} }
@Define("self")
public AssociativeScriptObject getSelf() {
return createBindingObject(mediaFile, infoObject, context);
}
@Define("model") @Define("model")
public List<AssociativeScriptObject> getContext() { public List<AssociativeScriptObject> getModel() {
List<AssociativeScriptObject> result = new ArrayList<AssociativeScriptObject>(); List<AssociativeScriptObject> result = new ArrayList<AssociativeScriptObject>();
for (Entry<File, Object> it : context.entrySet()) { for (Entry<File, Object> it : context.entrySet()) {
MediaBindingBean mediaBindingBean = new MediaBindingBean(it.getValue(), it.getKey(), context) { result.add(createBindingObject(it.getKey(), it.getValue(), context));
@Define(undefined)
public <T> T undefined(String name) {
return null; // never throw exceptions for empty or null values
}
};
result.add(new AssociativeScriptObject(new ExpressionBindings(mediaBindingBean)));
} }
return result; return result;
} }
@ -890,6 +889,16 @@ public class MediaBindingBean {
return null; return null;
} }
private AssociativeScriptObject createBindingObject(File file, Object info, Map<File, Object> context) {
MediaBindingBean mediaBindingBean = new MediaBindingBean(info, file, context) {
@Define(undefined)
public <T> T undefined(String name) {
return null; // never throw exceptions for empty or null values
}
};
return new AssociativeScriptObject(new ExpressionBindings(mediaBindingBean));
}
private AssociativeScriptObject createMapBindings(Map<?, ?> map) { private AssociativeScriptObject createMapBindings(Map<?, ?> map) {
return new AssociativeScriptObject(map) { return new AssociativeScriptObject(map) {