Hi peoples

In the XalanComponent.setOutProperty (in xsl <jbi:setOutProperty />)
the Object that is set on the JBI as a property is always a String,

   ref:
/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XalanExtension.java:181

however from XSLT (xpath expressions) we can have a
   number()  (which is a double)
   boolean()  (T / F)
   string()   (ye olde string)

To have a a number in the JBI property is handy when we want to
"integrate" with, for eg: the SplitAggregator
which needs the "count" property but String's don't cut it there (a
direct "assumed" cast)
   org.apache.servicemix.eip.splitter.count
as an Integer
   ref
/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/SplitAggregator.java:194

-- Proposed Patch--

Index: XalanExtension.java
===================================================================
--- XalanExtension.java    (revision 421260)
+++ XalanExtension.java    (working copy)
@@ -15,6 +15,7 @@
 */
package org.apache.servicemix.components.xslt;

+import org.apache.commons.lang.math.NumberUtils;
import org.apache.servicemix.components.util.ComponentSupport;
import org.apache.servicemix.components.util.CopyTransformer;
import org.apache.servicemix.components.util.MarshalerSupport;
@@ -179,7 +180,21 @@
            throw new IllegalArgumentException("Must specify a 'select'
attribute to set a property on the output message");
        }
        XObject answer =
ExsltDynamic.evaluate(context.getTransformer().getXPathContext().getExpressionContext(),
xpath);
-        String value = answer.str();
+        Object value;
+        try {
+            if (answer.getType() == XObject.CLASS_NUMBER) {
+                value = NumberUtils.createNumber(answer.str());
+            } else if (answer.getType() == XObject.CLASS_BOOLEAN) {
+                value = new Boolean(answer.bool());
+            } else {
+                // XObject guarantees we are never null.
+                value = answer.str();
+            }
+        } catch (TransformerException e) {
+            value = answer.str();
+        } catch (NumberFormatException e) {
+            value = answer.str();
+        }
        out.setProperty(name, value);
    }




Reply via email to