// re-use existing code if possible
int sourceType = v.getType();
if (sourceType == targetType) {
return v;
}
CoreValueFactory vf = query.getValueFactory();
switch (sourceType) {
case PropertyType.STRING:
switch(targetType) {
case PropertyType.BINARY:
try {
byte[] data = v.getString().getBytes("UTF-8");
return vf.createValue(new ByteArrayInputStream(data));
} catch (IOException e) {
// I don't know in what case that could really occur
// except if UTF-8 isn't supported
throw new IllegalArgumentException(v.getString(), e);
}
}
return vf.createValue(v.getString(), targetType);
}
switch (targetType) {
case PropertyType.STRING:
return vf.createValue(v.getString());
case PropertyType.BOOLEAN:
return vf.createValue(v.getBoolean());
case PropertyType.DATE:
return vf.createValue(v.getString(), PropertyType.DATE);
case PropertyType.LONG:
return vf.createValue(v.getLong());
case PropertyType.DOUBLE:
return vf.createValue(v.getDouble());
case PropertyType.DECIMAL:
return vf.createValue(v.getString(), PropertyType.DECIMAL);
case PropertyType.NAME:
return vf.createValue(getOakPath(v.getString()), PropertyType.NAME);
case PropertyType.PATH:
return vf.createValue(v.getString(), PropertyType.PATH);
case PropertyType.REFERENCE:
return vf.createValue(v.getString(), PropertyType.REFERENCE);
case PropertyType.WEAKREFERENCE:
return vf.createValue(v.getString(), PropertyType.WEAKREFERENCE);
case PropertyType.URI:
return vf.createValue(v.getString(), PropertyType.URI);
case PropertyType.BINARY:
try {
byte[] data = v.getString().getBytes("UTF-8");
return vf.createValue(new ByteArrayInputStream(data));
} catch (IOException e) {
// I don't know in what case that could really occur
// except if UTF-8 isn't supported
throw new IllegalArgumentException(v.getString(), e);
}