Update of /var/cvs/src/org/mmbase/module/builders
In directory james.mmbase.org:/tmp/cvs-serv12844
Modified Files:
Tag: MMBase-1_8
Properties.java
Log Message:
support for default value
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/module/builders
Index: Properties.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/module/builders/Properties.java,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -b -r1.15.2.1 -r1.15.2.2
--- Properties.java 12 Jun 2008 11:42:20 -0000 1.15.2.1
+++ Properties.java 12 Jun 2008 12:05:13 -0000 1.15.2.2
@@ -41,7 +41,7 @@
</mm:cloud>
</pre>
*
- * @version $Id: Properties.java,v 1.15.2.1 2008/06/12 11:42:20 michiel Exp $
+ * @version $Id: Properties.java,v 1.15.2.2 2008/06/12 12:05:13 michiel Exp $
*/
public class Properties extends MMObjectBuilder {
@@ -59,7 +59,8 @@
protected final static Parameter NODE = new Parameter("node", Node.class,
true);
protected final static Parameter KEY = new Parameter("key",
String.class, true);
protected final static Parameter VALUE = new Parameter("value",
Object.class);
- protected final static Parameter[] GET_PARAMETERS = { NODE, KEY };
+ protected final static Parameter DEFAULT = new Parameter("default",
Object.class);
+ protected final static Parameter[] GET_PARAMETERS = { NODE, KEY, DEFAULT };
protected final static Parameter[] SET_PARAMETERS = { new
Parameter.Wrapper(GET_PARAMETERS), VALUE };
protected List getValueNode(Node node, String key) {
@@ -90,7 +91,9 @@
{
addFunction(new AbstractFunction("get", GET_PARAMETERS,
ReturnType.UNKNOWN) {
public Object getFunctionValue(Parameters parameters) {
- return Properties.this.getValue((Node)
parameters.get(NODE), (String) parameters.get(KEY));
+ Object v = Properties.this.getValue((Node)
parameters.get(NODE), (String) parameters.get(KEY));
+ if (v == null) return parameters.get(DEFAULT);
+ return v;
}
});
addFunction(new AbstractFunction("set", SET_PARAMETERS,
ReturnType.UNKNOWN) {
@@ -138,6 +141,7 @@
n.setValue("value", newValue);
n.commit();
}
+ if (orgValue == null) return parameters.get(DEFAULT);
return orgValue;
}
});
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs