com.thoughtworks.xstream.InitializationException Java Examples

The following examples show how to use com.thoughtworks.xstream.InitializationException. 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: AnnotationMapper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void processAliasAnnotation(final Class<?> type, final Set<Class<?>> types) {
    final XStreamAlias aliasAnnotation = type.getAnnotation(XStreamAlias.class);
    if (aliasAnnotation != null) {
        if (classAliasingMapper == null) {
            throw new InitializationException("No "
                + ClassAliasingMapper.class.getName()
                + " available");
        }
        classAliasingMapper.addClassAlias(aliasAnnotation.value(), type);
        if (aliasAnnotation.impl() != Void.class) {
            // Alias for Interface/Class with an impl
            defaultImplementationsMapper.addDefaultImplementation(
                aliasAnnotation.impl(), type);
            if (type.isInterface()) {
                types.add(aliasAnnotation.impl()); // alias Interface's impl
            }
        }
    }
}
 
Example #2
Source File: EnumToStringConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static <T extends Enum<T>> Map<String, T> extractStringMap(Class<T> type) {
    checkType(type);
    EnumSet<T> values = EnumSet.allOf(type);
    Map<String, T> strings = new HashMap<String, T>(values.size());
    for (T value : values) {
        if (strings.put(value.toString(), value) != null) {
            throw new InitializationException("Enum type "
                + type.getName()
                + " does not have unique string representations for its values");
        }
    }
    return strings;
}
 
Example #3
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processConverterAnnotations(final Class<?> type) {
    if (converterRegistry != null) {
        final XStreamConverters convertersAnnotation = type
            .getAnnotation(XStreamConverters.class);
        final XStreamConverter converterAnnotation = type
            .getAnnotation(XStreamConverter.class);
        final List<XStreamConverter> annotations = convertersAnnotation != null
            ? new ArrayList<XStreamConverter>(Arrays.asList(convertersAnnotation.value()))
            : new ArrayList<XStreamConverter>();
        if (converterAnnotation != null) {
            annotations.add(converterAnnotation);
        }
        for (final XStreamConverter annotation : annotations) {
            final Converter converter = cacheConverter(
                annotation, converterAnnotation != null ? type : null);
            if (converter != null) {
                if (converterAnnotation != null || converter.canConvert(type)) {
                    converterRegistry.registerConverter(converter, annotation.priority());
                } else {
                    throw new InitializationException("Converter "
                        + annotation.value().getName()
                        + " cannot handle annotated class "
                        + type.getName());
                }
            }
        }
    }
}
 
Example #4
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processAliasTypeAnnotation(final Class<?> type) {
    final XStreamAliasType aliasAnnotation = type.getAnnotation(XStreamAliasType.class);
    if (aliasAnnotation != null) {
        if (classAliasingMapper == null) {
            throw new InitializationException("No "
                + ClassAliasingMapper.class.getName()
                + " available");
        }
        classAliasingMapper.addTypeAlias(aliasAnnotation.value(), type);
    }
}
 
Example #5
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
private void processImplicitCollectionAnnotation(final Class<?> type) {
    final XStreamImplicitCollection implicitColAnnotation = type
        .getAnnotation(XStreamImplicitCollection.class);
    if (implicitColAnnotation != null) {
        if (implicitCollectionMapper == null) {
            throw new InitializationException("No "
                + ImplicitCollectionMapper.class.getName()
                + " available");
        }
        final String fieldName = implicitColAnnotation.value();
        final String itemFieldName = implicitColAnnotation.item();
        final Field field;
        try {
            field = type.getDeclaredField(fieldName);
        } catch (final NoSuchFieldException e) {
            throw new InitializationException(type.getName()
                + " does not have a field named '"
                + fieldName
                + "' as required by "
                + XStreamImplicitCollection.class.getName());
        }
        Class itemType = null;
        final Type genericType = field.getGenericType();
        if (genericType instanceof ParameterizedType) {
            final Type typeArgument = ((ParameterizedType)genericType)
                .getActualTypeArguments()[0];
            itemType = getClass(typeArgument);
        }
        if (itemType == null) {
            implicitCollectionMapper.add(type, fieldName, null, Object.class);
        } else {
            if (itemFieldName.equals("")) {
                implicitCollectionMapper.add(type, fieldName, null, itemType);
            } else {
                implicitCollectionMapper.add(type, fieldName, itemFieldName, itemType);
            }
        }
    }
}
 
Example #6
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processFieldAliasAnnotation(final Field field) {
    final XStreamAlias aliasAnnotation = field.getAnnotation(XStreamAlias.class);
    if (aliasAnnotation != null) {
        if (fieldAliasingMapper == null) {
            throw new InitializationException("No "
                + FieldAliasingMapper.class.getName()
                + " available");
        }
        fieldAliasingMapper.addFieldAlias(
            aliasAnnotation.value(), field.getDeclaringClass(), field.getName());
    }
}
 
