当前位置: 首页>>代码示例>>Java>>正文


Java UnmarshallingContext.getRequiredType方法代码示例

本文整理汇总了Java中com.thoughtworks.xstream.converters.UnmarshallingContext.getRequiredType方法的典型用法代码示例。如果您正苦于以下问题:Java UnmarshallingContext.getRequiredType方法的具体用法?Java UnmarshallingContext.getRequiredType怎么用?Java UnmarshallingContext.getRequiredType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.thoughtworks.xstream.converters.UnmarshallingContext的用法示例。


在下文中一共展示了UnmarshallingContext.getRequiredType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unmarshal

import com.thoughtworks.xstream.converters.UnmarshallingContext; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context)
{
	Class<? extends IdCloneable> idClass = context.getRequiredType();
	IdCloneable newIdType;
	try
	{
		newIdType = idClass.newInstance();
		reader.moveDown();
		String value = reader.getValue();
		newIdType.setId(Long.parseLong(value));
		reader.moveUp();
		return newIdType;
	}
	catch( Exception e )
	{
		throw Throwables.propagate(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:IdOnlyConverter.java

示例2: unmarshal

import com.thoughtworks.xstream.converters.UnmarshallingContext; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    Class<?> type = context.getRequiredType();
    if (type.getSuperclass() != Enum.class) {
        type = type.getSuperclass(); // polymorphic enums
    }
    final String name = reader.getValue();
    try {
        @SuppressWarnings("rawtypes")
        final Class rawType = type;
        @SuppressWarnings("unchecked")
        final Enum<?> enumValue = Enum.valueOf(rawType, name);
        return enumValue;
    } catch (final IllegalArgumentException e) {
        // failed to find it, do a case insensitive match
        for (final Enum<?> c : (Enum<?>[])type.getEnumConstants()) {
            if (c.name().equalsIgnoreCase(name)) {
                return c;
            }
        }
        // all else failed
        throw e;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:EnumConverter.java

示例3: unmarshal

import com.thoughtworks.xstream.converters.UnmarshallingContext; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final Class<?> collectionType = context.getRequiredType();
    final Collection<?> collection = createCollection(collectionType);
    populateCollection(reader, context, collection);
    return collection;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:CollectionConverter.java

示例4: unmarshal

import com.thoughtworks.xstream.converters.UnmarshallingContext; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final Class<?> requiredType = context.getRequiredType();
    final Map<?, ?> map = createCollection(requiredType);
    populateMap(reader, context, map);
    return map;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:MapConverter.java

示例5: unmarshal

import com.thoughtworks.xstream.converters.UnmarshallingContext; //导入方法依赖的package包/类
@Override
public Collection<?> unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    reader.moveDown();
    final Object item = readItem(reader, context, null);
    reader.moveUp();
    return context.getRequiredType() == LIST ? Collections.singletonList(item) : Collections.singleton(item);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:SingletonCollectionConverter.java

示例6: unmarshal

import com.thoughtworks.xstream.converters.UnmarshallingContext; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final Map<TextAttribute, Object> attributes;
    if (reader.hasMoreChildren()) {
        reader.moveDown();
        if (!reader.getNodeName().equals("attributes")) {
            final String classAlias = mapper.aliasForSystemAttribute("class");
            attributes = new HashMap<TextAttribute, Object>();
            do {
                if (!attributes.isEmpty()) {
                    reader.moveDown();
                }
                final Class<?> type = mapper.realClass(reader.getAttribute(classAlias));
                final TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader.getNodeName());
                final Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type);
                attributes.put(attribute, value);
                reader.moveUp();
            } while (reader.hasMoreChildren());
        } else {
            // in <attributes>
            @SuppressWarnings("unchecked")
            final Map<TextAttribute, Object> typedAttributes = (Map<TextAttribute, Object>)context.convertAnother(
                null, Map.class);
            attributes = typedAttributes;
            reader.moveUp(); // out of </attributes>
        }
    } else {
        attributes = Collections.emptyMap();
    }
    for (final Iterator<?> iter = attributes.values().iterator(); iter.hasNext();) {
        if (iter.next() == null) {
            iter.remove();
        }
    }
    final Font font = Font.getFont(attributes);
    if (context.getRequiredType() == FontUIResource.class) {
        return new FontUIResource(font);
    } else {
        return font;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:FontConverter.java


注:本文中的com.thoughtworks.xstream.converters.UnmarshallingContext.getRequiredType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。