* make AssociativeScriptObject exception behavior more generic

This commit is contained in:
Reinhard Pointner 2012-07-08 03:09:42 +00:00
parent 8921cfc934
commit a8452bed7f
4 changed files with 26 additions and 12 deletions

View File

@ -251,7 +251,7 @@ public class Main {
private static void warmupCachedResources() {
Thread warmup = new Thread("warmup") {
Thread warmup = new Thread("warmupCachedResources") {
@Override
public void run() {

View File

@ -50,6 +50,8 @@ public class ArgumentProcessor {
String[] pair = it.substring(2).split("=", 2);
if (pair.length == 2) {
parameters.put(pair[0], pair[1]);
} else if (pair.length == 1) {
parameters.put(pair[0], "true");
}
} else {
arguments.add(it);

View File

@ -31,12 +31,7 @@ public class AssociativeScriptObject extends GroovyObjectSupport {
*/
@Override
public Object getProperty(String name) {
Object value = properties.get(name);
if (value == null)
throw new BindingException(name, "undefined");
return value;
return properties.get(name);
}

View File

@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
@ -363,7 +364,7 @@ public class MediaBindingBean {
}
}
return new AssociativeScriptObject(new PropertyBindings(metaInfo, null));
return createMapBindings(new PropertyBindings(metaInfo, null));
}
@ -375,25 +376,25 @@ public class MediaBindingBean {
@Define("media")
public AssociativeScriptObject getGeneralMediaInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.General, 0));
return createMapBindings(getMediaInfo().snapshot(StreamKind.General, 0));
}
@Define("video")
public AssociativeScriptObject getVideoInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Video, 0));
return createMapBindings(getMediaInfo().snapshot(StreamKind.Video, 0));
}
@Define("audio")
public AssociativeScriptObject getAudioInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Audio, 0));
return createMapBindings(getMediaInfo().snapshot(StreamKind.Audio, 0));
}
@Define("text")
public AssociativeScriptObject getTextInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Text, 0));
return createMapBindings(getMediaInfo().snapshot(StreamKind.Text, 0));
}
@ -508,6 +509,22 @@ public class MediaBindingBean {
}
private AssociativeScriptObject createMapBindings(Map<?, ?> map) {
return new AssociativeScriptObject(map) {
@Override
public Object getProperty(String name) {
Object value = super.getProperty(name);
if (value == null)
throw new BindingException(name, "undefined");
return value;
}
};
}
private String crc32(File file) throws IOException, InterruptedException {
// try to get checksum from cache
Cache cache = CacheManager.getInstance().getCache("checksum");