Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

In this page you can find the example usage for org.jdom2 Element setAttribute.

Prototype

public Element setAttribute(final String name, final String value) 

Source Link

Document

This sets an attribute value for this element.

Usage

From source file:cz.pecina.retro.cpu.Device.java

License:Open Source License

/**
 * Gets a representation of the {@code Device} in 
 * a JDOM {@code Element}.//  ww w.  j ava 2s. c  o  m
 *
 * @return {@code Element} representing the {@code Device}
 */
public Element marshal() {
    log.fine("Marshalling device: " + name);
    preMarshal();
    final Element device = new Element("device");
    device.setAttribute("name", name);
    for (Descriptor descriptor : this) {
        log.finest("Marshalling '" + descriptor.getName() + "'");
        device.addContent(descriptor.marshal());
    }
    postMarshal();
    return device;
}

From source file:cz.pecina.retro.cpu.Hardware.java

License:Open Source License

/**
 * Gets a representation of the {@code Hardware} object in 
 * a JDOM {@code Element}./*from   www.  jav  a  2  s.c  o m*/
 *
 * @param hardware {@code Element} representing the
 * {@code Hardware} object
 */
public void marshal(final Element hardware) {
    log.fine("Marshalling hardware");
    hardware.setAttribute("name", name);
    for (Device device : this) {
        hardware.addContent(device.marshal());
    }
}

From source file:cz.pecina.retro.cpu.Register.java

License:Open Source License

@Override
public Element marshal() {
    final Element register = new Element(tagName);
    register.setAttribute("name", name);
    final String value = getValue();
    register.addContent(value);//w w w .  j  av  a  2 s.c o m
    log.fine("Register '" + name + "' holding value '" + value + "' marshalled");
    return register;
}

From source file:cz.pecina.retro.memory.Snapshot.java

License:Open Source License

/**
 * Builds a block tag.//from   w  w w  . ja v a  2  s. c  om
 *
 * @param memory       memory array
 * @param tag          tag to build
 * @param startAddress starting address
 * @param number       number of bytes
 */
public static void buildBlockElement(final byte[] memory, final Element tag, final int startAddress,
        final int number) {
    log.finer(String.format("Method buildMemoryElement called: start address: %04x," + " number of bytes: %d",
            startAddress, number));
    final int size = memory.length;
    boolean inSequence = false;
    StringBuilder data = new StringBuilder();
    Element bytes;
    for (int i = 0, j = 0; i < number;) {
        final int memoryI = memory[(startAddress + i) % size] & 0xff;
        final int remain = number - i;
        boolean compress = false;
        if (remain >= COUNT_LIMIT) {
            compress = true;
            for (j = 0; j < COUNT_LIMIT; j++) {
                if (memoryI != (memory[(startAddress + i + j) % size] & 0xff)) {
                    compress = false;
                    break;
                }
            }
        }
        if (compress) {
            for (; j < remain; j++) {
                if (memoryI != (memory[(startAddress + i + j) % size] & 0xff)) {
                    break;
                }
            }
            if (inSequence) {
                bytes = new Element(subtagName);
                bytes.addContent(data.toString());
                tag.addContent(bytes);
                data = new StringBuilder();
                log.finest("Data sequence closed");
            }
            inSequence = false;
            bytes = new Element(subtagName);
            bytes.setAttribute("count", String.valueOf(j));
            bytes.addContent(String.format("%02x", memoryI));
            tag.addContent(bytes);
            log.finest(String.format("Repeated data sequence written, count: %d, data: %02x", j, memoryI));
            i += j;
        } else {
            if (!inSequence) {
                data = new StringBuilder();
                log.finest("Unique data sequence started");
            }
            data.append(String.format("%02x", memoryI));
            log.finest(String.format("One byte written: %02x", memoryI));
            inSequence = true;
            i++;
        }
    }
    if (inSequence) {
        bytes = new Element(subtagName);
        bytes.addContent(data.toString());
        tag.addContent(bytes);
        log.finest("Final data sequence closed");
    }
    log.finer("Method buildMemoryElement finished");
}

From source file:de.bund.bfr.knime.pmm.common.AgentXml.java

License:Open Source License

@Override
public Element toXmlElement() {
    Element ret = new Element(ELEMENT_AGENT);

    ret.setAttribute(ATT_ID, XmlHelper.getNonNull(id));
    ret.setAttribute(ATT_NAME, XmlHelper.getNonNull(name));
    ret.setAttribute(ATT_DETAIL, XmlHelper.getNonNull(detail));
    ret.setAttribute(ATT_DBUUID, XmlHelper.getNonNull(dbuuid));

    return ret;/*from   w  w  w  . ja  v a  2  s.c o  m*/
}

From source file:de.bund.bfr.knime.pmm.common.CatalogModelXml.java

License:Open Source License

