use of com.thoughtworks.xstream.converters.ConversionException in project hudson-2.x by hudson.
the class XmlFile method read.
/**
* Loads the contents of this file into a new object.
*/
public Object read() throws IOException {
LOGGER.fine("Reading " + file);
Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
try {
return xs.fromXML(r);
} catch (StreamException e) {
throw new IOException2("Unable to read " + file, e);
} catch (ConversionException e) {
throw new IOException2("Unable to read " + file, e);
} catch (Error e) {
// mostly reflection errors
throw new IOException2("Unable to read " + file, e);
} finally {
r.close();
}
}
use of com.thoughtworks.xstream.converters.ConversionException in project hudson-2.x by hudson.
the class XReferenceConverter method doMarshal.
@Override
protected void doMarshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
// Do the default marshalling for the reference container
super.doMarshal(source, writer, context);
// Then delegate the storage of the reference target
XReference ref = (XReference) source;
Object target = ref.get();
if (target != null) {
try {
store(ref);
ref.holder = createStoredHolder(ref, target);
} catch (Exception e) {
throw new ConversionException("Failed to marshal reference: " + ref, e);
}
}
}
use of com.thoughtworks.xstream.converters.ConversionException in project camel by apache.
the class MultiSelectPicklistConverter method marshal.
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
// get Picklist enum element class from array class
Class<?> arrayClass = o.getClass();
final Class<?> aClass = arrayClass.getComponentType();
try {
Method getterMethod = aClass.getMethod("value");
final int length = Array.getLength(o);
// construct a string of form value1;value2;...
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < length; i++) {
buffer.append((String) getterMethod.invoke(Array.get(o, i)));
if (i < (length - 1)) {
buffer.append(';');
}
}
writer.setValue(buffer.toString());
} catch (Exception e) {
throw new ConversionException(String.format("Exception writing pick list value %s of type %s: %s", o, o.getClass().getName(), e.getMessage()), e);
}
}
use of com.thoughtworks.xstream.converters.ConversionException in project camel by apache.
the class PicklistEnumConverter method marshal.
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
Class<?> aClass = o.getClass();
try {
Method getterMethod = aClass.getMethod("value");
writer.setValue((String) getterMethod.invoke(o));
} catch (Exception e) {
throw new ConversionException(String.format("Exception writing pick list value %s of type %s: %s", o, o.getClass().getName(), e.getMessage()), e);
}
}
use of com.thoughtworks.xstream.converters.ConversionException in project camel by apache.
the class PicklistEnumConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String value = reader.getValue();
Class<?> requiredType = context.getRequiredType();
try {
Method factoryMethod = requiredType.getMethod(FACTORY_METHOD, String.class);
// use factory method to create object
return factoryMethod.invoke(null, value);
} catch (Exception e) {
throw new ConversionException(String.format("Exception reading pick list value %s of type %s: %s", value, context.getRequiredType().getName(), e.getMessage()), e);
}
}
Aggregations