Java Code Examples for com.thoughtworks.xstream.mapper.Mapper

The following examples show how to use com.thoughtworks.xstream.mapper.Mapper. These examples are extracted from open source projects. 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
/**
 * Creates a new ToAttributedValueConverter instance.
 * 
 * @param mapper the mapper in use
 * @param reflectionProvider the reflection provider in use
 * @param lookup the converter lookup in use
 * @param valueFieldName the field defining the tag's value (may be null)
 * @param valueDefinedIn the type defining the field
 */
public IdentifiableToIdConverter(
    final Class<Identifiable<?>> type, final Mapper mapper, final ReflectionProvider reflectionProvider,
    final ConverterLookup lookup, final String valueFieldName, Class<?> valueDefinedIn) {
    this.type = type;

       Field field = null;
       try {
           field = (valueDefinedIn != null ? valueDefinedIn : type.getSuperclass())
               .getDeclaredField("id");
          
           if (!field.isAccessible()) {
               field.setAccessible(true);
           }
       } catch (NoSuchFieldException e) {
           throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
       }
}
 
Example 2
Source Project: lams   Source File: NamedArrayConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final List list = new ArrayList();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        final Object item;
        final String className = HierarchicalStreams.readClassAttribute(reader, mapper);
        final Class itemType = className == null ? arrayType.getComponentType() : mapper.realClass(className);
        if (Mapper.Null.class.equals(itemType)) {
            item = null;
        } else {
            item = context.convertAnother(null, itemType);
        }
        list.add(item);
        reader.moveUp();
    }
    final Object array = Array.newInstance(arrayType.getComponentType(), list.size());
    for (int i = 0; i < list.size(); ++i) {
        Array.set(array, i, list.get(i));
    }
    return array;
}
 
Example 3
/**
 * Creates a new ToAttributedValueConverter instance.
 * 
 * @param type the type that is handled by this converter instance
 * @param mapper the mapper in use
 * @param reflectionProvider the reflection provider in use
 * @param lookup the converter lookup in use
 * @param valueFieldName the field defining the tag's value (may be null)
 * @param valueDefinedIn the type defining the field
 */
public ToAttributedValueConverter(
    final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider,
    final ConverterLookup lookup, final String valueFieldName, Class valueDefinedIn) {
    this.type = type;
    this.mapper = mapper;
    this.reflectionProvider = reflectionProvider;
    this.lookup = lookup;

    if (valueFieldName == null) {
        valueField = null;
    } else {
        Field field = null;
        try {
            field = (valueDefinedIn != null ? valueDefinedIn : type)
                .getDeclaredField(valueFieldName);
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
        } catch (NoSuchFieldException e) {
            throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
        }
        this.valueField = field;
    }
    enumMapper = JVM.isVersion(5) ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null;
}
 
Example 4
Source Project: weblaf   Source File: StyleConverterUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Read properties for the specified class into the provided properties map.
 *
 * @param reader     {@link HierarchicalStreamReader}
 * @param context    {@link UnmarshallingContext}
 * @param mapper     {@link Mapper}
 * @param properties map to read properties into
 * @param clazz      class to read properties for, it will be used to retrieve properties field types
 * @param styleId    component {@link com.alee.managers.style.StyleId}, might be used to report problems
 */
public static void readProperties ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context,
                                    @NotNull final Mapper mapper, @NotNull final Map<String, Object> properties,
                                    @NotNull final Class clazz, final String styleId )
{
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();
        readProperty ( reader, context, mapper, styleId, properties, clazz, reader.getNodeName () );
        reader.moveUp ();
    }
}
 
Example 5
Source Project: cuba   Source File: CubaXStream.java    License: Apache License 2.0 5 votes vote down vote up
protected CubaXStream(
        ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
        Mapper mapper, final CubaXStreamConverterLookup converterLookup) {
    super(reflectionProvider, driver, classLoader, mapper,
            converterLookup::lookupConverterForType,
            converterLookup::registerConverter);
}
 
Example 6
Source Project: lams   Source File: TreeUnmarshaller.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TreeUnmarshaller(
    Object root, HierarchicalStreamReader reader, ConverterLookup converterLookup,
    Mapper mapper) {
    this.root = root;
    this.reader = reader;
    this.converterLookup = converterLookup;
    this.mapper = mapper;
}
 
