public Value valueOf(Object value, Context context) throws ValueCastException {
if ( value instanceof XMLValue ) {
return (XMLValue)value;
} else if ( value instanceof StreamableValue ) {
try {
return new DocumentValue(((StreamableValue)value).getInputStream());
} catch ( Exception e ) {
throw new ValueCastException(new ErrorMessage("uncastableXMLValue", new Object[] { value }), e);
}
} else if ( value instanceof PrintableValue ) {
try {
return new DocumentValue(new ByteArrayInputStream(((PrintableValue)value).toString().getBytes("UTF-8")));
} catch ( Exception e ) {
throw new ValueCastException(new ErrorMessage("uncastableXMLValue", new Object[] { value }), e);
}
}
throw new ValueCastException(new ErrorMessage("uncastableXMLValue", new Object[] { value }));