* 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() { private static void warmupCachedResources() {
Thread warmup = new Thread("warmup") { Thread warmup = new Thread("warmupCachedResources") {
@Override @Override
public void run() { public void run() {

View File

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

View File

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

View File

@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set; 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") @Define("media")
public AssociativeScriptObject getGeneralMediaInfo() { public AssociativeScriptObject getGeneralMediaInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.General, 0)); return createMapBindings(getMediaInfo().snapshot(StreamKind.General, 0));
} }
@Define("video") @Define("video")
public AssociativeScriptObject getVideoInfo() { public AssociativeScriptObject getVideoInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Video, 0)); return createMapBindings(getMediaInfo().snapshot(StreamKind.Video, 0));
} }
@Define("audio") @Define("audio")
public AssociativeScriptObject getAudioInfo() { public AssociativeScriptObject getAudioInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.Audio, 0)); return createMapBindings(getMediaInfo().snapshot(StreamKind.Audio, 0));
} }
@Define("text") @Define("text")
public AssociativeScriptObject getTextInfo() { 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 { private String crc32(File file) throws IOException, InterruptedException {
// try to get checksum from cache // try to get checksum from cache
Cache cache = CacheManager.getInstance().getCache("checksum"); Cache cache = CacheManager.getInstance().getCache("checksum");