Example 7
Source Project: lams   Source File: XStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Mapper buildMapper() {
    Mapper mapper = new DefaultMapper(classLoaderReference);
    if (useXStream11XmlFriendlyMapper()) {
        mapper = new XStream11XmlFriendlyMapper(mapper);
    }
    mapper = new DynamicProxyMapper(mapper);
    mapper = new PackageAliasingMapper(mapper);
    mapper = new ClassAliasingMapper(mapper);
    mapper = new ElementIgnoringMapper(mapper);
    mapper = new FieldAliasingMapper(mapper);
    mapper = new AttributeAliasingMapper(mapper);
    mapper = new SystemAttributeAliasingMapper(mapper);
    mapper = new ImplicitCollectionMapper(mapper, reflectionProvider);
    mapper = new OuterClassMapper(mapper);
    mapper = new ArrayMapper(mapper);
    mapper = new DefaultImplementationsMapper(mapper);
    mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider);
    if (JVM.isVersion(5)) {
        mapper = buildMapperDynamically(
            "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
            new Object[]{mapper});
    }
    mapper = new LocalConversionMapper(mapper);
    mapper = new ImmutableTypesMapper(mapper);
    if (JVM.isVersion(8)) {
        mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class},
            new Object[]{mapper});
    }
    mapper = new SecurityMapper(mapper);
    if (JVM.isVersion(5)) {
        mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{
            Mapper.class, ConverterRegistry.class, ConverterLookup.class,
            ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{
            mapper, converterRegistry, converterLookup, classLoaderReference,
            reflectionProvider});
    }
    mapper = wrapMapper((MapperWrapper)mapper);
    mapper = new CachingMapper(mapper);
    return mapper;
}
 
Example 8
Source Project: lams   Source File: CollectionConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a CollectionConverter for a special Collection type.
 * @param mapper the mapper
 * @param type the Collection type to handle
 * @since 1.4.5
 */
public CollectionConverter(Mapper mapper, Class type) {
    super(mapper);
    this.type = type;
    if (type != null && !Collection.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException(type + " not of type " + Collection.class);
    }
}
 
Example 9
Source Project: lams   Source File: MapConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a MapConverter for a special Map type.
 * @param mapper the mapper
 * @param type the type to handle
 * @since 1.4.5
 */
public MapConverter(Mapper mapper, Class type) {
    super(mapper);
    this.type = type;
    if (type != null && !Map.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException(type + " not of type " + Map.class);
    }
}
 
Example 10
Source Project: brooklyn-server   Source File: XmlMementoSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected MapperWrapper wrapMapperForNormalUsage(Mapper next) {
    MapperWrapper mapper = super.wrapMapperForNormalUsage(next);
    mapper = new CustomMapper(mapper, Entity.class, "entityProxy");
    mapper = new CustomMapper(mapper, Location.class, "locationProxy");
    mapper = new UnwantedStateLoggingMapper(mapper);
    return mapper;
}
 
Example 11
static Mapper createEnumMapper(final Mapper mapper) {
    try {
        Class enumMapperClass = Class.forName(
            "com.thoughtworks.xstream.mapper.EnumMapper", true,
            Mapper.class.getClassLoader());
        return (Mapper)DependencyInjectionFactory.newInstance(
            enumMapperClass,
            new Object[]{new UseAttributeForEnumMapper(mapper
                .lookupMapperOfType(DefaultMapper.class))});
    } catch (Exception e) {
        return null;
    }
}
 
Example 12
Source Project: lams   Source File: AbstractJsonWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method to return the appropriate JSON type for a Java type.
 * 
 * @param clazz the type
 * @return One of the {@link Type} instances
 * @since 1.4.4
 */
protected Type getType(Class clazz) {
    return clazz == Mapper.Null.class
        ? Type.NULL
        : (clazz == Boolean.class || clazz == Boolean.TYPE) 
            ? Type.BOOLEAN 
            : NUMBER_TYPES.contains(clazz) 
                ? Type.NUMBER 
                : Type.STRING;
}
 
Example 13
Source Project: lams   Source File: NamedArrayConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a NamedArrayConverter.
 * @param arrayType
 * @param mapper
 * @param itemName
 * @since 1.4.6
 */
public NamedArrayConverter(final Class arrayType, final Mapper mapper, final String itemName) {
    if (!arrayType.isArray()) {
        throw new IllegalArgumentException(arrayType.getName() + " is not an array");
    }
    this.arrayType = arrayType;
    this.mapper = mapper;
    this.itemName = itemName;
}
 
Example 14
Source Project: lams   Source File: FontConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a FontConverter.
 * @param mapper
 * @since 1.4.5
 */
public FontConverter(Mapper mapper) {
    this.mapper = mapper;
    if (mapper == null) {
        textAttributeConverter = null;
    } else {
        textAttributeConverter = new TextAttributeConverter();
    }
}
 
