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


Java HierarchicalStreamDriver类代码示例

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


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

示例1: XStream

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

示例2: fromXML

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
/**
 * Deserialize a self-contained XStream with object from an XML Reader.
 * 
 * @param driver the implementation to use
 * @param xml the {@link Reader} providing the XML data
 * @param permissions the permissions to use (ensure that they include the defaults)
 * @throws IOException if an error occurs reading from the Reader.
 * @throws ClassNotFoundException if a class in the XML stream cannot be found
 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
 * @since 1.4.7
 */
public <T> T fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission... permissions)
        throws IOException, ClassNotFoundException {
    final XStream outer = new XStream(driver);
    for (final TypePermission permission : permissions) {
        outer.addPermission(permission);
    }
    final HierarchicalStreamReader reader = driver.createReader(xml);
    final ObjectInputStream configIn = outer.createObjectInputStream(reader);
    try {
        final XStream configured = (XStream)configIn.readObject();
        final ObjectInputStream in = configured.createObjectInputStream(reader);
        try {
            @SuppressWarnings("unchecked")
            final T t = (T)in.readObject();
            return t;
        } finally {
            in.close();
        }
    } finally {
        configIn.close();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:XStreamer.java

示例3: fromJson

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
/**
 * parse json
 * <p>
 * 
 * @param clazz
 *            the class
 * @param original
 *            original text
 * @return the class
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
protected <T> T fromJson(Class<T> clazz, String original) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    HierarchicalStreamDriver hierarchicalStreamDriver = new JettisonMappedXmlDriver();

    XStream xStream = generateXStream(hierarchicalStreamDriver);

    Field rootField = clazz.getField("XSTREAM_ROOT");
    boolean root = (Boolean) rootField.get(null);
    if (root) {
        original = "{\"" + ROOT + "\":" + original + "}";
        xStream.alias(ROOT, clazz);
    }
    else {
        Field aliasField = clazz.getField("XSTREAM_ALIAS");
        xStream.alias(String.valueOf(aliasField.get(null)), clazz);
    }

    return (T) xStream.fromXML(original);
}
 
开发者ID:owen-chen,项目名称:crawl-center,代码行数:33,代码来源:BaseParser.java

示例4: generateXStream

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
/**
 * {@link XStream} generator
 * <p>
 * 
 * @param hierarchicalStreamDriver
 *            {@link HierarchicalStreamDriver}
 * @return {@link XStream}
 */
private XStream generateXStream(HierarchicalStreamDriver hierarchicalStreamDriver) {
    XStream xStream = new XStream(hierarchicalStreamDriver) {
        @Override
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return new MapperWrapper(next) {
                @Override
                // avoid {@link XStream} crash when field misses
                public boolean shouldSerializeMember(Class definedIn, String fieldName) {
                    try {
                        return definedIn != Object.class || realClass(fieldName) != null;
                    }
                    catch (CannotResolveClassException cnrce) {
                        return false;
                    }
                }
            };
        }
    };
    xStream.autodetectAnnotations(true);

    return xStream;
}
 
开发者ID:owen-chen,项目名称:crawl-center,代码行数:31,代码来源:BaseParser.java

示例5: fromXML

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
/**
 * Deserialize a self-contained XStream with object from an XML Reader.
 *
 * @param driver the implementation to use
 * @param xml the {@link Reader} providing the XML data
 * @param permissions the permissions to use (ensure that they include the defaults)
 * @throws IOException if an error occurs reading from the Reader.
 * @throws ClassNotFoundException if a class in the XML stream cannot be found
 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
 * @since 1.4.7
 */
public <T> T fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission... permissions)
        throws IOException, ClassNotFoundException {
    final XStream outer = new XStream(driver);
    for (final TypePermission permission : permissions) {
        outer.addPermission(permission);
    }
    final HierarchicalStreamReader reader = driver.createReader(xml);
    final ObjectInputStream configIn = outer.createObjectInputStream(reader);
    try {
        final XStream configured = (XStream)configIn.readObject();
        final ObjectInputStream in = configured.createObjectInputStream(reader);
        try {
            @SuppressWarnings("unchecked")
            final T t = (T)in.readObject();
            return t;
        } finally {
            in.close();
        }
    } finally {
        configIn.close();
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:34,代码来源:XStreamer.java

示例6: createDriver

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
protected HierarchicalStreamDriver createDriver() {
    // if the system property is set, use it to load the driver
    String driver = null;
    try {
        driver = System.getProperty("xstream.driver");
        if (driver != null) {
            System.out.println("Using driver: " + driver);
            Class type = Class.forName(driver);
            return (HierarchicalStreamDriver) type.newInstance();
        }
    }
    catch (Exception e) {
        throw new RuntimeException("Could not load driver: " + driver);
    }
    return new XppDriver();
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:17,代码来源:AbstractBuilderAcceptanceTest.java

示例7: XStream

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
public XStream(ReflectionProvider paramReflectionProvider, HierarchicalStreamDriver paramHierarchicalStreamDriver, ClassLoaderReference paramClassLoaderReference, Mapper paramMapper, ConverterLookup paramConverterLookup, ConverterRegistry paramConverterRegistry)
{
  if (paramReflectionProvider == null)
    paramReflectionProvider = JVM.newReflectionProvider();
  this.reflectionProvider = paramReflectionProvider;
  this.hierarchicalStreamDriver = paramHierarchicalStreamDriver;
  this.classLoaderReference = paramClassLoaderReference;
  this.converterLookup = paramConverterLookup;
  this.converterRegistry = paramConverterRegistry;
  Mapper localMapper;
  if (paramMapper == null)
    localMapper = buildMapper();
  else
    localMapper = paramMapper;
  this.mapper = localMapper;
  setupMappers();
  setupSecurity();
  setupAliases();
  setupDefaultImplementations();
  setupConverters();
  setupImmutableTypes();
  setMode(1003);
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:24,代码来源:XStream.java

示例8: fromXML

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
public Object fromXML(HierarchicalStreamDriver paramHierarchicalStreamDriver, Reader paramReader, TypePermission[] paramArrayOfTypePermission)
{
  XStream localXStream = new XStream(paramHierarchicalStreamDriver);
  for (int i = 0; i < paramArrayOfTypePermission.length; i++)
    localXStream.addPermission(paramArrayOfTypePermission[i]);
  HierarchicalStreamReader localHierarchicalStreamReader = paramHierarchicalStreamDriver.createReader(paramReader);
  ObjectInputStream localObjectInputStream1 = localXStream.createObjectInputStream(localHierarchicalStreamReader);
  try
  {
    ObjectInputStream localObjectInputStream2 = ((XStream)localObjectInputStream1.readObject()).createObjectInputStream(localHierarchicalStreamReader);
    try
    {
      Object localObject3 = localObjectInputStream2.readObject();
      return localObject3;
    }
    finally
    {
    }
  }
  finally
  {
    localObjectInputStream1.close();
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:25,代码来源:XStreamer.java

示例9: XStream

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
public XStream(ReflectionProvider reflectionProvider,
			ClassMapper classMapper, HierarchicalStreamDriver driver,
			String classAttributeIdentifier) {
		jvm = new JVM();
		if (reflectionProvider == null) {
			reflectionProvider = jvm.bestReflectionProvider();
		}
		this.reflectionProvider = reflectionProvider;
		this.hierarchicalStreamDriver = driver;
		//this.classLoaderReference = new ClassLoaderReference(
		//		new CompositeClassLoader());	// サーブレットで実行するとメモリが増えてしまう
		this.classLoaderReference = new ClassLoaderReference(
				getClass().getClassLoader());
		this.classMapper = classMapper == null ? buildMapper(classAttributeIdentifier)
				: classMapper;
		converterLookup = new DefaultConverterLookup(this.classMapper);
		setupAliases();
		setupDefaultImplementations();
		setupConverters();
		setupImmutableTypes();
//		setMode(XPATH_REFERENCES);
		setMode(NO_REFERENCES);
	}
 
开发者ID:reflexworks,项目名称:reflexcore,代码行数:24,代码来源:XStream.java

示例10: CubaXStream

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
protected CubaXStream(
        ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
        Mapper mapper, final CubaXStreamConverterLookup converterLookup) {
    super(reflectionProvider, driver, classLoader, mapper,
            converterLookup::lookupConverterForType,
            converterLookup::registerConverter);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:8,代码来源:CubaXStream.java

示例11: XMLConfigurer

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
/**
 * creates an XMLConfigurer instance backed by a new XStream instance
 * using the com.thoughtworks.xstream.io.xml.StaxDriver for XML parsing
 * if the StAX API is available
 *
 * @see com.thoughtworks.xstream.io.xml.StaxDriver
 */
public XMLConfigurer() {
    final HierarchicalStreamDriver xmlDriver = //
            ReflectionUtils.isClassPresent("javax.xml.stream.XMLStreamReader") ? new StaxDriver() : //
                    ReflectionUtils.isClassPresent("org.xmlpull.mxp1.MXParser") ? new XppDriver() : //
                            new DomDriver();
    LOG.info("XML driver implementation: {1}", xmlDriver.getClass().getName());
    xStream = new XStream(new XStreamReflectionProvider(), xmlDriver);
    configureXStream();
}
 
开发者ID:sebthom,项目名称:oval,代码行数:17,代码来源:XMLConfigurer.java

示例12: createDriver

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
protected HierarchicalStreamDriver createDriver() {
    // careful, called from inside base class constructor
    qnameMap = new QNameMap();
    StaxDriver driver = new BEAStaxDriver(qnameMap);
    driver.setRepairingNamespace(false);
    return driver;
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:8,代码来源:QNameMappedConcreteClassesTest.java

示例13: createDriver

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
protected HierarchicalStreamDriver createDriver() {
    // if the system property is set, use it to load the driver
    String driver = null;
    try {
        driver = System.getProperty("xstream.driver");
        if (driver != null) {
            System.out.println("Using driver: " + driver);
            final Class<?> type = Class.forName(driver);
            return (HierarchicalStreamDriver)type.newInstance();
        }
    } catch (final Exception e) {
        throw new RuntimeException("Could not load driver: " + driver, e);
    }
    return new XppDriver();
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:16,代码来源:AbstractAcceptanceTest.java

示例14: test

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
private void test(final HierarchicalStreamDriver driver, final String encoding) throws IOException {
    final String headerLine = encoding != null ? "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n" : "";
    final String xmlData = headerLine // force code format
        + "<test>\n"
        + "  <data>J\u00f6rg</data>\n"
        + "</test>";

    final XStream xstream = new XStream(driver);
    xstream.allowTypes(TestObject.class);
    xstream.alias("test", TestObject.class);
    final TestObject obj = new TestObject();
    obj.data = "J\u00f6rg";

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final OutputStreamWriter writer = encoding != null
        ? new OutputStreamWriter(bos, encoding)
        : new OutputStreamWriter(bos);
    xstream.toXML(obj, writer);
    writer.close();

    final String generated = encoding != null ? bos.toString(encoding) : bos.toString();
    Assert.assertTrue("'" + obj.data + "' was not found", generated.indexOf(obj.data) > 0);

    final Object restored = xstream.fromXML(new ByteArrayInputStream(encoding != null
        ? xmlData.getBytes(encoding)
        : xmlData.getBytes()));
    Assert.assertEquals(obj, restored);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:29,代码来源:EncodingTestSuite.java

示例15: XStreamDriver

import com.thoughtworks.xstream.io.HierarchicalStreamDriver; //导入依赖的package包/类
/**
 * Create a XStream product based on a driver.
 * 
 * @param driver the driver to use for serialization/deserialization 
 * @param desc the driver description
 * 
 * @since 1.4
 */
public XStreamDriver(HierarchicalStreamDriver driver, String desc) {
    this.xstream = new XStream(driver);
    this.xstream.registerConverter(new JavaBeanConverter(this.xstream.getMapper()) {

        public boolean canConvert(Class type) {
            return type == OneBean.class || type == FiveBean.class;
        }
        
    });
    this.desc = desc;
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:20,代码来源:XStreamDriver.java


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