本文整理匯總了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;
}
}