* @return the conversion preference. A high number indicates a low preference;
* -1 indicates that conversion is not possible.
*/
private int getConversionPreference(Expression arg, Class required) {
ItemType itemType = arg.getItemType();
int cardinality = arg.getCardinality();
if (required == Object.class) {
return 100;
} else if (Cardinality.allowsMany(cardinality)) {
if (required.isAssignableFrom(SequenceIterator.class)) {
return 20;
} else if (required.isAssignableFrom(SequenceValue.class)) {
return 21;
} else if (Collection.class.isAssignableFrom(required)) {
return 22;
} else if (required.isAssignableFrom(NodeList.class)) {
return 23;
} else if (required.isArray()) {
return 24;
// sort out at run-time whether the component type of the array is actually suitable
} else {
return -1; // conversion not possible
}
} else {
if (Type.isNodeType(itemType)) {
if (required.isAssignableFrom(NodeInfo.class)) {
return 20;
} else if (required.isAssignableFrom(DocumentInfo.class)) {
return 21;
} else if (required.isAssignableFrom(Node.class)) {
return 22;
} else if (required.isAssignableFrom(NodeList.class)) {
return 23;
} else {
return -1;
}
} else {
int primitiveType = itemType.getPrimitiveType();
return atomicConversionPreference(primitiveType, required);
}
}
}