當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。