Example #7
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processAsAttributeAnnotation(final Field field) {
    final XStreamAsAttribute asAttributeAnnotation = field
        .getAnnotation(XStreamAsAttribute.class);
    if (asAttributeAnnotation != null) {
        if (attributeMapper == null) {
            throw new InitializationException("No "
                + AttributeMapper.class.getName()
                + " available");
        }
        attributeMapper.addAttributeFor(field);
    }
}
 
Example #8
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processImplicitAnnotation(final Field field) {
    final XStreamImplicit implicitAnnotation = field.getAnnotation(XStreamImplicit.class);
    if (implicitAnnotation != null) {
        if (implicitCollectionMapper == null) {
            throw new InitializationException("No "
                + ImplicitCollectionMapper.class.getName()
                + " available");
        }
        final String fieldName = field.getName();
        final String itemFieldName = implicitAnnotation.itemFieldName();
        final String keyFieldName = implicitAnnotation.keyFieldName();
        boolean isMap = Map.class.isAssignableFrom(field.getType());
        Class itemType = null;
        if (!field.getType().isArray()) {
            final Type genericType = field.getGenericType();
            if (genericType instanceof ParameterizedType) {
                final Type[] actualTypeArguments = ((ParameterizedType)genericType)
                    .getActualTypeArguments();
                final Type typeArgument = actualTypeArguments[isMap ? 1 : 0];
                itemType = getClass(typeArgument);
            }
        }
        if (isMap) {
            implicitCollectionMapper.add(
                field.getDeclaringClass(), fieldName,
                itemFieldName != null && !"".equals(itemFieldName) ? itemFieldName : null,
                itemType, keyFieldName != null && !"".equals(keyFieldName)
                    ? keyFieldName
                    : null);
        } else {
            if (itemFieldName != null && !"".equals(itemFieldName)) {
                implicitCollectionMapper.add(
                    field.getDeclaringClass(), fieldName, itemFieldName, itemType);
            } else {
                implicitCollectionMapper
                    .add(field.getDeclaringClass(), fieldName, itemType);
            }
        }
    }
}
 
Example #9
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processOmitFieldAnnotation(final Field field) {
    final XStreamOmitField omitFieldAnnotation = field
        .getAnnotation(XStreamOmitField.class);
    if (omitFieldAnnotation != null) {
        if (elementIgnoringMapper == null) {
            throw new InitializationException("No "
                + ElementIgnoringMapper.class.getName()
                + " available");
        }
        elementIgnoringMapper.omitField(field.getDeclaringClass(), field.getName());
    }
}
 
Example #10
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processLocalConverterAnnotation(final Field field) {
    final XStreamConverter annotation = field.getAnnotation(XStreamConverter.class);
    if (annotation != null) {
        final Converter converter = cacheConverter(annotation, field.getType());
        if (converter != null) {
            if (localConversionMapper == null) {
                throw new InitializationException("No "
                    + LocalConversionMapper.class.getName()
                    + " available");
            }
            localConversionMapper.registerLocalConverter(
                field.getDeclaringClass(), field.getName(), converter);
        }
    }
}
 
Example #11
Source File: DefaultImplementationsMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void addDefaultImplementation(Class defaultImplementation, Class ofType) {
    if (defaultImplementation != null && defaultImplementation.isInterface()) {
        throw new InitializationException(
            "Default implementation is not a concrete class: "
                + defaultImplementation.getName());
    }
    typeToImpl.put(ofType, defaultImplementation);
    implToType.put(defaultImplementation, ofType);
}
 
Example #12
Source File: VRaptorMatchers.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private VRaptorMatchers(){
	throw new InitializationException("Not allowed to initialize");
}
 
Example #13
Source File: HasConstructor.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private HasConstructor(){
	throw new InitializationException("Not allowed to initialize");
}
 
Example #14
Source File: VRaptorMatchers.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private VRaptorMatchers(){
	throw new InitializationException("Not allowed to initialize");
}
 
Example #15
Source File: StringUtils.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private StringUtils(){
	throw new InitializationException("Not allowed to initialize");
}
 
Example #16
Source File: DownloadBuilder.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private DownloadBuilder () {
	throw new InitializationException("Not allowed to initialize");
}
 
Example #17
Source File: CDIProxies.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private CDIProxies(){
	throw new InitializationException("Not allowed to initialize");
}
 
Example #18
Source File: Results.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
private Results(){
	throw new InitializationException("Not allowed to initialize");
}
 
Example #19
Source File: EnumToStringConverter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static <T> void checkType(Class<T> type) {
    if (!Enum.class.isAssignableFrom(type) && type != Enum.class) {
        throw new InitializationException("Converter can only handle enum types");
    }
}