use of com.scratchdisk.list.ReadOnlyList in project scriptographer by scriptographer.
the class RhinoWrapFactory method wrapAsJavaObject.
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObj, Class<?> staticType, boolean newObject) {
// Keep track of wrappers so that if a given object needs to be
// wrapped again, take the wrapper from the pool...
WeakReference<Scriptable> ref = wrappers.get(javaObj);
Scriptable obj = ref == null ? null : ref.get();
if (obj == null) {
boolean cache = true;
// Allays override staticType and set it to the native type
// of the class. Sometimes the interface used to access an
// object of a certain class is passed. But why should it
// be wrapped that way?
staticType = javaObj.getClass();
if (staticType != null && staticType.isArray())
obj = new ExtendedJavaArray(scope, javaObj, staticType, true);
else {
if (javaObj instanceof ReadOnlyList) {
obj = new ListWrapper(scope, (ReadOnlyList) javaObj, staticType, true);
} else if (javaObj instanceof Map) {
obj = new MapWrapper(scope, (Map) javaObj);
} else {
obj = wrapCustom(cx, scope, javaObj, staticType, newObject);
if (obj == null) {
obj = new ExtendedJavaObject(scope, javaObj, staticType, true);
// See the comment in wrapCustom for an explanation of
// this:
cache = false;
}
}
}
if (cache)
wrappers.put(javaObj, new WeakReference<Scriptable>(obj));
}
return obj;
}
use of com.scratchdisk.list.ReadOnlyList in project scriptographer by scriptographer.
the class ListWrapper method getDefaultValue.
public Object getDefaultValue(Class hint) {
if (hint == null || hint == ScriptRuntime.StringClass) {
StringBuffer buffer = new StringBuffer();
ReadOnlyList list = (ReadOnlyList) javaObject;
for (int i = 0, l = list.size(); i < l; i++) {
if (i > 0)
buffer.append(",");
Object entry = list.get(i);
if (entry != null) {
Scriptable obj = Context.toObject(entry, this);
buffer.append(obj.getDefaultValue(hint));
} else {
buffer.append("null");
}
}
return buffer.toString();
} else {
return super.getDefaultValue(hint);
}
}
Aggregations