Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

In this page you can find the example usage for org.dom4j Element attributeValue.

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

From source file:com.devoteam.srit.xmlloader.core.Scenario.java

License:Open Source License

/**
 * Parse a ReceivePacketSCTP operation//  w  w w  .ja  va 2s.c o  m
 */
@Deprecated
private Operation parseReceiveSCTP(String protocol, Element node) throws Exception {
    String channel = node.attributeValue("connexionName");
    return new OperationReceiveMsg(StackFactory.PROTOCOL_SCTP, true, channel, null, null, null, node, this);
}

From source file:com.devoteam.srit.xmlloader.core.ScenarioReference.java

License:Open Source License

public ScenarioReference(Element elements, Testcase testcase) {
    _name = elements.attributeValue("name");
    _routingName = elements.attributeValue("routingName");
    _description = elements.attributeValue("description");
    String strState = elements.attributeValue("state");
    if (strState != null) {
        _state = Boolean.parseBoolean(strState);
    }// w w w.j  a  va2s .co  m
    _filename = elements.attributeValue("file");
    if (null == _filename) {
        _filename = elements.getStringValue();
    }
    _filename = _filename.trim();
    _testcase = testcase;
}

From source file:com.devoteam.srit.xmlloader.diameter.dictionary.Application.java

License:Open Source License

private void parseVendor(Element root) throws ParsingException {

    int code = -1;
    try {/*from  ww  w  .j av  a  2  s  .  co  m*/
        if (null != root.attribute("code")) {
            code = Integer.parseInt(root.attributeValue("code"));
        } else {
            Dictionary.traceWarning("No vendor.code, skipping");
            return;
        }
    } catch (Exception e) {
        Dictionary.traceWarning("Invalid vendor.code, skipping");
        return;
    }

    String vendor_id = null;
    if (null != root.attributeValue("vendor-id"))
        vendor_id = root.attributeValue("vendor-id");
    else {
        Dictionary.traceWarning("No vendor.vendor-id, skipping");
        return;
    }

    String name = null;
    if (null != root.attributeValue("name"))
        name = root.attributeValue("name");

    VendorDef vendorDef = new VendorDef(code, vendor_id, name);

    if (null != getVendorDefByCode(code))
        Dictionary.traceWarning("VendorDef of code " + code + " already exists, overwriting");
    if (null != getVendorDefByName(vendor_id))
        Dictionary.traceWarning("VendorDef of vendor-id " + vendor_id + " already exists, overwriting");

    vendorDefByName.put(vendor_id, vendorDef);
    vendorDefByCode.put(Integer.toString(code), vendorDef);

}

From source file:com.devoteam.srit.xmlloader.diameter.dictionary.Application.java

License:Open Source License

private void parseAvp(Element root) throws ParsingException {
    String name = null;/*from w ww. j a v a2s  . c  o m*/
    String description = null;
    String may_encrypt = null;
    String mandatory = null;
    String protected_ = null;
    String vendor_bit = null;

    if (null != root.attributeValue("name"))
        name = root.attributeValue("name");
    else {
        Dictionary.traceWarning("Invalid avp.name, skipping");
        return;
    }
    if (null != root.attributeValue("description"))
        description = root.attributeValue("description");
    if (null != root.attributeValue("may-encrypt"))
        may_encrypt = root.attributeValue("may-encrypt");
    if (null != root.attributeValue("mandatory"))
        mandatory = root.attributeValue("mandatory");
    if (null != root.attributeValue("protected"))
        protected_ = root.attributeValue("protected");
    if (null != root.attributeValue("vendor-bit"))
        vendor_bit = root.attributeValue("vendor-bit");

    int code;
    try {
        code = Integer.parseInt(root.attributeValue("code"));
    } catch (Exception e) {
        code = -1;
    }

    if (code == -1) {
        Dictionary.traceWarning("Missing avp.code, skipping");
        return;
    }

    boolean constrained = false;
    if (null != root.attributeValue("constrained"))
        constrained = Boolean.parseBoolean(root.attributeValue("constrained"));

    VendorDef vendor_id = null;
    if (null != root.attributeValue("vendor-id"))
        vendor_id = Dictionary.getInstance().getVendorDefByName(root.attributeValue("vendor-id"), _name);

    TypeDef type = null;
    {
        List<Element> elements;
        elements = root.elements("type");
        for (Element element : elements) {
            String type_name = element.attributeValue("type-name");
            type = Dictionary.getInstance().getTypeDefByName(type_name, _name);
            if (type == null) {
                Dictionary.traceWarning("Invalid avp.type (" + type_name + "), skipping");
            }
        }
    }

    AvpDef avpDef = new AvpDef(name, code, description, may_encrypt, protected_, vendor_bit, mandatory,
            constrained, type, vendor_id);

    // parse enums
    {
        List<Element> elements;
        elements = root.elements("enum");
        for (Element element : elements) {
            String enum_name = null;
            if (null != element.attribute("name")) {
                enum_name = element.attributeValue("name");
            } else {
                Dictionary.traceWarning("No avp.enum.name in " + avpDef.get_name() + ", skipping this enum");
                continue;
            }

            int enum_code = -1;
            if (null != element.attribute("code")) {
                try {
                    enum_code = Integer.parseInt(element.attributeValue("code"));
                } catch (Exception e) {
                    Dictionary.traceWarning(
                            "Invalid avp.enum.code in " + avpDef.get_name() + ", skipping this enum");
                    continue;
                }
            } else {
                Dictionary.traceWarning("No avp.enum.code in " + avpDef.get_name() + ", skipping this enum");
                continue;
            }

            avpDef.addEnum(enum_name, enum_code);
        }
    }

    // parse grouped
    {
        Element elementGrouped = root.element("grouped");
        if (null != elementGrouped) {
            List<Element> elements;
            elements = elementGrouped.elements("gavp");

            for (Element element : elements) {
                String gavp_name = element.attributeValue("name");
                avpDef.addGroupedAvpName(gavp_name);
            }
        }
    }

    if (null != getAvpDefByCode(avpDef.get_code()))
        Dictionary.traceWarning("AvpDef of code " + avpDef.get_code() + " already exists, overwriting");
    if (null != getAvpDefByName(avpDef.get_name()))
        Dictionary.traceWarning("AvpDef of name " + avpDef.get_name() + " already exists, overwriting");

    avpDefByName.put(avpDef.get_name(), avpDef);
    avpDefByCode.put(Integer.toString(avpDef.get_code()), avpDef);
}

