本文整理汇总了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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}