Example 15
Source Project: brooklyn-server   Source File: XmlMementoSerializer.java    License: Apache License 2.0 5 votes vote down vote up
private static Class<?> readClassType(HierarchicalStreamReader reader, Mapper mapper) {
    String classAttribute = readClassAttribute(reader, mapper);
    Class<?> type;
    if (classAttribute == null) {
        type = mapper.realClass(reader.getNodeName());
    } else {
        type = mapper.realClass(classAttribute);
    }
    return type;
}
 
Example 16
Source Project: lams   Source File: NamedMapConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void writeItem(String name, Class type, Object item, MarshallingContext context,
    HierarchicalStreamWriter writer) {
    Class itemType = item == null ? Mapper.Null.class : item.getClass();
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
    if (!itemType.equals(type)) {
        String attributeName = mapper().aliasForSystemAttribute("class");
        if (attributeName != null) {
            writer.addAttribute(attributeName, mapper().serializedClass(itemType));
        }
    }
    if (item != null) {
        context.convertAnother(item);
    }
    writer.endNode();
}
 
Example 17
Source Project: lams   Source File: HierarchicalStreams.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) {
    String attributeName = mapper.aliasForSystemAttribute("resolves-to");
    String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName);
    if (classAttribute == null) {
        attributeName = mapper.aliasForSystemAttribute("class");
        if (attributeName != null) {
            classAttribute = reader.getAttribute(attributeName);
        }
    }
    return classAttribute;
}
 
Example 18
/**
 * @deprecated As of 1.4.11 use {@link #writeCompleteItem(Object, MarshallingContext, HierarchicalStreamWriter)}
 *             instead.
 */
protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
    final Class itemType = item == null ? Mapper.Null.class : item.getClass();
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
    if (!itemType.equals(type)) {
        String attributeName = mapper().aliasForSystemAttribute("class");
        if (attributeName != null) {
            writer.addAttribute(attributeName, mapper().serializedClass(itemType));
        }
    }
    if (item != null) {
        context.convertAnother(item);
    }
    writer.endNode();
}
 
Example 19
Source Project: lams   Source File: TreeUnmarshaller.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected Mapper getMapper() {
    return this.mapper;
}
 
Example 20
Source Project: onedev   Source File: CollectionConverter.java    License: MIT License 4 votes vote down vote up
public CollectionConverter(Mapper mapper) {
	super(mapper);
}
 
Example 21
Source Project: onedev   Source File: MapConverter.java    License: MIT License 4 votes vote down vote up
public MapConverter(Mapper mapper) {
	super(mapper);
}
 
Example 22
Source Project: onedev   Source File: MapConverter.java    License: MIT License 4 votes vote down vote up
public MapConverter(Mapper mapper, Class<?> type) {
	super(mapper, type);
}
 
Example 23
Source Project: onedev   Source File: ReflectionConverter.java    License: MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider, Class type) {
   	super(mapper, reflectionProvider, type);
   }
 
Example 24
Source Project: depan   Source File: EdgeReferenceConverter.java    License: Apache License 2.0 4 votes vote down vote up
public EdgeReferenceConverter(
    Mapper mapper, ReferencedGraphDocumentConverter refConverter) {
  this.mapper = mapper;
  this.refConverter = refConverter;
}
 
Example 25
Source Project: lams   Source File: TreeMarshaller.java    License: GNU General Public License v2.0 4 votes vote down vote up
public TreeMarshaller(
    HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) {
    this.writer = writer;
    this.converterLookup = converterLookup;
    this.mapper = mapper;
}
 
Example 26
Source Project: lams   Source File: NullPermission.java    License: GNU General Public License v2.0 4 votes vote down vote up
public boolean allows(Class type) {
    return type == null || type == Mapper.Null.class;
}
 
Example 27
Source Project: depan   Source File: GraphModelConverter.java    License: Apache License 2.0 4 votes vote down vote up
public GraphModelConverter(Mapper mapper) {
  this.mapper = mapper;
}
 
Example 28
Source Project: lams   Source File: CGLIBEnhancedConverter.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated As of 1.4.5 use {@link #CGLIBEnhancedConverter(Mapper, ReflectionProvider, ClassLoaderReference)}
 */
public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoader classLoader) {
    super(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), classLoader);
    this.fieldCache = new HashMap();
}
 
Example 29
public AbstractReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
    this.mapper = mapper;
    this.reflectionProvider = reflectionProvider;
    serializationMethodInvoker = new SerializationMethodInvoker();
    serializationMembers = serializationMethodInvoker.serializationMembers;
}
 
Example 30
Source Project: brooklyn-server   Source File: MapConverter.java    License: Apache License 2.0 4 votes vote down vote up
public MapConverter(Mapper mapper) {
    super(mapper);
}