Author: michiel
Date: 2010-06-21 11:47:28 +0200 (Mon, 21 Jun 2010)
New Revision: 42625
Modified:
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/FunctionSets.java
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/SetFunction.java
Log:
MMB-1965
Modified:
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/FunctionSets.java
===================================================================
---
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/FunctionSets.java
2010-06-21 09:46:36 UTC (rev 42624)
+++
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/FunctionSets.java
2010-06-21 09:47:28 UTC (rev 42625)
@@ -192,7 +192,7 @@
functionSets.put(setName, functionSet);
for (Element element: reader.getChildElements("functionset",
"function")) {
- String functionName = reader.getElementAttributeValue(element,
"name");
+ final String functionName =
reader.getElementAttributeValue(element, "name");
if (functionName != null) {
Element a = DocumentReader.getElementByPath(element,
"function.type");
@@ -236,15 +236,24 @@
}
*/
+ SetFunction.Type functionType =
SetFunction.Type.valueOf(type.toUpperCase());
+
// read the parameters
Parameter<?>[] parameters =
Parameter.readArrayFromXml(element);
- for (Parameter param : parameters) {
- if (param.getClass().isPrimitive() &&
param.getDefaultValue() == null) {
- // that would give enigmatic
IllegalArgumentExceptions, so fix that.
- param.setDefaultValue(Casting.toType(param.getClass(),
-1));
- log.debug("Primitive parameter '" + param + "' had
default value null, which is impossible for primitive types. Setting to " +
param.getDefaultValue());
+
+ if (functionType != SetFunction.Type.BEAN) {
+ for (Parameter param : parameters) {
+ if (param.getClass().isPrimitive() &&
param.getDefaultValue() == null) {
+ // that would give enigmatic
IllegalArgumentExceptions, so fix that.
+
param.setDefaultValue(Casting.toType(param.getClass(), -1));
+ log.debug("Primitive parameter '" + param + "' had
default value null, which is impossible for primitive types. Setting to " +
param.getDefaultValue());
+ }
}
+ } else {
+ if (parameters.length != 0) {
+ throw new RuntimeException("Cannot define explicit
parmeters for BEAN functions");
+ }
}
try {
@@ -254,7 +263,17 @@
} catch(Exception e) {
throw new RuntimeException("Can't create an
application function class : " + className + " " + e.getMessage(), e);
}
- SetFunction fun = new SetFunction(functionName,
parameters, returnType, functionClass, methodName,
SetFunction.Type.valueOf(type.toUpperCase()));
+ Function fun;
+ if (functionType == SetFunction.Type.BEAN) {
+ fun = new
WrappedFunction(BeanFunction.getFunction(functionClass, methodName)) {
+ @Override
+ public String getName() {
+ return functionName;
+ }
+ };
+ } else {
+ fun = new SetFunction(functionName, parameters,
returnType, functionClass, methodName, functionType);
+ }
fun.setDescription(description);
Function prev = functionSet.addFunction(fun);
if (prev != null && ! (prev.equals(fun))) {
Modified:
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/SetFunction.java
===================================================================
---
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/SetFunction.java
2010-06-21 09:46:36 UTC (rev 42624)
+++
mmbase/trunk/bridge/src/main/java/org/mmbase/util/functions/SetFunction.java
2010-06-21 09:47:28 UTC (rev 42625)
@@ -39,6 +39,11 @@
*/
INSTANCE,
/**
+ * If type is 'bean' the method must not be static, and on every call
to getFunctionValue, a new object is instantiated. There is not need to
+ * explicitely declare the parameters.
+ */
+ BEAN,
+ /**
* If type is 'singleton', then the static method 'getInstance' will
be called to get the one instance, unless the method is static.
*/
SINGLETON
@@ -155,6 +160,7 @@
throw new RuntimeException("Can't create an function
instance : " + functionMethod.getDeclaringClass().getName(), e);
}
break;
+ case BEAN:
case INSTANCE:
functionInstance = null;
// one will be made on every calle
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs