本文整理汇总了Java中com.thoughtworks.xstream.mapper.Mapper类的典型用法代码示例。如果您正苦于以下问题:Java Mapper类的具体用法?Java Mapper怎么用?Java Mapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mapper类属于com.thoughtworks.xstream.mapper包,在下文中一共展示了Mapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshal
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final int length = Array.getLength(source);
for (int i = 0; i < length; ++i) {
final Object item = Array.get(source, i);
final Class<?> itemType = item == null ? Mapper.Null.class : arrayType.getComponentType().isPrimitive()
? Primitives.unbox(item.getClass())
: item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType);
if (!itemType.equals(arrayType.getComponentType())) {
final String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
}
示例2: unmarshal
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final List<Object> list = new ArrayList<Object>();
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;
}
示例3: marshal
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Font font = (Font)source;
final Map<TextAttribute, ?> attributes = font.getAttributes();
if (mapper != null) {
final String classAlias = mapper.aliasForSystemAttribute("class");
for (final Map.Entry<TextAttribute, ?> entry : attributes.entrySet()) {
final String name = textAttributeConverter.toString(entry.getKey());
final Object value = entry.getValue();
final Class<?> type = value != null ? value.getClass() : Mapper.Null.class;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type);
writer.addAttribute(classAlias, mapper.serializedClass(type));
if (value != null) {
context.convertAnother(value);
}
writer.endNode();
}
} else {
writer.startNode("attributes"); // <attributes>
context.convertAnother(attributes);
writer.endNode(); // </attributes>
}
}
示例4: ToAttributedValueConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* 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, final 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 (final NoSuchFieldException e) {
throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
}
valueField = field;
}
enumMapper = UseAttributeForEnumMapper.createEnumMapper(mapper);
}
示例5: XStream
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
private XStream(
final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
final ClassLoaderReference classLoader, final Mapper mapper,
final DefaultConverterLookup defaultConverterLookup) {
this(reflectionProvider, driver, classLoader, mapper, new ConverterLookup() {
@Override
public Converter lookupConverterForType(final Class<?> type) {
return defaultConverterLookup.lookupConverterForType(type);
}
}, new ConverterRegistry() {
@Override
public void registerConverter(final Converter converter, final int priority) {
defaultConverterLookup.registerConverter(converter, priority);
}
});
}
示例6: CGLIBEnhancedConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* @deprecated As of 1.4.5 use {@link #CGLIBEnhancedConverter(Mapper, ReflectionProvider, ClassLoaderReference)}
*/
@Deprecated
public CGLIBEnhancedConverter(
final Mapper mapper, final ReflectionProvider reflectionProvider, final ClassLoader classLoader) {
super(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), classLoader);
fieldCache = new HashMap<String, List<Field>>();
}
示例7: writeValueToImplicitCollection
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
private void writeValueToImplicitCollection(final Object value,
final Map<String, Collection<? super Object>> implicitCollections, final Object result,
final String implicitFieldName) {
Collection<? super Object> collection = implicitCollections.get(implicitFieldName);
if (collection == null) {
final Class<?> physicalFieldType = reflectionProvider.getFieldType(result, implicitFieldName, null);
if (physicalFieldType.isArray()) {
collection = new ArraysList(physicalFieldType);
} else {
final Class<?> fieldType = mapper.defaultImplementationOf(physicalFieldType);
if (!(Collection.class.isAssignableFrom(fieldType) || Map.class.isAssignableFrom(fieldType))) {
throw new ObjectAccessException("Field "
+ implicitFieldName
+ " of "
+ result.getClass().getName()
+ " is configured for an implicit Collection or Map, but field is of type "
+ fieldType.getName());
}
if (pureJavaReflectionProvider == null) {
pureJavaReflectionProvider = new PureJavaReflectionProvider();
}
final Object instance = pureJavaReflectionProvider.newInstance(fieldType);
if (instance instanceof Collection) {
@SuppressWarnings("unchecked")
final Collection<? super Object> uncheckedCollection = (Collection<? super Object>)instance;
collection = uncheckedCollection;
} else {
final Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper
.getImplicitCollectionDefForFieldName(result.getClass(), implicitFieldName);
@SuppressWarnings("unchecked")
final Map<Object, Object> map = (Map<Object, Object>)instance;
collection = new MappingList(map, implicitCollectionMapping.getKeyFieldName());
}
reflectionProvider.writeField(result, implicitFieldName, instance, null);
}
implicitCollections.put(implicitFieldName, collection);
}
collection.add(value);
}
示例8: readClassType
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
public static Class<?> readClassType(final HierarchicalStreamReader reader, final Mapper mapper) {
final String classAttribute = readClassAttribute(reader, mapper);
Class<?> type;
if (classAttribute == null) {
type = mapper.realClass(reader.getNodeName());
} else {
type = mapper.realClass(classAttribute);
}
return type;
}
示例9: CollectionConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* 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(final Mapper mapper, @SuppressWarnings("rawtypes") final Class<? extends Collection> type) {
super(mapper);
@SuppressWarnings("unchecked")
final Class<? extends Collection<?>> checkedType = (Class<? extends Collection<?>>)type;
this.type = checkedType;
if (type != null && !Collection.class.isAssignableFrom(type)) {
throw new IllegalArgumentException(type + " not of type " + Collection.class);
}
}
示例10: MapConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* Construct a MapConverter for a special Map type.
*
* @param mapper the mapper
* @param type the type to handle
* @since 1.4.5
*/
public MapConverter(final Mapper mapper, @SuppressWarnings("rawtypes") final Class<? extends Map> type) {
super(mapper);
@SuppressWarnings("unchecked")
final Class<? extends Map<?, ?>> checkedType = (Class<? extends Map<?, ?>>)type;
this.type = checkedType;
if (type != null && !Map.class.isAssignableFrom(type)) {
throw new IllegalArgumentException(type + " not of type " + Map.class);
}
}
示例11: JavaFieldConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* Construct a JavaFieldConverter. Depending on the mapper chain the converter will also respect aliases.
*
* @param javaClassConverter the converter to use
* @param mapper to use
* @since 1.4.5
*/
protected JavaFieldConverter(final SingleValueConverter javaClassConverter, final Mapper mapper) {
if (!javaClassConverter.canConvert(Class.class)) {
throw new InitializationException("Java Class Converter cannot handle Class types");
}
this.javaClassConverter = javaClassConverter;
this.mapper = mapper;
}
示例12: NamedArrayConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* 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;
}
示例13: FontConverter
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
/**
* Constructs a FontConverter.
*
* @param mapper
* @since 1.4.5
*/
public FontConverter(final Mapper mapper) {
this.mapper = mapper;
if (mapper == null) {
textAttributeConverter = null;
} else {
textAttributeConverter = new TextAttributeConverter();
}
}
示例14: writeItem
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
protected void writeItem(final String name, final Class<?> type, final Object item,
final MarshallingContext context, final HierarchicalStreamWriter writer) {
final Class<?> itemType = item == null ? Mapper.Null.class : item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
if (!itemType.equals(type)) {
final String attributeName = mapper().aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper().serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
示例15: readItem
import com.thoughtworks.xstream.mapper.Mapper; //导入依赖的package包/类
protected Object readItem(final Class<?> type, final HierarchicalStreamReader reader,
final UnmarshallingContext context, final Object current) {
final String className = HierarchicalStreams.readClassAttribute(reader, mapper());
final Class<?> itemType = className == null ? type : mapper().realClass(className);
if (Mapper.Null.class.equals(itemType)) {
return null;
} else {
return context.convertAnother(current, itemType);
}
}