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

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

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

Element.<init>介绍

[英]This protected constructor is provided in order to support an Element subclass that wants full control over variable initialization. It intentionally leaves all instance variables null, allowing a lightweight subclass implementation. The subclass is responsible for ensuring all the get and set methods on Element behave as documented.

When implementing an Element subclass which doesn't require full control over variable initialization, be aware that simply calling super() (or letting the compiler add the implicit super() call) will not initialize the instance variables which will cause many of the methods to throw a NullPointerException. Therefore, the constructor for these subclasses should call one of the public constructors so variable initialization is handled automatically.
[中]提供此受保护的构造函数是为了支持希望完全控制变量初始化的元素子类。它有意将所有实例变量保留为null,从而允许轻量级子类实现。子类负责确保元素上的所有get和set方法都按照文档中的方式运行。
在实现不需要完全控制变量初始化的元素子类时,请注意,仅调用super()(或让编译器添加隐式super()调用)不会初始化实例变量,这将导致许多方法抛出NullPointerException。因此,这些子类的构造函数应该调用其中一个公共构造函数,以便自动处理变量初始化。

代码示例

代码示例来源:origin: gocd/gocd

private void addBreakers(Element element) {
  Element messages = new Element("messages");
  Element message = new Element("message");
  String breakerNames = StringUtils.join(breakers, ", ");
  message.setAttribute("text", breakerNames);
  message.setAttribute("kind", "Breakers");
  messages.addContent(message);
  element.addContent(messages);
}

代码示例来源:origin: gocd/gocd

public Element ccTrayXmlElement(String fullContextPath) {
  Element element = new Element("Project");
  element.setAttribute("name", name);
  element.setAttribute("activity", activity);
  element.setAttribute("lastBuildStatus", lastBuildStatus);
  element.setAttribute("lastBuildLabel", lastBuildLabel);
  element.setAttribute("lastBuildTime", DateUtils.formatIso8601ForCCTray(lastBuildTime));
  element.setAttribute("webUrl", fullContextPath + "/" + webUrl);
  if (!breakers.isEmpty()) {
    addBreakers(element);
  }
  return element;
}

代码示例来源:origin: geotools/geotools

public Element createRootTree() {
  final Element rootElement = new Element(GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME);
  rootElement.addContent(createIFD());
  return rootElement;
}

代码示例来源:origin: geotools/geotools

private Element createIFD() {
  Element ifd = new Element(GeoTiffConstants.GEOTIFF_IFD_TAG);
  ifd.setAttribute(
      GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME,
      BaselineTIFFTagSet.class.getName() + "," + GeoTIFFTagSet.class.getName());
  if (modelPixelScale.isSet()) {
    ifd.addContent(createModelPixelScaleElement());
  }
  if (isModelTiePointsSet()) {
    ifd.addContent(createModelTiePointsElement());
  } else if (isModelTransformationSet()) {
    ifd.addContent(createModelTransformationElement());
  }
  if (getNumGeoKeyEntries() > 1) {
    ifd.addContent(createGeoKeyDirectoryElement());
  }
  if (numGeoTiffDoubleParams > 0) {
    ifd.addContent(createGeoDoubleParamsElement());
  }
  if (numGeoTiffAsciiParams > 0) {
    ifd.addContent(createGeoAsciiParamsElement());
  }
  if (isNodataSet) {
    ifd.addContent(createNoDataElement());
  }
  if (isMetadataSet) {
    createMetadataElement(ifd);
  }
  return ifd;
}

代码示例来源:origin: gocd/gocd

private Document createEmptyCruiseConfigDocument() {
  Element root = new Element("cruise");
  Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS);
  root.addNamespaceDeclaration(xsiNamespace);
  registry.registerNamespacesInto(root);
  root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace);
  String xsds = registry.xsds();
  if (!xsds.isEmpty()) {
    root.setAttribute("schemaLocation", xsds, xsiNamespace);
  }
  root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION));
  return new Document(root);
}

代码示例来源:origin: geotools/geotools

private Element createGeoAsciiParamsElement() {
  Element field = createFieldElement(getGeoAsciiParamsTag());
  Element data = new Element(GeoTiffConstants.GEOTIFF_ASCIIS_TAG);
  field.addContent(data);
  data.addContent(createAsciiElement(geoTiffAsciiParams.toString()));
  return field;
}

代码示例来源:origin: edu.ucar/netcdf

private Element genCapabilityOperationElem( String operationAsString )
{
 Element getCapOpsElem;
 getCapOpsElem= new Element( operationAsString, wcsNS );
 getCapOpsElem.addContent(
     new Element( "DCPType", wcsNS ).addContent(
         new Element( "HTTP", wcsNS ).addContent(
             new Element( "Get", wcsNS ).addContent(
                 new Element( "OnlineResource", wcsNS ).setAttribute(
                     "href", serverURI.toString(), xlinkNS ) ) ) ) );
 return getCapOpsElem;
}

代码示例来源:origin: gocd/gocd

private static Element elementFor(Class<?> aClass, ConfigCache configCache) {
  final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class);
  if (attributeAwareConfigTag != null) {
    final Element element = new Element(attributeAwareConfigTag.value(), namespaceFor(attributeAwareConfigTag));
    element.setAttribute(attributeAwareConfigTag.attribute(), attributeAwareConfigTag.attributeValue());
    return element;
  }
  ConfigTag configTag = annotationFor(aClass, ConfigTag.class);
  if (configTag == null)
    throw bomb(format("Cannot get config tag for {0}", aClass));
  return new Element(configTag.value(), namespaceFor(configTag));
}

代码示例来源:origin: geotools/geotools

