com.thoughtworks.xstream.XStream.aliasSystemAttribute()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(255)

本文整理了Java中com.thoughtworks.xstream.XStream.aliasSystemAttribute()方法的一些代码示例,展示了XStream.aliasSystemAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XStream.aliasSystemAttribute()方法的具体详情如下:
包路径:com.thoughtworks.xstream.XStream
类名称:XStream
方法名:aliasSystemAttribute

XStream.aliasSystemAttribute介绍

[英]Create an alias for a system attribute. XStream will not write a system attribute if its alias is set to null. However, this is not reversible, i.e. deserialization of the result is likely to fail afterwards and will not produce an object equal to the originally written one.
[中]为系统属性创建别名。如果XStream的别名设置为[$0$],它将不会写入系统属性。然而,这是不可逆的,也就是说,结果的反序列化之后可能会失败,并且不会生成与最初写入的对象相等的对象。

代码示例

代码示例来源:origin: kiegroup/optaplanner

/**
 * Builds the {@link XStream} setup which is used to read/write {@link SolverConfig solver configs} and benchmark configs.
 * It should never be used to read/write {@link PlanningSolution solutions}.
 * Use XStreamSolutionFileIO for that instead.
 * @return never null.
 */
public static XStream buildXStream() {
  XStream xStream = new XStream();
  xStream.setMode(XStream.ID_REFERENCES);
  xStream.aliasSystemAttribute("xStreamId", "id");
  xStream.aliasSystemAttribute("xStreamRef", "reference");
  xStream.processAnnotations(SolverConfig.class);
  XStream.setupDefaultSecurity(xStream);
  xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.config\\..*"});
  return xStream;
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
   Players xstramAliasObject = new Players();
   XStream xstream = new XStream(new JsonHierarchicalStreamDriver());
   xstream.setMode(XStream.NO_REFERENCES);
   xstream.aliasSystemAttribute(null, "class");
   xstream.autodetectAnnotations(true);
   System.out.println("--- "+xstream.toXML(xstramAliasObject));
 }

代码示例来源:origin: fabriciocolombo/sonar-delphi

/**
 * Builds rule sets from xml file
 * 
 * @param configuration Xml file configuration
 * @return Rule set
 */
