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


Java XStream.allowTypes方法代码示例

本文整理汇总了Java中com.thoughtworks.xstream.XStream.allowTypes方法的典型用法代码示例。如果您正苦于以下问题:Java XStream.allowTypes方法的具体用法?Java XStream.allowTypes怎么用?Java XStream.allowTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.thoughtworks.xstream.XStream的用法示例。


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

示例1: loadArgs

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
private static List<ByteChameleon> loadArgs(String agentArguments) {
	XStream xStream = new XStream();

	Class<?>[] classes = new Class[] { ByteChameleon.class, Clazz.class, Method.class };
	XStream.setupDefaultSecurity(xStream);
	xStream.allowTypes(classes);

	xStream.processAnnotations(ByteChameleon.class);

	String[] files = agentArguments.split(",");
	List<ByteChameleon> list = new ArrayList<ByteChameleon>();

	for (String file : files) {
		list.add((ByteChameleon) xStream.fromXML(new File(file.replace(" ", ""))));
	}

	return list;
}
 
开发者ID:remartins,项目名称:byte-chameleon,代码行数:19,代码来源:Agent.java

示例2: readXml

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
@Test
public void readXml() {
	XStream xStream = new XStream();
	
	Class<?>[] classes = new Class[] { ByteChameleon.class, Clazz.class, Method.class };
	XStream.setupDefaultSecurity(xStream);
	xStream.allowTypes(classes);
	xStream.processAnnotations(ByteChameleon.class);
	
	ByteChameleon byteChameleon = (ByteChameleon) xStream
			.fromXML(new File(AgentTest.class.getResource("/byte-chameleon.xml").getPath()));
	
	String[] result = new String[6];
	result[1] = "com.github.remartins.bytechameleon.Process";
	result[2] = "- replace : process";
	result[3] = "- replace : sum";
	result[4] = "- before : sum";
	result[5] = "- after : process";
	
	
	String[] real = byteChameleon.toString().split("\n");
	
	for (int i = 1; i < real.length; i++) {
		assertTrue(real[i].equals(result[i]));
	}
}
 
开发者ID:remartins,项目名称:byte-chameleon,代码行数:27,代码来源:XStreamTest.java

示例3: initXStream

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
protected void initXStream() {

        _xStream = new XStream(null, new XppDriver(), new ClassLoaderReference(
                XStreamConfiguratorRegistryUtil.getConfiguratorsClassLoader(XStream.class.getClassLoader())));

        _xStream.omitField(HashMap.class, "cache_bitmask");

        Set<XStreamConfigurator> xStreamConfigurators = XStreamConfiguratorRegistryUtil.getXStreamConfigurators();

        if (SetUtil.isEmpty(xStreamConfigurators)) {
            return;
        }

        List<String> allowedTypeNames = new ArrayList<>();

        for (XStreamConfigurator xStreamConfigurator : xStreamConfigurators) {
            List<XStreamAlias> xStreamAliases = xStreamConfigurator.getXStreamAliases();

            if (ListUtil.isNotEmpty(xStreamAliases)) {
                for (XStreamAlias xStreamAlias : xStreamAliases) {
                    _xStream.alias(xStreamAlias.getName(), xStreamAlias.getClazz());
                }
            }

            List<XStreamConverter> xStreamConverters = xStreamConfigurator.getXStreamConverters();

            if (ListUtil.isNotEmpty(xStreamConverters)) {
                for (XStreamConverter xStreamConverter : xStreamConverters) {
                    _xStream.registerConverter(new ConverterAdapter(xStreamConverter), XStream.PRIORITY_VERY_HIGH);
                }
            }

            List<XStreamType> xStreamTypes = xStreamConfigurator.getAllowedXStreamTypes();

            if (ListUtil.isNotEmpty(xStreamTypes)) {
                for (XStreamType xStreamType : xStreamTypes) {
                    allowedTypeNames.add(xStreamType.getTypeExpression());
                }
            }
        }

        // For default permissions, first wipe than add default

        _xStream.addPermission(NoTypePermission.NONE);

        // Add permissions

        _xStream.addPermission(PrimitiveTypePermission.PRIMITIVES);
        _xStream.addPermission(XStreamStagedModelTypeHierarchyPermission.STAGED_MODELS);

        _xStream.allowTypes(_XSTREAM_DEFAULT_ALLOWED_TYPES);

        _xStream.allowTypeHierarchy(List.class);
        _xStream.allowTypeHierarchy(Map.class);
        _xStream.allowTypeHierarchy(Timestamp.class);
        _xStream.allowTypeHierarchy(Set.class);

        _xStream.allowTypes(allowedTypeNames.toArray(new String[0]));

        _xStream.allowTypesByWildcard(new String[] { "com.thoughtworks.xstream.mapper.DynamicProxyMapper*" });
    }
 
开发者ID:inofix,项目名称:ch-inofix-timetracker,代码行数:62,代码来源:BaseExportImportController.java

示例4: writeXml

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
@Test
public void writeXml() {
	
	Method method = new Method();
	method.setName("message");
	method.setParams("String");
	method.setType("before");
	method.setCode("System.out.println(\"Hello before call !!!\");");
	
	Clazz clazz = new Clazz();
	clazz.setName("Messenger");
	clazz.setMethods(new ArrayList<Method>());
	clazz.getMethods().add(method);

	ByteChameleon bc = new ByteChameleon();
	bc.setClasses(new ArrayList<Clazz>());
	bc.getClasses().add(clazz);
	
	XStream xStream = new XStream();
	Class<?>[] classes = new Class[] { ByteChameleon.class, Clazz.class, Method.class };
	XStream.setupDefaultSecurity(xStream);
	xStream.allowTypes(classes);
	xStream.processAnnotations(ByteChameleon.class);
	
	String result = xStream.toXML(bc).replaceAll("&quot;", "\"");
	String[] resultArray = result.split("\n");
	
	
	String[] padrao = {
			"<byte-chameleon>",
			"  <classes>",
			"    <class>",
			"      <name>Messenger</name>",
			"      <methods>",
			"        <method type=\"before\">",
			"          <name>message</name>",
			"          <params>String</params>",
			"          <code>System.out.println(\"Hello before call !!!\");</code>",
			"        </method>",
			"      </methods>",
			"    </class>",
			"  </classes>",
			"</byte-chameleon>"
	};
	
	assertEquals(padrao.length, resultArray.length);
	
	for (int i = 0; i < padrao.length - 1; i++) {
		assertTrue("Linha " + (i + 1) + ": " + resultArray[i], resultArray[i].equals(padrao[i]));
	}
	
	
}
 
开发者ID:remartins,项目名称:byte-chameleon,代码行数:54,代码来源:XStreamTest.java


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