本文整理汇总了Java中com.thoughtworks.xstream.converters.Converter类的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于com.thoughtworks.xstream.converters包,在下文中一共展示了Converter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractKey
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
/**
* Given a filename, the unescape method returns the key which originated it.
*
* @param name the filename
* @return the original key
*/
@Override
protected K extractKey(final String name) {
final String key = unescape(name.substring(0, name.length() - 4));
if ("[email protected]".equals(key)) {
return null;
}
final int idx = key.indexOf('@');
if (idx < 0) {
throw new StreamException("Not a valid key: " + key);
}
final Class<?> type = getMapper().realClass(key.substring(0, idx));
final Converter converter = getConverterLookup().lookupConverterForType(type);
if (converter instanceof SingleValueConverter) {
final SingleValueConverter svConverter = (SingleValueConverter)converter;
@SuppressWarnings("unchecked")
final K k = (K)svConverter.fromString(key.substring(idx + 1));
return k;
} else {
throw new StreamException("No SingleValueConverter for type " + type.getName() + " available");
}
}
示例2: XStream
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private XStream(
final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
final ClassLoaderReference classLoader, final Mapper mapper,
final DefaultConverterLookup defaultConverterLookup) {
this(reflectionProvider, driver, classLoader, mapper, new ConverterLookup() {
@Override
public Converter lookupConverterForType(final Class<?> type) {
return defaultConverterLookup.lookupConverterForType(type);
}
}, new ConverterRegistry() {
@Override
public void registerConverter(final Converter converter, final int priority) {
defaultConverterLookup.registerConverter(converter, priority);
}
});
}
示例3: 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());
}
}
}
}
}
示例4: getName
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
/**
* Given a key, the escape method returns the filename which shall be used.
*
* @param key the key
* @return the desired and escaped filename
*/
@Override
protected String getName(final Object key) {
if (key == null) {
return "[email protected]";
}
final Class<?> type = key.getClass();
final Converter converter = getConverterLookup().lookupConverterForType(type);
if (converter instanceof SingleValueConverter) {
final SingleValueConverter svConverter = (SingleValueConverter)converter;
return getMapper().serializedClass(type) + '@' + escape(svConverter.toString(key)) + ".xml";
} else {
final ConversionException exception = new ConversionException(
"No SingleValueConverter available for key type");
exception.add("key-type", type.getName());
throw exception;
}
}
示例5: 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());
}
}
}
}
}
示例6: loadConverter
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private static Converter[] loadConverter(ConverterScope cs)
{
Converter[] converters= new Converter[12];
converters[0]= new GamaBasicTypeConverter(cs);
converters[1]=new GamaAgentConverter(cs);
converters[2]=new GamaListConverter(cs);
converters[3]=new GamaMapConverter(cs);
converters[4]=new GamaPairConverter();
converters[5]=new GamaMatrixConverter(cs);
converters[6]=new GamaGraphConverter(cs);
converters[7]=new GamaFileConverter(cs);
converters[8]=new LogConverter();
converters[9]=new SavedAgentConverter(cs);
converters[10]= new GamaPopulationConverter(cs);
converters[11]= new GamaSpeciesConverter(cs);
//converters[12]= new ComplexMessageConverter(cs);
return converters;
}
示例7: loadConverterNetwork
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private static Converter[] loadConverterNetwork(ConverterScope cs)
{
Converter[] converters= new Converter[12];
converters[0]= new GamaBasicTypeConverter(cs);
converters[1]=new GamaAgentConverterNetwork(cs);
converters[2]=new GamaListConverter(cs);
converters[3]=new GamaMapConverter(cs);
converters[4]=new GamaPairConverter();
converters[5]=new GamaMatrixConverter(cs);
converters[6]=new GamaGraphConverter(cs);
converters[7]=new GamaFileConverter(cs);
converters[8]=new LogConverter();
converters[9]=new SavedAgentConverter(cs);
converters[10]= new GamaPopulationConverter(cs);
converters[11]= new GamaSpeciesConverter(cs);
//converters[12]= new ComplexMessageConverter(cs);
return converters;
}
示例8: getSingleValueConverter
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private SingleValueConverter getSingleValueConverter(Class paramClass)
{
SingleValueConverter localSingleValueConverter1;
if (UseAttributeForEnumMapper.isEnum(paramClass))
localSingleValueConverter1 = this.enumMapper.getConverterFromItemType(null, paramClass, null);
else
localSingleValueConverter1 = mapper().getConverterFromItemType(null, paramClass, null);
SingleValueConverter localSingleValueConverter2 = localSingleValueConverter1;
if (localSingleValueConverter1 == null)
{
Converter localConverter = this.lookup.lookupConverterForType(paramClass);
if ((localConverter instanceof SingleValueConverter))
return (SingleValueConverter)localConverter;
throw new ConversionException("No SingleValueConverter for key available");
}
return localSingleValueConverter2;
}
示例9: XStream
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private XStream(ReflectionProvider paramReflectionProvider, HierarchicalStreamDriver paramHierarchicalStreamDriver, ClassLoaderReference paramClassLoaderReference, Mapper paramMapper, DefaultConverterLookup paramDefaultConverterLookup)
{
this(paramReflectionProvider, paramHierarchicalStreamDriver, paramClassLoaderReference, paramMapper, new ConverterLookup()
{
public Converter lookupConverterForType(Class paramAnonymousClass)
{
return XStream.this.lookupConverterForType(paramAnonymousClass);
}
}
, new ConverterRegistry()
{
public void registerConverter(Converter paramAnonymousConverter, int paramAnonymousInt)
{
XStream.this.registerConverter(paramAnonymousConverter, paramAnonymousInt);
}
});
}
示例10: registerConverterDynamically
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private void registerConverterDynamically(String paramString, int paramInt, Class[] paramArrayOfClass, Object[] paramArrayOfObject)
{
try
{
Object localObject = Class.forName(paramString, false, this.classLoaderReference.getReference()).getConstructor(paramArrayOfClass).newInstance(paramArrayOfObject);
if ((localObject instanceof Converter))
{
registerConverter((Converter)localObject, paramInt);
return;
}
if ((localObject instanceof SingleValueConverter))
registerConverter((SingleValueConverter)localObject, paramInt);
return;
}
catch (Exception localException)
{
throw new InitializationException("Could not instantiate converter : " + paramString, localException);
}
}
示例11: newInstance
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
private Converter newInstance(Class<? extends ConverterMatcher> paramClass)
{
try
{
if (SingleValueConverter.class.isAssignableFrom(paramClass))
return new SingleValueConverterWrapper((SingleValueConverter)paramClass.getConstructor(new Class[0]).newInstance(new Object[0]));
Converter localConverter = (Converter)paramClass.getConstructor(new Class[0]).newInstance(new Object[0]);
return localConverter;
}
catch (InvocationTargetException localInvocationTargetException)
{
throw new ObjectAccessException("Cannot construct " + paramClass.getName(), localInvocationTargetException.getCause());
}
catch (InstantiationException localInstantiationException)
{
throw new ObjectAccessException("Cannot construct " + paramClass.getName(), localInstantiationException);
}
catch (IllegalAccessException localIllegalAccessException)
{
throw new ObjectAccessException("Cannot construct " + paramClass.getName(), localIllegalAccessException);
}
catch (NoSuchMethodException localNoSuchMethodException)
{
throw new ObjectAccessException("Cannot construct " + paramClass.getName(), localNoSuchMethodException);
}
}
示例12: 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);
}
示例13: convert
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
protected Object convert(Object paramObject, Class paramClass, Converter paramConverter)
{
try
{
this.types.push(paramClass);
Object localObject = paramConverter.unmarshal(this.reader, this);
this.types.popSilently();
return localObject;
}
catch (ConversionException localConversionException2)
{
addInformationTo(localConversionException2, paramClass, paramConverter, paramObject);
throw localConversionException2;
}
catch (RuntimeException localRuntimeException)
{
ConversionException localConversionException1 = new ConversionException(localRuntimeException);
addInformationTo(localConversionException1, paramClass, paramConverter, paramObject);
throw localConversionException1;
}
}
示例14: 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);
}
示例15: setup
import com.thoughtworks.xstream.converters.Converter; //导入依赖的package包/类
@Override
@Before
public void setup() throws Exception {
stream = new ByteArrayOutputStream();
environment = mock(Environment.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(new PrintWriter(stream));
List<Converter> converters = new ArrayList<>();
converters.add(new CalendarConverter());
final DefaultTypeNameExtractor extractor = new DefaultTypeNameExtractor();
Instance<Converter> convertersInst = new MockInstanceImpl<>(converters);
Instance<SingleValueConverter> singleValueConverters = new MockInstanceImpl<>();
XStreamConverters xStreamConverters = new XStreamConverters(convertersInst, singleValueConverters);
serialization = new XStreamXMLSerialization(response, new XStreamBuilderImpl(xStreamConverters, extractor,
new Serializee(new DefaultReflectionProvider()), new DefaultReflectionProvider()), environment);
}