当前位置: 首页>>代码示例>>Java>>正文


Java SingleValueConverter类代码示例

本文整理汇总了Java中com.thoughtworks.xstream.converters.SingleValueConverter的典型用法代码示例。如果您正苦于以下问题:Java SingleValueConverter类的具体用法?Java SingleValueConverter怎么用?Java SingleValueConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SingleValueConverter类属于com.thoughtworks.xstream.converters包,在下文中一共展示了SingleValueConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractKey

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:FilePersistenceStrategy.java

示例2: getLocalConverter

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
private SingleValueConverter getLocalConverter(final String fieldName, final Class<?> type, final Class<?> definedIn) {
    if (attributeMapper != null
        && Enum.class.isAssignableFrom(type)
        && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) {
        synchronized (enumConverterMap) {
            SingleValueConverter singleValueConverter = enumConverterMap.get(type);
            if (singleValueConverter == null) {
                singleValueConverter = super.getConverterFromItemType(fieldName, type, definedIn);
                if (singleValueConverter == null) {
                    @SuppressWarnings("unchecked")
                    final Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>)type;
                    @SuppressWarnings({"rawtypes", "unchecked"})
                    final EnumSingleValueConverter<?> enumConverter = new EnumSingleValueConverter(enumType);
                    singleValueConverter = enumConverter;
                }
                enumConverterMap.put(type, singleValueConverter);
            }
            return singleValueConverter;
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:EnumMapper.java

示例3: getName

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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;
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:24,代码来源:FilePersistenceStrategy.java

示例4: ISO8601GregorianCalendarConverter

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
public ISO8601GregorianCalendarConverter() {
    SingleValueConverter svConverter = null;
    final Class<? extends SingleValueConverter> type = JVM.<SingleValueConverter>loadClassForName(JVM.is18()
        ? "com.thoughtworks.xstream.core.util.ISO8601JavaTimeConverter"
        : "com.thoughtworks.xstream.core.util.ISO8601JodaTimeConverter");
    try {
        svConverter = type.getDeclaredConstructor().newInstance();
    } catch (final
            InstantiationException
            | IllegalAccessException
            | IllegalArgumentException
            | InvocationTargetException
            | NoSuchMethodException
            | SecurityException e) {
        // ignore
    }
    converter = svConverter;
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:19,代码来源:ISO8601GregorianCalendarConverter.java

示例5: getLocalConverter

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
private SingleValueConverter getLocalConverter(final String fieldName, final Class<?> type, final Class<?> definedIn) {
    if (attributeMapper != null
            && Enum.class.isAssignableFrom(type)
            && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) {
        synchronized (enumConverterMap) {
            SingleValueConverter singleValueConverter = enumConverterMap.get(type);
            if (singleValueConverter == null) {
                singleValueConverter = super.getConverterFromItemType(fieldName, type, definedIn);
                if (singleValueConverter == null) {
                    @SuppressWarnings("unchecked")
                    final Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>)type;
                    @SuppressWarnings({"rawtypes", "unchecked"})
                    final EnumSingleValueConverter<?> enumConverter = new EnumSingleValueConverter(enumType);
                    singleValueConverter = enumConverter;
                }
                enumConverterMap.put(type, singleValueConverter);
            }
            return singleValueConverter;
        }
    }
    return null;
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:23,代码来源:EnumMapper.java

示例6: getSingleValueConverter

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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;
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:18,代码来源:NamedMapConverter.java

示例7: registerConverterDynamically

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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);
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:20,代码来源:XStream.java

示例8: newInstance

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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);
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:27,代码来源:AnnotationReflectionConverter.java

示例9: createXStream

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
private static XStream createXStream() {
    final XStream xStream = new XStream();
    xStream.alias("magicWandSettings", MagicWandModel.class);
    xStream.registerConverter(new SingleValueConverter() {
        @Override
        public boolean canConvert(Class type) {
            return type.equals(double[].class);
        }

        @Override
        public String toString(Object obj) {
            return StringUtils.arrayToString(obj, ",");
        }

        @Override
        public Object fromString(String str) {
            return StringUtils.toDoubleArray(str, ",");
        }
    });
    return xStream;
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:22,代码来源:MagicWandModel.java

示例10: createXStream

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
public static XStream createXStream() {
    final XStream xStream = new XStream();
    xStream.setClassLoader(Filter.class.getClassLoader());
    xStream.alias("filter", Filter.class);
    xStream.registerLocalConverter(Filter.class, "kernelElements", new SingleValueConverter() {
        @Override
        public String toString(Object o) {
            double[] o1 = (double[]) o;
            // todo - find out how to obtain width, height
            return Filter.formatKernelElements(o1, new Dimension(o1.length, 1), ",");
        }

        @Override
        public Object fromString(String s) {
            return Filter.parseKernelElementsFromText(s, null);
        }

        @Override
        public boolean canConvert(Class aClass) {
            return aClass.equals(double[].class);
        }
    });
    return xStream;
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:25,代码来源:Filter.java

示例11: setup

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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);
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:21,代码来源:XStreamSerializerTest.java

示例12: getName

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的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 {
        throw new StreamException("No SingleValueConverter for type " + type.getName() + " available");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:FilePersistenceStrategy.java

示例13: JavaFieldConverter

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
/**
 * Construct a JavaFieldConverter. Depending on the mapper chain the converter will also respect aliases.
 * 
 * @param javaClassConverter the converter to use
 * @param mapper to use
 * @since 1.4.5
 */
protected JavaFieldConverter(final SingleValueConverter javaClassConverter, final Mapper mapper) {
    if (!javaClassConverter.canConvert(Class.class)) {
        throw new InitializationException("Java Class Converter cannot handle Class types");
    }
    this.javaClassConverter = javaClassConverter;
    this.mapper = mapper;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:JavaFieldConverter.java

示例14: JavaMethodConverter

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
/**
 * Construct a JavaMethodConverter.
 * 
 * @param javaClassConverter the converter to use
 * @since 1.4.5
 */
protected JavaMethodConverter(final SingleValueConverter javaClassConverter) {
    if (!javaClassConverter.canConvert(Class.class)) {
        throw new InitializationException("Java Class Converter cannot handle Class types");
    }
    this.javaClassConverter = javaClassConverter;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:JavaMethodConverter.java

示例15: getLocalConverterFromItemType

import com.thoughtworks.xstream.converters.SingleValueConverter; //导入依赖的package包/类
private SingleValueConverter getLocalConverterFromItemType(final Class<?> type) {
    final Converter converter = converterLookup.lookupConverterForType(type);
    if (converter != null && converter instanceof SingleValueConverter) {
        return (SingleValueConverter)converter;
    } else {
        return null;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AttributeMapper.java


注:本文中的com.thoughtworks.xstream.converters.SingleValueConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。