From source file:com.devoteam.srit.xmlloader.diameter.dictionary.Application.java

License:Open Source License

private void parseCommand(Element root) throws ParsingException {
    int code = -1;
    try {/*from  w  w  w  .j  av  a  2s  .c o m*/
        if (null != root.attribute("code"))
            code = Integer.parseInt(root.attributeValue("code"));
        else {
            Dictionary.traceWarning("No commands.code, skipping");
            return;
        }
    } catch (Exception e) {
        Dictionary.traceWarning("Invalid command.code, skipping");
        return;
    }

    VendorDef vendor_id = null;
    if (null != root.attributeValue("vendor-id"))
        Dictionary.getInstance().getVendorDefByName(root.attributeValue("vendor-id"), _name);

    String name = null;
    if (null != root.attributeValue("name"))
        name = root.attributeValue("name");
    else {
        Dictionary.traceWarning("Invalid command.name, skipping");
        return;
    }

    CommandDef commandDef = new CommandDef(code, name, vendor_id);

    if (null != getCommandDefByCode(code))
        Dictionary.traceWarning("CommandDef of code " + code + " already exists, overwriting");
    if (null != getCommandDefByName(name))
        Dictionary.traceWarning("CommandDef of name " + name + " already exists, overwriting");

    commandDefByName.put(name, commandDef);
    commandDefByCode.put(Integer.toString(code), commandDef);
}

From source file:com.devoteam.srit.xmlloader.diameter.dictionary.Application.java

License:Open Source License

private void parseType(Element root) throws ParsingException {
    TypeDef type_parent = null;//from  w  w  w  .j  av  a  2 s.c  om
    if (null != root.attributeValue("type-parent")) {
        type_parent = Dictionary.getInstance().getTypeDefByName(root.attributeValue("type-parent"), _name);
        if (type_parent == null) {
            Dictionary.traceWarning("Invalid typedefn.type-parent, skipping");
            return;
        }
    }

    String name = null;

    if (null != root.attributeValue("type-name"))
        name = root.attributeValue("type-name");
    else {
        Dictionary.traceWarning("Invalid typedefn.name, skipping");
        return;
    }

    TypeDef typeDef = new TypeDef(name, type_parent);

    if (null != getTypeDefByName(name))
        Dictionary.traceWarning("TypeDef of name " + name + " already exists, overwriting");

    typeDefByName.put(name, typeDef);
}

From source file:com.devoteam.srit.xmlloader.diameter.dictionary.Dictionary.java

License:Open Source License

private void parseApplication(Element root) throws ParsingException {
    boolean isBase = false;
    if (root.getName().equals("base")) {
        isBase = true;/*from w  ww  .  ja  v  a  2  s  .c  om*/
    }

    int id = -1;
    try {
        if (null != root.attribute("id")) {
            id = Integer.parseInt(root.attributeValue("id"));
        } else if (false == isBase) {
            traceWarning("No application.id, skipping");
            return;
        }
    } catch (Exception e) {
        traceWarning("Invalid application.code, skipping");
        return;
    }

    String name = null;
    if (null != root.attribute("name")) {
        name = root.attributeValue("name");
    } else if (false == isBase) {
        traceWarning("No application.name, skipping");
        return;
    }

    if (isBase) {
        name = "0";
        id = 0;
    }

    traceDebug("parsing application " + name);

    Application application = getApplicationById(id);
    if (application == null) {
        application = new Application(name, id);
    }
    applicationByName.put(name, application);
    applicationById.put(Integer.toString(id), application);

    application.parseApplication(root);
    application.fillGroupedAvpsReferences();
}

From source file:com.devoteam.srit.xmlloader.diameter.ListenpointDiamCommon.java

License:Open Source License

