Altova StyleVision 2025 Basic Edition

When a Java function is called from within an XPath/XQuery expression, the datatype of the function's arguments is important in determining which of multiple Java classes having the same name is called.

 

In Java, the following rules are followed:

 

If there is more than one Java method with the same name, but each has a different number of arguments than the other/s, then the Java method that best matches the number of arguments in the function call  is selected.

The XPath/XQuery string, number, and boolean datatypes (see list below) are implicitly converted to a corresponding Java datatype. If the supplied XPath/XQuery type can be converted to more than one Java type (for example, xs:integer), then that Java type is selected which is declared for the selected method. For example, if the Java method being called is fx(decimal) and the supplied XPath/XQuery datatype is xs:integer, then xs:integer will be converted to Java's decimal datatype.

 

The table below lists the implicit conversions of XPath/XQuery string, number, and boolean types to Java datatypes.

 

xs:string

java.lang.String

xs:boolean

boolean (primitive), java.lang.Boolean

xs:integer

int, long, short, byte, float, double, and the wrapper classes of these, such as java.lang.Integer

xs:float

float (primitive), java.lang.Float, double (primitive)

xs:double

double (primitive), java.lang.Double

xs:decimal

float (primitive), java.lang.Float, double(primitive), java.lang.Double

 

Subtypes of the XML Schema datatypes listed above (and which are used in XPath and XQuery) will also be converted to the Java type/s corresponding to that subtype's ancestor type.

 

In some cases, it might not be possible to select the correct Java method based on the supplied information. For example, consider the following case.

 

The supplied argument is an xs:untypedAtomic value of 10 and it is intended for the method mymethod(float).

However, there is another method in the class which takes an argument of another datatype: mymethod(double).

Since the method names are the same and the supplied type (xs:untypedAtomic) could be converted correctly to either float or double, it is possible that xs:untypedAtomic is converted to double instead of float.

Consequently the method selected will not be the required method and might not produce the expected result. To work around this, you can create a user-defined method with a different name and use this method.

 

Types that are not covered in the list above (for example xs:date) will not be converted and will generate an error. However, note that in some cases, it might be possible to create the required Java type by using a Java constructor.

 

© 2018-2024 Altova GmbH