Package com.thoughtworks.xstream.converters

Examples of com.thoughtworks.xstream.converters.Converter


        private AssociatedConverterImpl(XStream xstream) {
            this.xstream = xstream;
        }

        private Converter findConverter(Class<?> t) {
            Converter result = cache.get(t);
            if (result != null)
                // ConcurrentHashMap does not allow null, so use this object to represent null
                return result == this ? null : result;
            try {
                if(t==null || t.getClassLoader()==null)
View Full Code Here


        });
    }

    protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
        Converter converter = mapper.getLocalConverter(field.getDeclaringClass(), field.getName());
        context.convertAnother(newObj, converter);
    }
View Full Code Here

        //boolean fieldExistsInClass = reflectionProvider.fieldDefinedInClass(attrName, result.getClass());
        return reflectionProvider.getFieldOrNull(result.getClass(),attrName)!=null;
    }

    protected Object unmarshalField(final UnmarshallingContext context, final Object result, Class type, Field field) {
        Converter converter = mapper.getLocalConverter(field.getDeclaringClass(), field.getName());
        return context.convertAnother(result, type, converter);
    }
View Full Code Here

            }

            if (this.converters != null) {
                for (String name : this.converters) {
                    Class<Converter> converterClass = resolver.resolveMandatoryClass(name, Converter.class);
                    Converter converter;

                    Constructor con = null;
                    try {
                        con = converterClass.getDeclaredConstructor(new Class[] {XStream.class});
                    } catch (Exception e) {
View Full Code Here

    private SingleValueConverter getSingleValueConverter(final Class<?> type) {
        SingleValueConverter conv = Enum.class.isAssignableFrom(type) ? enumMapper.getConverterFromItemType(null, type,
            null) : mapper().getConverterFromItemType(null, type, null);
        if (conv == null) {
            final Converter converter = lookup.lookupConverterForType(type);
            if (converter instanceof SingleValueConverter) {
                conv = (SingleValueConverter)converter;
            } else {
                throw new ConversionException("No SingleValueConverter for key available");
            }
View Full Code Here

     * @param converter the converter to use
     * @since 1.3
     */
    public void registerLocalConverter(final Class<?> definedIn, final String fieldName,
            final SingleValueConverter converter) {
        final Converter wrapper = new SingleValueConverterWrapper(converter);
        registerLocalConverter(definedIn, fieldName, wrapper);
    }
View Full Code Here

    public void addAttributeFor(final Class<?> type) {
        typeSet.add(type);
    }

    private SingleValueConverter getLocalConverterFromItemType(final Class<?> type) {
        final Converter converter = converterLookup.lookupConverterForType(type);
        if (converter != null && converter instanceof SingleValueConverter) {
            return (SingleValueConverter)converter;
        } else {
            return null;
        }
View Full Code Here

    }

    private SingleValueConverter getLocalSingleValueConverter(final Class<?> definedIn, final String fieldName,
            final Class<?> type) {
        if (attributeMapper != null && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) {
            final Converter converter = getLocalConverter(definedIn, fieldName);
            if (converter != null && converter instanceof SingleValueConverter) {
                return (SingleValueConverter)converter;
            }
        }
        return null;
View Full Code Here

        final int idx = key.indexOf('@');
        if (idx < 0) {
            throw new StreamException("Not a valid key: " + key);
        }
        final Class<?> type = getMapper().realClass(key.substring(0, idx));
        final Converter converter = getConverterLookup().lookupConverterForType(type);
        if (converter instanceof SingleValueConverter) {
            final SingleValueConverter svConverter = (SingleValueConverter)converter;
            @SuppressWarnings("unchecked")
            final K k = (K)svConverter.fromString(key.substring(idx + 1));
            return k;
View Full Code Here

    protected String getName(final Object key) {
        if (key == null) {
            return "null@null.xml";
        }
        final Class<?> type = key.getClass();
        final Converter converter = getConverterLookup().lookupConverterForType(type);
        if (converter instanceof SingleValueConverter) {
            final SingleValueConverter svConverter = (SingleValueConverter)converter;
            return getMapper().serializedClass(type) + '@' + escape(svConverter.toString(key)) + ".xml";
        } else {
            throw new StreamException("No SingleValueConverter for type " + type.getName() + " available");
View Full Code Here

TOP

Related Classes of com.thoughtworks.xstream.converters.Converter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.