made app.properties-object readonly, plus formatting fixes.

This commit is contained in:
stefanp 2002-07-29 12:46:36 +00:00
parent e6cf8647cc
commit 1012b31a6a

View file

@ -2,7 +2,9 @@ package helma.scripting.fesi;
import java.util.Map; import java.util.Map;
import helma.framework.core.ApplicationBean;
import helma.objectmodel.INode; import helma.objectmodel.INode;
import helma.util.SystemProperties;
import FESI.Interpreter.Evaluator; import FESI.Interpreter.Evaluator;
import FESI.Exceptions.EcmaScriptException; import FESI.Exceptions.EcmaScriptException;
@ -19,38 +21,41 @@ public class ESBeanWrapper extends ESWrapper {
FesiEvaluator eval; FesiEvaluator eval;
public ESBeanWrapper (Object object, FesiEvaluator eval) { public ESBeanWrapper (Object object, FesiEvaluator eval) {
super (object, eval.getEvaluator(),true); super (object, eval.getEvaluator(),true);
this.eval = eval; this.eval = eval;
} }
/** /**
* Wrap getProperty, return ESNode if INode would be returned. * Wrap getProperty, return ESNode if INode would be returned,
* ESMapWrapper if Map would be returned.
*/ */
public ESValue getProperty(String propertyName, int hash) public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
throws EcmaScriptException { try {
try { ESValue val = super.getProperty (propertyName, hash);
ESValue val = super.getProperty (propertyName, hash); Object theObject = ((ESWrapper)val).getJavaObject ();
if (val instanceof ESWrapper && ((ESWrapper)val).getJavaObject() instanceof INode) { if (val instanceof ESWrapper && theObject instanceof INode) {
return eval.getNodeWrapper( (INode) ((ESWrapper)val).getJavaObject() ); return eval.getNodeWrapper ((INode) theObject);
} else if (val instanceof ESWrapper && ((ESWrapper)val).getJavaObject() instanceof Map) { } else if (val instanceof ESWrapper && theObject instanceof Map) {
return new ESMapWrapper(eval, (Map) ((ESWrapper)val).getJavaObject() ); ESMapWrapper wrapper = new ESMapWrapper(eval, (Map) theObject);
} else { if (theObject instanceof SystemProperties && super.getJavaObject () instanceof ApplicationBean)
return val; wrapper.setReadonly(true);
} return wrapper;
} catch (Exception rte) { } else {
return ESNull.theNull; return val;
} }
} catch (Exception rte) {
return ESNull.theNull;
}
} }
public void putProperty(String propertyName, ESValue propertyValue, int hash) public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException {
throws EcmaScriptException { try {
try { super.putProperty (propertyName, propertyValue, hash);
super.putProperty (propertyName, propertyValue, hash); } catch (Exception rte) {
} catch (Exception rte) { // create a nice error message
// create a nice error message throw new EcmaScriptException("can't set property " + propertyName +
throw new EcmaScriptException("can't set property " + propertyName + " to this value on " + getJavaObject().toString() );
" to this value on " + getJavaObject().toString() ); }
}
} }
} }