Java Code Examples for com.thoughtworks.xstream.converters.ConversionException#add()

The following examples show how to use com.thoughtworks.xstream.converters.ConversionException#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CGLIBEnhancedConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Callback createReverseEngineeredCallbackOfProperType(Callback callback, int index,
    Map callbackIndexMap) {
    Class iface = null;
    Class[] interfaces = callback.getClass().getInterfaces();
    for (int i = 0; i < interfaces.length; i++ ) {
        if (Callback.class.isAssignableFrom(interfaces[i])) {
            iface = interfaces[i];
            if (iface == Callback.class) {
                ConversionException exception = new ConversionException(
                    "Cannot handle CGLIB callback");
                exception.add("CGLIB-callback-type", callback.getClass().getName());
                throw exception;
            }
            interfaces = iface.getInterfaces();
            if (Arrays.asList(interfaces).contains(Callback.class)) {
                break;
            }
            i = -1;
        }
    }
    return (Callback)Proxy.newProxyInstance(
        iface.getClassLoader(), new Class[]{iface},
        new ReverseEngineeringInvocationHandler(index, callbackIndexMap));
}
 
Example 2
Source File: XStream.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserialize an object from a hierarchical data structure (such as XML).
 * 
 * @param root If present, the passed in object will have its fields populated, as opposed
 *            to XStream creating a new instance. Note, that this is a special use case!
 *            With the ReflectionConverter XStream will write directly into the raw memory
 *            area of the existing object. Use with care!
 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
 *            want. If not present, XStream shall create one lazily as needed.
 * @throws XStreamException if the object cannot be deserialized
 */
public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
    try {
        if (!securityInitialized && !securityWarningGiven) {
            securityWarningGiven = true;
            System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable.");
        }
        return marshallingStrategy.unmarshal(
            root, reader, dataHolder, converterLookup, mapper);

    } catch (ConversionException e) {
        Package pkg = getClass().getPackage();
        String version = pkg != null ? pkg.getImplementationVersion() : null;
        e.add("version", version != null ? version : "not available");
        throw e;
    }
}
 
Example 3
Source File: SortableFieldKeySorter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public int compare(final String first, final String second) {
    int firstPosition = -1, secondPosition = -1;
    for (int i = 0; i < fieldOrder.length; i++) {
        if (fieldOrder[i].equals(first)) {
            firstPosition = i;
        }
        if (fieldOrder[i].equals(second)) {
            secondPosition = i;
        }
    }
    if (firstPosition == -1 || secondPosition == -1) {
        // field not defined!!!
        final ConversionException exception = new ConversionException(
            "Incomplete list of serialized fields for type");
        exception.add("sort-type", type.getName());
        throw exception;
    }
    return firstPosition - secondPosition;
}
 
Example 4
Source File: ZonedDateTimeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return ZonedDateTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as zoned date time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 5
Source File: YearMonthConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public YearMonth fromString(final String str) {
    try {
        return YearMonth.parse(str);
    } catch (final DateTimeParseException ex) {
        final ConversionException exception = new ConversionException("Cannot parse value as year month", ex);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 6
Source File: EnumToStringConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(String str) {
    if (str == null) {
        return null;
    }
    T result = strings.get(str);
    if (result == null) {
        ConversionException exception = new ConversionException("Invalid string representation for enum type");
        exception.add("enum-type", enumType.getName());
        exception.add("enum-string", str);
        throw exception;
    }
    return result;
}
 
Example 7
Source File: MonthDayConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MonthDay fromString(final String str) {
    try {
        return MonthDay.parse(str);
    } catch (final DateTimeParseException ex) {
        final ConversionException exception = new ConversionException("Cannot parse value as month day", ex);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 8
Source File: JapaneseEraConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JapaneseEra fromString(final String str) {
    if (str == null) {
        return null;
    }
    try {
        return JapaneseEra.valueOf(str);
    } catch (final IllegalArgumentException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as Japanese era", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 9
Source File: InstantConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Instant fromString(final String str) {
    try {
        return Instant.parse(str);
    } catch (final DateTimeParseException ex) {
        final ConversionException exception = new ConversionException("Cannot parse value as instant", ex);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 10
Source File: OffsetDateTimeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return OffsetDateTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 11
Source File: ChronologyConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Chronology fromString(final String str) {
    if (str == null) {
        return null;
    }
    try {
        return Chronology.of(str);
    } catch (final DateTimeException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as chronology", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 12
Source File: OffsetTimeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return OffsetTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as offset time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 13
Source File: AbstractReflectionConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public boolean add(Object object) {
    if (object == null) {
        boolean containsNull = !map.containsKey(null);
        map.put(null, null);
        return containsNull;
    }
    Class itemType = object.getClass();

    if (keyFieldName != null) {
        Field field = (Field)fieldCache.get(itemType);
        if (field == null) {
            field = reflectionProvider.getField(itemType, keyFieldName);
            fieldCache.put(itemType, field);
        }
        if (field != null) {
            Object key = Fields.read(field, object);
            return map.put(key, object) == null;
        }
    } else if (object instanceof Map.Entry) {
        final Map.Entry entry = (Map.Entry)object;
        return map.put(entry.getKey(), entry.getValue()) == null;
    }

    ConversionException exception =
            new ConversionException("Element  is not defined as entry for implicit map");
    exception.add("map-type", map.getClass().getName());
    exception.add("element-type", object.getClass().getName());
    throw exception;
}
 
Example 14
Source File: TreeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object convertAnother(Object parent, Class type, Converter converter) {
    type = mapper.defaultImplementationOf(type);
    if (converter == null) {
        converter = converterLookup.lookupConverterForType(type);
    } else {
        if (!converter.canConvert(type)) {
            ConversionException e = new ConversionException(
                "Explicit selected converter cannot handle type");
            e.add("item-type", type.getName());
            e.add("converter-type", converter.getClass().getName());
            throw e;
        }
    }
    return convert(parent, type, converter);
}
 
Example 15
Source File: LocalTimeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return LocalTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as local time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 16
Source File: TreeMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void convertAnother(Object item, Converter converter) {
    if (converter == null) {
        converter = converterLookup.lookupConverterForType(item.getClass());
    } else {
        if (!converter.canConvert(item.getClass())) {
            ConversionException e = new ConversionException(
                "Explicit selected converter cannot handle item");
            e.add("item-type", item.getClass().getName());
            e.add("converter-type", converter.getClass().getName());
            throw e;
        }
    }
    convert(item, converter);
}
 
Example 17
Source File: LocalDateTimeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return LocalDateTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as local date time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 18
Source File: YearConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Year fromString(final String str) {
    try {
        return Year.of(Integer.parseInt(str));
    } catch (final NumberFormatException ex) {
        final ConversionException exception = new ConversionException("Cannot parse value as year", ex);
        exception.add("value", str);
        throw exception;
    }
}
 
Example 19
Source File: CGLIBEnhancedConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public int accept(Method method) {
    if (!callbackIndexMap.containsKey(method)) {
        ConversionException exception = new ConversionException(
            "CGLIB callback not detected in reverse engineering");
        exception.add("CGLIB-callback", method.toString());
        throw exception;
    }
    return ((Integer)callbackIndexMap.get(method)).intValue();
}
 
Example 20
Source File: AbstractAttributedCharacterIteratorAttributeConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object fromString(final String str) {
    if (attributeMap.containsKey(str)) {
        return attributeMap.get(str);
    }
    ConversionException exception = new ConversionException("Cannot find attribute");
    exception.add("attribute-type", type.getName());
    exception.add("attribute-name", str);
    throw exception;
}