Package com.thoughtworks.xstream.converters

Examples of com.thoughtworks.xstream.converters.Converter


    public DefaultConverterLookup(ClassMapper classMapper) {
        this((Mapper)classMapper);
    }

    public Converter lookupConverterForType(Class type) {
        Converter cachedConverter = (Converter) typeToConverterMap.get(type);
        if (cachedConverter != null) return cachedConverter;
        Class mapType = mapper.defaultImplementationOf(type);
        Iterator iterator = converters.iterator();
        while (iterator.hasNext()) {
            Converter converter = (Converter) iterator.next();
            if (converter.canConvert(mapType)) {
                typeToConverterMap.put(type, converter);
                return converter;
            }
        }
        throw new ConversionException("No converter specified for " + type);
View Full Code Here


    excludes.clear();
    return this;
  }

  private void registerProxyInitializer() {
    xstream.registerConverter(new Converter() {

      public boolean canConvert(Class clazz) {
        return initializer.isProxy(clazz);
      }

      public Object unmarshal(HierarchicalStreamReader reader,
          UnmarshallingContext context) {
        throw new AssertionError();
      }

      public void marshal(Object value, HierarchicalStreamWriter writer,
          MarshallingContext context) {
        Converter converter = xstream.getConverterLookup().lookupConverterForType(initializer.getActualClass(value));
        initializer.initialize(value);
        converter.marshal(value, writer, context);
      }
    });
  }
View Full Code Here

            }

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

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

        _xstream.alias("module-info", ModuleInfoImpl.class);
        _xstream.alias("user", User.class);
        _xstream.alias("group", Group.class);
        _xstream.alias("module-descriptor", ModuleDescriptorImpl.class);
        _xstream.alias("answer", Answer.class);
        _xstream.registerConverter(new Converter() {
            public Object unmarshal(HierarchicalStreamReader r, UnmarshallingContext ctx) {
                r.moveDown();
                try {
                    return Visibility.fromInt(Integer.parseInt(r.getValue().trim()));
                } finally {
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

            }

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

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

     *
     * @param type the converter type to instantiate
     * @return the new instance
     */
    private Converter newInstance(Class<? extends ConverterMatcher> type) {
        Converter converter;
        // TODO: We need a separate exception for runtime initialization.
        try {
            if (SingleValueConverter.class.isAssignableFrom(type)) {
                final SingleValueConverter svc = (SingleValueConverter)type.getConstructor().newInstance();
                converter = new SingleValueConverterWrapper(svc);
View Full Code Here

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

            if (converterAnnotation != null) {
                annotations.add(converterAnnotation);
            }
            for (final XStreamConverter annotation : annotations) {
                final Class<? extends ConverterMatcher> converterType = annotation.value();
                final Converter converter = cacheConverter(converterType);
                if (converter != null) {
                    if (converterAnnotation != null || converter.canConvert(type)) {
                        converterRegistry.registerConverter(converter, XStream.PRIORITY_NORMAL);
                    } else {
                        throw new InitializationException("Converter "
                            + converterType.getName()
                            + " cannot handle annotated class "
View Full Code Here

    private void processLocalConverterAnnotation(final Field field) {
        final XStreamConverter annotation = field.getAnnotation(XStreamConverter.class);
        if (annotation != null) {
            final Class<? extends ConverterMatcher> converterType = annotation.value();
            final Converter converter = cacheConverter(converterType);
            if (converter != null) {
                if (localConversionMapper == null) {
                    throw new InitializationException("No "
                        + LocalConversionMapper.class.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.