@Override
public Element toXmlElement() {
    Element modelElement = new Element(ELEMENT_CATALOGMODEL);

    modelElement.setAttribute(ATT_ID, XmlHelper.getNonNull(id));
    modelElement.setAttribute(ATT_NAME, XmlHelper.getNonNull(name));
    modelElement.setAttribute(ATT_FORMULA, XmlHelper.getNonNull(formula));
    modelElement.setAttribute(ATT_MODEL_CLASS, XmlHelper.getNonNull(modelClass));
    modelElement.setAttribute(ATT_COMMENT, XmlHelper.getNonNull(comment));
    modelElement.setAttribute(ATT_DBUUID, XmlHelper.getNonNull(dbuuid));

    return modelElement;
}

From source file:de.bund.bfr.knime.pmm.common.DepXml.java

License:Open Source License

@Override
public Element toXmlElement() {
    Element ret = new Element(ELEMENT_DEPENDENT);

    ret.setAttribute(ATT_NAME, XmlHelper.getNonNull(name));
    ret.setAttribute(ATT_ORIGNAME, XmlHelper.getNonNull(origName));
    ret.setAttribute(ATT_MIN, XmlHelper.getNonNull(min));
    ret.setAttribute(ATT_MAX, XmlHelper.getNonNull(max));
    ret.setAttribute(ATT_CATEGORY, XmlHelper.getNonNull(category));
    ret.setAttribute(ATT_UNIT, XmlHelper.getNonNull(unit));
    ret.setAttribute(ATT_DESCRIPTION, XmlHelper.getNonNull(description));

    return ret;// ww w .  ja va 2  s. c  o  m
}

From source file:de.bund.bfr.knime.pmm.common.EstModelXml.java

License:Open Source License

@Override
public Element toXmlElement() {
    Element ret = new Element(ELEMENT_ESTMODEL);

    ret.setAttribute(ATT_ID, XmlHelper.getNonNull(id));
    ret.setAttribute(ATT_NAME, XmlHelper.getNonNull(name));
    ret.setAttribute(ATT_SSE, XmlHelper.getNonNull(sse));
    ret.setAttribute(ATT_RMS, XmlHelper.getNonNull(rms));
    ret.setAttribute(ATT_R2, XmlHelper.getNonNull(r2));
    ret.setAttribute(ATT_AIC, XmlHelper.getNonNull(aic));
    ret.setAttribute(ATT_BIC, XmlHelper.getNonNull(bic));
    ret.setAttribute(ATT_DOF, XmlHelper.getNonNull(dof));
    ret.setAttribute(ATT_QUALITYSCORE, XmlHelper.getNonNull(qualityScore));
    ret.setAttribute(ATT_CHECKED, XmlHelper.getNonNull(checked));
    ret.setAttribute(ATT_COMMENT, XmlHelper.getNonNull(comment));
    ret.setAttribute(ATT_DBUUID, XmlHelper.getNonNull(dbuuid));

    return ret;/*from w w  w .  jav a  2s .  c o  m*/
}

From source file:de.bund.bfr.knime.pmm.common.IndepXml.java

License:Open Source License

@Override
public Element toXmlElement() {
    Element ret = new Element(ELEMENT_INDEP);

    ret.setAttribute(ATT_NAME, XmlHelper.getNonNull(name));
    ret.setAttribute(ATT_ORIGNAME, XmlHelper.getNonNull(origName));
    ret.setAttribute(ATT_MIN, XmlHelper.getNonNull(min));
    ret.setAttribute(ATT_MAX, XmlHelper.getNonNull(max));
    ret.setAttribute(ATT_CATEGORY, XmlHelper.getNonNull(category));
    ret.setAttribute(ATT_UNIT, XmlHelper.getNonNull(unit));
    ret.setAttribute(ATT_DESCRIPTION, XmlHelper.getNonNull(description));

    return ret;/*from  ww w.j a v a  2s  . com*/
}

From source file:de.bund.bfr.knime.pmm.common.LiteratureItem.java

License:Open Source License

@Override
public Element toXmlElement() {
    Element ret = new Element(ELEMENT_LITERATURE);

    ret.setAttribute(ATT_AUTHOR, XmlHelper.getNonNull(author));
    ret.setAttribute(ATT_YEAR, XmlHelper.getNonNull(year));
    ret.setAttribute(ATT_TITLE, XmlHelper.removeDirt(title));
    ret.setAttribute(ATT_ABSTRACT, XmlHelper.removeDirt(abstractText));
    ret.setAttribute(ATT_JOURNAL, XmlHelper.getNonNull(journal));
    ret.setAttribute(ATT_VOLUME, XmlHelper.getNonNull(volume));
    ret.setAttribute(ATT_ISSUE, XmlHelper.getNonNull(issue));
    ret.setAttribute(ATT_PAGE, XmlHelper.getNonNull(page));
    ret.setAttribute(ATT_APPROVAL_MODE, XmlHelper.getNonNull(approvalMode));
    ret.setAttribute(ATT_WEBSITE, XmlHelper.getNonNull(website));
    ret.setAttribute(ATT_TYPE, XmlHelper.getNonNull(type));
    ret.setAttribute(ATT_COMMENT, XmlHelper.getNonNull(comment));
    ret.setAttribute(ATT_ID, XmlHelper.getNonNull(id));
    ret.setAttribute(ATT_DBUUID, XmlHelper.getNonNull(dbuuid));

    return ret;//w w  w  .ja va2s . co m
}