本文整理汇总了Java中com.thoughtworks.xstream.converters.Converter.canConvert方法的典型用法代码示例。如果您正苦于以下问题:Java Converter.canConvert方法的具体用法?Java Converter.canConvert怎么用?Java Converter.canConvert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thoughtworks.xstream.converters.Converter
的用法示例。
在下文中一共展示了Converter.canConvert方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processConverterAnnotations
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
private void processConverterAnnotations(final Class<?> type) {
if (converterRegistry != null) {
final XStreamConverters convertersAnnotation = type.getAnnotation(XStreamConverters.class);
final XStreamConverter converterAnnotation = type.getAnnotation(XStreamConverter.class);
final List<XStreamConverter> annotations = convertersAnnotation != null ? new ArrayList<XStreamConverter>(
Arrays.asList(convertersAnnotation.value())) : new ArrayList<XStreamConverter>();
if (converterAnnotation != null) {
annotations.add(converterAnnotation);
}
for (final XStreamConverter annotation : annotations) {
final Converter converter = cacheConverter(annotation, converterAnnotation != null ? type : null);
if (converter != null) {
if (converterAnnotation != null || converter.canConvert(type)) {
converterRegistry.registerConverter(converter, annotation.priority());
} else {
throw new InitializationException("Converter "
+ annotation.value().getName()
+ " cannot handle annotated class "
+ type.getName());
}
}
}
}
}
示例2: processConverterAnnotations
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
private void processConverterAnnotations(final Class<?> type) {
if (converterRegistry != null) {
final XStreamConverters convertersAnnotation = type.getAnnotation(XStreamConverters.class);
final XStreamConverter converterAnnotation = type.getAnnotation(XStreamConverter.class);
final List<XStreamConverter> annotations = convertersAnnotation != null
? new ArrayList<XStreamConverter>(Arrays.asList(convertersAnnotation.value()))
: new ArrayList<XStreamConverter>();
if (converterAnnotation != null) {
annotations.add(converterAnnotation);
}
for (final XStreamConverter annotation : annotations) {
final Converter converter = cacheConverter(annotation, converterAnnotation != null ? type : null);
if (converter != null) {
if (converterAnnotation != null || converter.canConvert(type)) {
converterRegistry.registerConverter(converter, annotation.priority());
} else {
throw new InitializationException("Converter "
+ annotation.value().getName()
+ " cannot handle annotated class "
+ type.getName());
}
}
}
}
}
示例3: lookupConverterForType
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
public Converter lookupConverterForType(Class paramClass)
{
Converter localConverter1 = (Converter)this.typeToConverterMap.get(paramClass);
if (localConverter1 != null)
return localConverter1;
Iterator localIterator = this.converters.iterator();
while (localIterator.hasNext())
{
Converter localConverter2 = (Converter)localIterator.next();
if (localConverter2.canConvert(paramClass))
{
this.typeToConverterMap.put(paramClass, localConverter2);
return localConverter2;
}
}
throw new ConversionException("No converter specified for " + paramClass);
}
示例4: convertAnother
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
public Object convertAnother(Object paramObject, Class paramClass, Converter paramConverter)
{
Class localClass = this.mapper.defaultImplementationOf(paramClass);
if (paramConverter == null)
{
paramConverter = this.converterLookup.lookupConverterForType(localClass);
}
else if (!paramConverter.canConvert(localClass))
{
ConversionException localConversionException = new ConversionException("Explicit selected converter cannot handle type");
localConversionException.add("item-type", localClass.getName());
localConversionException.add("converter-type", paramConverter.getClass().getName());
throw localConversionException;
}
return convert(paramObject, localClass, paramConverter);
}
示例5: lookupConverterForType
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
@Override
public Converter lookupConverterForType(final Class<?> type) {
final Converter cachedConverter = typeToConverterMap.get(type);
if (cachedConverter != null) {
return cachedConverter;
}
for (final Converter converter : converters) {
if (converter.canConvert(type)) {
return converter;
}
}
throw new ConversionException("No converter specified for " + type);
}
示例6: registerConverter
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
@Override
public void registerConverter(final Converter converter, final int priority) {
converters.add(converter, priority);
for (final Iterator<Class<?>> iter = typeToConverterMap.keySet().iterator(); iter.hasNext();) {
final Class<?> type = iter.next();
if (converter.canConvert(type)) {
iter.remove();
}
}
}
示例7: convertAnother
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
@Override
public Object convertAnother(final Object parent, Class<?> type, Converter converter) {
type = mapper.defaultImplementationOf(type);
if (converter == null) {
converter = converterLookup.lookupConverterForType(type);
} else {
if (!converter.canConvert(type)) {
final ConversionException e = new ConversionException("Explicit selected converter cannot handle type");
e.add("item-type", type.getName());
e.add("converter-type", converter.getClass().getName());
throw e;
}
}
return convert(parent, type, converter);
}
示例8: convertAnother
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
@Override
public void convertAnother(final Object item, Converter converter) {
if (converter == null) {
converter = converterLookup.lookupConverterForType(item.getClass());
} else {
if (!converter.canConvert(item.getClass())) {
final ConversionException e = new ConversionException("Explicit selected converter cannot handle item");
e.add("item-type", item.getClass().getName());
e.add("converter-type", converter.getClass().getName());
throw e;
}
}
convert(item, converter);
}
示例9: lookupConverterForType
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
@Override
public Converter lookupConverterForType(final Class<?> type) {
final Converter cachedConverter = type != null ? typeToConverterMap.get(type.getName()) : null;
if (cachedConverter != null) {
return cachedConverter;
}
final Map<String, String> errors = new LinkedHashMap<>();
for (final Converter converter : converters) {
try {
if (converter.canConvert(type)) {
if (type != null) {
typeToConverterMap.put(type.getName(), converter);
}
return converter;
}
} catch (final RuntimeException | LinkageError e) {
errors.put(converter.getClass().getName(), e.getMessage());
}
}
final ConversionException exception = new ConversionException(errors.isEmpty()
? "No converter specified"
: "No converter available");
exception.add("type", type.getName());
for (final Map.Entry<String, String> entry : errors.entrySet()) {
exception.add("converter", entry.getKey());
exception.add("message", entry.getValue());
}
throw exception;
}
示例10: processConverterAnnotations
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
private void processConverterAnnotations(Class<?> paramClass)
{
if (this.converterRegistry != null)
{
XStreamConverters localXStreamConverters = (XStreamConverters)paramClass.getAnnotation(XStreamConverters.class);
XStreamConverter localXStreamConverter1 = (XStreamConverter)paramClass.getAnnotation(XStreamConverter.class);
ArrayList localArrayList1;
if (localXStreamConverters != null)
localArrayList1 = new ArrayList(Arrays.asList(localXStreamConverters.value()));
else
localArrayList1 = new ArrayList();
ArrayList localArrayList2 = localArrayList1;
if (localXStreamConverter1 != null)
localArrayList2.add(localXStreamConverter1);
Iterator localIterator = localArrayList2.iterator();
while (localIterator.hasNext())
{
XStreamConverter localXStreamConverter2 = (XStreamConverter)localIterator.next();
Class<?> localClass;
if (localXStreamConverter1 != null)
localClass = paramClass;
else
localClass = null;
Converter localConverter = cacheConverter(localXStreamConverter2, localClass);
if (localConverter != null)
if ((localXStreamConverter1 != null) || (localConverter.canConvert(paramClass)))
this.converterRegistry.registerConverter(localConverter, localXStreamConverter2.priority());
else
throw new InitializationException("Converter " + localXStreamConverter2.value().getName() + " cannot handle annotated class " + paramClass.getName());
}
}
}
示例11: registerConverter
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
public void registerConverter(Converter paramConverter, int paramInt)
{
this.converters.add(paramConverter, paramInt);
Iterator localIterator = this.typeToConverterMap.keySet().iterator();
while (localIterator.hasNext())
if (paramConverter.canConvert((Class)localIterator.next()))
localIterator.remove();
}
示例12: convertAnother
import com.thoughtworks.xstream.converters.Converter; //导入方法依赖的package包/类
public void convertAnother(Object paramObject, Converter paramConverter)
{
if (paramConverter == null)
{
paramConverter = this.converterLookup.lookupConverterForType(paramObject.getClass());
}
else if (!paramConverter.canConvert(paramObject.getClass()))
{
ConversionException localConversionException = new ConversionException("Explicit selected converter cannot handle item");
localConversionException.add("item-type", paramObject.getClass().getName());
localConversionException.add("converter-type", paramConverter.getClass().getName());
throw localConversionException;
}
convert(paramObject, paramConverter);
}