/**
 * Create the node settingds object./*w w  w.j a va 2 s .  co m*/
 * @return
 */
protected NodeSettings createNodeSettings(Capability capability, Message capabilityMessage,
        Element nodeSettingsElement) throws Exception {
    // set node settings
    String nodeHostId = this.getHost();
    if (nodeHostId == null || nodeHostId.equalsIgnoreCase("0.0.0.0")) {
        // The listenpoint host can not be 0.0.0.0 due to the CER/CEA exchange mechanism
        nodeHostId = Utils.getLocalAddress().getHostAddress();
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "nodeHostId : ", nodeHostId);
    int nodePort = this.getPort();
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "nodePort : ", nodePort);

    String nodeRealm = stack.getConfig().getString("node.REALM");
    if (capabilityMessage != null) {
        // AVP Origin-Realm = 296
        AVP avp = capabilityMessage.find(296);
        if (avp != null) {
            nodeRealm = new String(new AVP_OctetString(avp).queryValue());
        }
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "nodeRealm : ", nodeRealm);
    int nodeVendorId = stack.getConfig().getInteger("node.VENDOR_ID");
    if (capabilityMessage != null) {
        // AVP Vendor-Id = 266
        AVP avp = capabilityMessage.find(266);
        if (avp != null) {
            nodeVendorId = new AVP_Integer32(avp).queryValue();
        }
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "nodeVendorId : ",
            nodeVendorId);
    String nodeProductName = stack.getConfig().getString("node.PRODUCT_NAME");
    if (capabilityMessage != null) {
        // AVP Product-Name = 269
        AVP avp = capabilityMessage.find(269);
        if (avp != null) {
            nodeProductName = new String(new AVP_OctetString(avp).queryValue());
        }
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "nodeProductName : ",
            nodeProductName);
    int nodeFirmwareRevision = stack.getConfig().getInteger("node.FIRMWARE_REVISION");
    if (capabilityMessage != null) {
        // AVP Firmware-Revision = 267
        AVP avp = capabilityMessage.find(267);
        if (avp != null) {
            nodeFirmwareRevision = new AVP_Integer32(avp).queryValue();
        }
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "nodeFirmwareRevision : ",
            nodeFirmwareRevision);

    // DNS resolver : not done by the diameter stack
    NodeSettings node_settings = new NodeSettings(nodeHostId, nodeRealm, nodeVendorId, capability, nodePort,
            nodeProductName, nodeFirmwareRevision);

    boolean isNodeUseSCTP = this.getListenSCTP();
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "isNodeUseSCTP : ",
            isNodeUseSCTP);
    node_settings.setUseSCTP(isNodeUseSCTP);
    boolean isNodeUseTCP = this.getListenTCP();
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "isNodeUseTCP : ",
            isNodeUseTCP);
    node_settings.setUseTCP(isNodeUseTCP);

    long idleTimeout = stack.getConfig().getInteger("node.IDLE_TIMEOUT");
    if (nodeSettingsElement != null) {
        idleTimeout = Long.parseLong(nodeSettingsElement.attributeValue("idleTimeout"));
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "idleTimeout : ",
            idleTimeout);
    node_settings.setIdleTimeout(idleTimeout);
    long watchdogInterval = stack.getConfig().getInteger("node.WATCHDOG_INTERVAL");
    if (nodeSettingsElement != null) {
        watchdogInterval = Long.parseLong(nodeSettingsElement.attributeValue("watchdogInterval"));
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "watchdogInterval : ",
            watchdogInterval);
    node_settings.setWatchdogInterval(watchdogInterval);

    return node_settings;
}

From source file:com.devoteam.srit.xmlloader.diameter.MsgDiamCommon.java

License:Open Source License

/** 
 * Parse the message from XML element /* w  w w  . ja  va2s.  co  m*/
 */
@Override
public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception {
    this.message = MsgDiameterParser.getInstance().parseMsgFromXml(request, root);

    // DEPRECATED begin
    String server = root.attributeValue("server");
    if (server != null) {
        GlobalLogger.instance().logDeprecatedMessage(root.getName() + " server=\"xxx\" .../",
                "sendMessageDiameter remoteUrl=\"xxx\" .../");
        this.setRemoteUrl(server);
    }
    // DEPRECATED end
}

From source file:com.devoteam.srit.xmlloader.diameter.MsgDiameterParser.java

License:Open Source License

/** Creates a new Msg object from the root XML element */
public MsgDiameter parseMsgFromXml(Boolean request, Element root) throws Exception {
    MsgDiameter msgDiameter = new MsgDiameter(new Message());

    //!!deprecated part!!//
    String server = root.attributeValue("server");
    if (server != null) {
        GlobalLogger.instance().logDeprecatedMessage(root.getName() + " server=\"xxx\" .../",
                "sendMessageDiameter remoteUrl=\"xxx\" .../");
        msgDiameter.setRemoteUrl(server);
    }//from   w w w. j a va2s  .  co  m
    //!!deprecated part!!//

    // parse the message after we set the channel (for hop-by-hop computing)
    parseMessage(msgDiameter, request, root);

    return msgDiameter;
}