org.jdom2.Element.setAttributes()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(147)

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

Element.setAttributes介绍

[英]This sets the attributes of the element. The supplied Collection should contain only objects of type Attribute.

When all objects in the supplied List are legal and before the new attributes are added, all old attributes will have their parentage set to null (no parent) and the old attribute list will be cleared. This has the effect that any active attribute list (previously obtained with a call to #getAttributes) will also change to reflect the new attributes. In addition, all attributes in the supplied List will have their parentage set to this element, but the List itself will not be "live" and further removals and additions will have no effect on this elements attributes. If the user wants to continue working with a "live" attribute list, then a call to setAttributes should be followed by a call to #getAttributes to obtain a "live" version of the attributes.

Passing a null or empty List clears the existing attributes.

In cases where the List contains duplicate attributes, only the last one will be retained. This has the same effect as calling #setAttribute(Attribute) sequentially.

In event of an exception the original attributes will be unchanged and the attributes in the supplied attributes will be unaltered.
[中]这将设置元素的属性。提供的集合应仅包含类型为Attribute的对象。
如果提供的列表中的所有对象都是合法的,并且在添加新属性之前,所有旧属性的父级都将设置为null(无父级),并且旧属性列表将被清除。这会导致任何活动属性列表(以前通过调用#getAttributes获得)也会更改以反映新属性。此外,所提供列表中的所有属性的父级都将设置为此元素,但列表本身将不会是“活动”的,进一步的删除和添加将不会对此元素属性产生任何影响。如果用户希望继续使用“活动”属性列表,则调用setAttributes后应调用#getAttributes以获取属性的“活动”版本。
传递null或空列表将清除现有属性。
如果列表包含重复属性,则仅保留最后一个属性。这与按顺序调用#setAttribute(Attribute)具有相同的效果。
在异常情况下,原始属性将保持不变,所提供属性中的属性将保持不变。

代码示例

代码示例来源:origin: org.codehaus.plexus/plexus-component-metadata

/**
 * @param newAttributes list of new attributes. 
 * @return {@link Element}
 */
public Element setAttributes( List newAttributes )
{
  return element.setAttributes( newAttributes );
}

代码示例来源:origin: org.codehaus.izpack/izpack-util

/**
 * Adds attributes from in element to out element.
 *
 * @param out out element
 * @param in in element
 */
private void addAttributes(Element out, Element in)
{
  LinkedHashMap<String, Attribute> allAttributes = new LinkedHashMap<String, Attribute>();
  List<Attribute> outAttributes = new ArrayList<Attribute>(out.getAttributes());
  List<Attribute> inAttributes = new ArrayList<Attribute>(in.getAttributes());
  for (Attribute attr : outAttributes)
  {
    attr.detach();
    allAttributes.put(attr.getQualifiedName(), attr);
    logger.fine("adding attr from out:" + attr);
  }
  for (Attribute attr : inAttributes)
  {
    attr.detach();
    allAttributes.put(attr.getQualifiedName(), attr);
    logger.fine("adding attr from in:" + attr);
  }
  out.setAttributes(new ArrayList<Attribute>(allAttributes.values()));
}

代码示例来源:origin: org.codehaus.izpack/izpack-util

/**
 * Adds attributes from in element to out element.
 *
 * @param out out element
 * @param in in element
 */
private void addAttributes(Element out, Element in)
{
  LinkedHashMap<String, Attribute> allAttributes = new LinkedHashMap<String, Attribute>();
  List<Attribute> outAttributes = new ArrayList<Attribute>(out.getAttributes());
  List<Attribute> inAttributes = new ArrayList<Attribute>(in.getAttributes());
  for (Attribute attr : outAttributes)
  {
    attr.detach();
    allAttributes.put(attr.getQualifiedName(), attr);
    logger.fine("adding attr from out:" + attr);
  }
  for (Attribute attr : inAttributes)
  {
    attr.detach();
    allAttributes.put(attr.getQualifiedName(), attr);
    logger.fine("adding attr from in:" + attr);
  }
  out.setAttributes(new ArrayList<Attribute>(allAttributes.values()));
}

代码示例来源:origin: fiji/TrackMate

spotElement.setAttributes( attributes );
return spotElement;

代码示例来源:origin: sc.fiji/TrackMate_

spotElement.setAttributes( attributes );
return spotElement;

代码示例来源:origin: jpos/jPOS

@Test
public void testExecuteThrowsParseException() throws Throwable {
  Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
  e.addContent("XXXXXXX XXXXXXXXX XXXX");
  e.setAttributes(new ArrayList());
  Map<Integer, ?> arguments = new HashMap();
  Collection<?> returnNames = new ArrayList();
  try {
    BSHMethod.createBshMethod(e).execute(arguments, returnNames);
    fail("Expected ParseException to be thrown");
  } catch (ParseException ex) {
    assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 19")));
  }
}

代码示例来源:origin: jpos/jPOS

@Test
public void testExecuteThrowsParseException1() throws Throwable {
  Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
  e.addContent("XXXXXXX XXXXXXXXX XXXX");
  e.setAttributes(new ArrayList());
  try {
    BSHMethod.createBshMethod(e).execute(arguments, "testBSHMethodResultName");
    fail("Expected ParseException to be thrown");
  } catch (ParseException ex) {
    assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 19")));
  }
}

代码示例来源:origin: jpos/jPOS

@Test
public void testInitInterpreterThrowsEvalError() throws Throwable {
  Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
  e.addContent("testBSHMethod\rStr");
  e.setAttributes(new ArrayList());
  BSHMethod bshMethod = BSHMethod.createBshMethod(e);
  try {
    bshMethod.initInterpreter(arguments);
    fail("Expected EvalError to be thrown");
  } catch (EvalError ex) {
    assertEquals(
        "ex.getMessage()",
        "Sourced file: inline evaluation of: ``testBSHMethod Str;'' : Typed variable declaration : Class: testBSHMethod not found in namespace",
        ex.getMessage());
    assertEquals(
        "ex.getMessage()",
        "Sourced file: inline evaluation of: ``testBSHMethod Str;'' : Typed variable declaration : Class: testBSHMethod not found in namespace",
        ex.getMessage());
    assertEquals("(HashMap) arguments.size()", 0, arguments.size());
  }
}

相关文章

微信公众号

最新文章

更多