public static Ruleset buildRuleSetFromXml(String configuration) {
 XStream xstream = new XStream();
 xstream.setClassLoader(DelphiRulesUtils.class.getClassLoader());
 xstream.processAnnotations(Ruleset.class);
 xstream.processAnnotations(DelphiRule.class);
 xstream.processAnnotations(Property.class);
 xstream.aliasSystemAttribute("ref", "class");
 return (Ruleset) xstream.fromXML(configuration);
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-php-plugin

/**
 * Gets the coverage.
 * 
 * @param coverageReportFile
 *          the coverage report file
 * @return the coverage
 */
private CoverageNode getCoverage(File coverageReportFile) {
 InputStream inputStream = null;
 try {
  XStream xstream = new XStream();
  xstream.setClassLoader(getClass().getClassLoader());
  xstream.aliasSystemAttribute("classType", "class");
  xstream.processAnnotations(CoverageNode.class);
  xstream.processAnnotations(ProjectNode.class);
  xstream.processAnnotations(FileNode.class);
  xstream.processAnnotations(MetricsNode.class);
  xstream.processAnnotations(LineNode.class);
  inputStream = new FileInputStream(coverageReportFile);
  return (CoverageNode) xstream.fromXML(inputStream);
 } catch (IOException e) {
  throw new SonarException("Can't read pUnit report : " + coverageReportFile.getName(), e);
 } finally {
  IOUtils.closeQuietly(inputStream);
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-php-plugin

/**
 * Gets the test suites.
 * 
 * @param report
 *          the report
 * @return the test suites
 */
private TestSuites getTestSuites(File report) {
 InputStream inputStream = null;
 try {
  XStream xstream = new XStream();
  // Sonar 2.2 migration
  xstream.setClassLoader(getClass().getClassLoader());
  xstream.aliasSystemAttribute("fileName", "class");
  xstream.processAnnotations(TestSuites.class);
  xstream.processAnnotations(TestSuite.class);
  xstream.processAnnotations(TestCase.class);
  inputStream = new FileInputStream(report);
  TestSuites testSuites = (TestSuites) xstream.fromXML(inputStream);
  Log.debug("Tests suites: " + testSuites);
  return testSuites;
 } catch (IOException e) {
  throw new SonarException("Can't read PhpUnit report : " + report.getAbsolutePath(), e);
 } finally {
  IOUtils.closeQuietly(inputStream);
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-php-plugin

/**
 * Gets the duplications.
 * 
 * @param reportFile
 *          the report file
 * @return the coverage
 */
private List<DuplicationNode> getDuplications(File reportFile) {
 InputStream inputStream = null;
 try {
  XStream xstream = new XStream();
  xstream.setClassLoader(getClass().getClassLoader());
  xstream.aliasSystemAttribute("classType", "class");
  xstream.processAnnotations(PmdCpdNode.class);
  xstream.processAnnotations(DuplicationNode.class);
  xstream.processAnnotations(FileNode.class);
  inputStream = new FileInputStream(reportFile);
  PmdCpdNode node = (PmdCpdNode) xstream.fromXML(inputStream);
  if (node.getDuplications() != null) {
   return node.getDuplications();
  }
 } catch (IOException e) {
  throw new SonarException("Can't read phpcpd report : " + reportFile.getName(), e);
 } finally {
  IOUtils.closeQuietly(inputStream);
 }
 return new ArrayList<DuplicationNode>();
}

代码示例来源:origin: de.digitalcollections.model/dc-model-xml

public DigitalCollectionsXStreamMarshaller() {
 super();
 setStreamDriver(new CdataXppDriver());
 Map<String, Class> aliases = getAliases();
 setAliases(aliases);
 Map<Class, String> attributes = new HashMap<>();
 attributes.put(MarkImpl.class, "type");
 setUseAttributeFor(attributes);
 XStream xStream = getXStream();
 xStream.aliasSystemAttribute(null, "class");
 xStream.registerConverter(new MapToFlatConverter(xStream.getMapper()));
 xStream.aliasField("body", TextImpl.class, "text");
 xStream.aliasField("content", BlockquoteImpl.class, "contentBlocks");
 xStream.aliasField("content", BulletListImpl.class, "contentBlocks");
 xStream.aliasField("content", CodeBlockImpl.class, "contentBlocks");
 xStream.aliasField("content", HeadingImpl.class, "contentBlocks");
 xStream.aliasField("content", ListItemImpl.class, "contentBlocks");
 xStream.aliasField("content", OrderedListImpl.class, "contentBlocks");
 xStream.aliasField("content", ParagraphImpl.class, "contentBlocks");
 xStream.setMode(XStream.NO_REFERENCES);
}

代码示例来源:origin: com.haulmont.reports/reports-core

xStream.alias("format", ReportValueFormat.class);
xStream.addDefaultImplementation(LinkedHashMap.class, Map.class);
xStream.aliasSystemAttribute(null, "class");

代码示例来源:origin: de.digitalcollections.model/dc-model-xml

public V1DigitalCollectionsXStreamMarshaller() {
 super();
 setStreamDriver(new CdataXppDriver());
 Map<String, Class> aliases = getAliases();
 setAliases(aliases);
 Map<Class, String> attributes = new HashMap<>();
 attributes.put(MarkImpl.class, "type");
 setUseAttributeFor(attributes);
 XStream xStream = getXStream();
 xStream.aliasSystemAttribute(null, "class");
 xStream.registerConverter(new MapToFlatConverter(xStream.getMapper()));
 xStream.aliasField("body", TextImpl.class, "text");
 xStream.aliasField("content", BlockquoteImpl.class, "contentBlocks");
 xStream.aliasField("content", BulletListImpl.class, "contentBlocks");
 xStream.aliasField("content", CodeBlockImpl.class, "contentBlocks");
 xStream.aliasField("content", HeadingImpl.class, "contentBlocks");
 xStream.aliasField("content", ListItemImpl.class, "contentBlocks");
 xStream.aliasField("content", OrderedListImpl.class, "contentBlocks");
 xStream.aliasField("content", ParagraphImpl.class, "contentBlocks");
 xStream.aliasField("content", StructuredContentImpl.class, "contentBlocks");
 xStream.aliasField("documents", LocalizedStructuredContentImpl.class, "localizedStructuredContent");
 xStream.setMode(XStream.NO_REFERENCES);
}

代码示例来源:origin: org.kantega.openaksess/openaksess-core

xstream.aliasSystemAttribute("refid", "id");

相关文章