Search in sources :

Example 1 with ConversionException

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();
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) XppReader(com.thoughtworks.xstream.io.xml.XppReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream) IOException2(hudson.util.IOException2) StreamException(com.thoughtworks.xstream.io.StreamException)

Example 2 with ConversionException

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);
        }
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) IOException(java.io.IOException) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Example 3 with ConversionException

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);
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) Method(java.lang.reflect.Method) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Example 4 with ConversionException

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);
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) Method(java.lang.reflect.Method) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Example 5 with ConversionException

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);
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) Method(java.lang.reflect.Method) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Aggregations

ConversionException (com.thoughtworks.xstream.converters.ConversionException)21 IOException (java.io.IOException)5 InputStreamReader (java.io.InputStreamReader)4 Method (java.lang.reflect.Method)4 XppReader (com.thoughtworks.xstream.io.xml.XppReader)3 Metacard (ddf.catalog.data.Metacard)3 CannotResolveClassException (com.thoughtworks.xstream.mapper.CannotResolveClassException)2 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 ActionEvent (java.awt.event.ActionEvent)2 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)2 HashTree (org.apache.jorphan.collections.HashTree)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 XStream (com.thoughtworks.xstream.XStream)1 SingleValueConverter (com.thoughtworks.xstream.converters.SingleValueConverter)1 NonExistentFieldException (com.thoughtworks.xstream.converters.reflection.NonExistentFieldException)1 StreamException (com.thoughtworks.xstream.io.StreamException)1 HierarchicalStreamCopier (com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier)1