private Element createNoDataElement() {
  Element field = createFieldElement(getNoDataTag());
  Element data = new Element(GeoTiffConstants.GEOTIFF_ASCIIS_TAG);
  field.addContent(data);
  data.addContent(createAsciiElement(Double.toString(noData)));
  return field;
}

代码示例来源:origin: edu.ucar/netcdf

private Element genParamElement( String name, List<String> allowedValues )
{
 Element paramElem = new Element( "Parameter", owcsNS ).setAttribute( "name", name );
 Element allowedValuesElem = new Element( "AllowedValues", owcsNS );
 for ( String curVal : allowedValues )
  allowedValuesElem.addContent( new Element( "Value", owcsNS).addContent( curVal ) );
 return paramElem.addContent( allowedValuesElem);
}

代码示例来源:origin: gocd/gocd

@Test(expected = RuntimeException.class) public void shouldValidateAndConvertOnlyIfAppropriate()
    throws NoSuchFieldException {
  final Foo object = new Foo();
  final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null);
  final Element element = new Element("foo");
  element.setAttribute("number", "anything");
  field.setValueIfNotNull(element, object);
}

代码示例来源:origin: geotools/geotools

private Element createGeoDoubleParamsElement() {
  Element field = createFieldElement(getGeoDoubleParamsTag());
  Element data = new Element(GeoTiffConstants.GEOTIFF_DOUBLES_TAG);
  field.addContent(data);
  for (int i = 0; i < numGeoTiffDoubleParams; i++) {
    Element param = createDoubleElement(geoTiffDoubleParams[i]);
    data.addContent(param);
  }
  return field;
}

代码示例来源:origin: edu.ucar/netcdf

private Element genCapabilityOperationElem( String operationAsString )
{
 Element getCapOpsElem;
 getCapOpsElem= new Element( operationAsString, wcsNS );
 getCapOpsElem.addContent(
     new Element( "DCPType", wcsNS ).addContent(
         new Element( "HTTP", wcsNS ).addContent(
             new Element( "Get", wcsNS ).addContent(
                 new Element( "OnlineResource", wcsNS ).setAttribute(
                     "href", serverURI.toString(), xlinkNS ) ) ) ) );
 return getCapOpsElem;
}

代码示例来源:origin: gocd/gocd

@Test public void shouldConvertFromXmlToJavaObjectCorrectly() throws Exception {
  final Foo object = new Foo();
  final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null);
  final Element element = new Element("foo");
  element.setAttribute("number", "100");
  field.setValueIfNotNull(element, object);
  assertThat(object.number, is(100L));
}

代码示例来源:origin: geotools/geotools

private Element createModelTransformationElement() {
  Element field = createFieldElement(getModelTransformationTag());
  Element data = new Element(GeoTiffConstants.GEOTIFF_DOUBLES_TAG);
  field.addContent(data);
  addDoubleElements(data, modelTransformation);
  return field;
}

代码示例来源:origin: isisaddons/isis-app-todoapp

private static Element addTable(final Element body, final String id) {
  final Element table = new Element("table");
  body.addContent(table);
  table.setAttribute("id", id);
  return table;
}

代码示例来源:origin: gocd/gocd

@Test public void shouldConvertFileCorrectly() throws Exception {
  final Foo object = new Foo();
  final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("directory"), object, configCache, null);
  final Element element = new Element("foo");
  element.setAttribute("directory", "foo" + FileUtil.fileseparator() + "dir");
  field.setValueIfNotNull(element, object);
  assertThat(object.directory.getPath(), is("foo" + FileUtil.fileseparator() + "dir"));
}

代码示例来源:origin: geotools/geotools

private void createMetadataElement(Element ifd) {
  if (ifd != null && tiffTagsMetadata != null && !tiffTagsMetadata.isEmpty()) {
    Iterator<String> keys = tiffTagsMetadata.keySet().iterator();
    while (keys.hasNext()) {
      String key = keys.next();
      String[] setIdPair = key.split(":");
      String set = TagSet.BASELINE.toString();
      if (setIdPair.length > 1) {
        set = setIdPair[0].toUpperCase();
      }
      String keyName = setIdPair[setIdPair.length - 1];
      if (GeoTiffConstants.isNumeric(keyName)) {
        final String value = tiffTagsMetadata.get(key);
        final TIFFTag tag = getAsciiTag(set, Integer.valueOf(keyName));
        if (tag != null) {
          Element field = createFieldElement(tag);
          Element data = new Element(GeoTiffConstants.GEOTIFF_ASCIIS_TAG);
          field.addContent(data);
          data.addContent(createAsciiElement(value));
          ifd.addContent(field);
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.jspwiki/jspwiki-main

private Element getRDFItems() {
  Element items = new Element( "items", NS_XMNLS );
  Element rdfseq = new Element( "Seq", NS_RDF );
  for( Entry e : m_entries ) {
    String url = e.getURL();
    rdfseq.addContent( new Element( "li", NS_RDF ).setAttribute( "resource", url, NS_RDF ) );
  }
  items.addContent( rdfseq );
  return items;
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldContinueParsingWhenConfigClassHasValidAttributeAwareConfigTagAnnotation() {
  final Element element = new Element("example");
  element.setAttribute("type", "example-type");
  when(configCache.getFieldCache()).thenReturn(new ClassAttributeCache.FieldCache());
  final GoConfigClassLoader<ConfigWithAttributeAwareConfigTagAnnotation> loader = GoConfigClassLoader.classParser(element, ConfigWithAttributeAwareConfigTagAnnotation.class, configCache, goCipher, registry, referenceElements);
  final ConfigWithAttributeAwareConfigTagAnnotation configWithConfigTagAnnotation = loader.parse();
  assertNotNull(configWithConfigTagAnnotation);
}

相关文章

微信公众号

最新文章

更多