Search in sources :

Example 1 with BXMLAttributes

use of org.ballerinalang.model.values.BXMLAttributes in project ballerina by ballerina-lang.

the class CPU method execXMLOpcodes.

@SuppressWarnings("rawtypes")
private static void execXMLOpcodes(WorkerExecutionContext ctx, WorkerData sf, int opcode, int[] operands) {
    int i;
    int j;
    int k;
    int localNameIndex;
    int uriIndex;
    int prefixIndex;
    BXML<?> xmlVal;
    BXMLQName xmlQName;
    switch(opcode) {
        case InstructionCodes.XMLATTRSTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            xmlVal = (BXML) sf.refRegs[i];
            if (xmlVal == null) {
                handleNullRefError(ctx);
                break;
            }
            xmlQName = (BXMLQName) sf.refRegs[j];
            if (xmlQName == null) {
                handleNullRefError(ctx);
                break;
            }
            xmlVal.setAttribute(xmlQName.getLocalName(), xmlQName.getUri(), xmlQName.getPrefix(), sf.stringRegs[k]);
            break;
        case InstructionCodes.XMLATTRLOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            xmlVal = (BXML) sf.refRegs[i];
            if (xmlVal == null) {
                handleNullRefError(ctx);
                break;
            }
            xmlQName = (BXMLQName) sf.refRegs[j];
            if (xmlQName == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.stringRegs[k] = xmlVal.getAttribute(xmlQName.getLocalName(), xmlQName.getUri(), xmlQName.getPrefix());
            break;
        case InstructionCodes.XML2XMLATTRS:
            i = operands[0];
            j = operands[1];
            xmlVal = (BXML) sf.refRegs[i];
            if (xmlVal == null) {
                sf.refRegs[j] = null;
                break;
            }
            sf.refRegs[j] = new BXMLAttributes(xmlVal);
            break;
        case InstructionCodes.S2QNAME:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            String qNameStr = sf.stringRegs[i];
            int parenEndIndex = qNameStr.indexOf('}');
            if (qNameStr.startsWith("{") && parenEndIndex > 0) {
                sf.stringRegs[j] = qNameStr.substring(parenEndIndex + 1, qNameStr.length());
                sf.stringRegs[k] = qNameStr.substring(1, parenEndIndex);
            } else {
                sf.stringRegs[j] = qNameStr;
                sf.stringRegs[k] = STRING_NULL_VALUE;
            }
            break;
        case InstructionCodes.NEWQNAME:
            localNameIndex = operands[0];
            uriIndex = operands[1];
            prefixIndex = operands[2];
            i = operands[3];
            String localname = sf.stringRegs[localNameIndex];
            localname = StringEscapeUtils.escapeXml11(localname);
            String prefix = sf.stringRegs[prefixIndex];
            prefix = StringEscapeUtils.escapeXml11(prefix);
            sf.refRegs[i] = new BXMLQName(localname, sf.stringRegs[uriIndex], prefix);
            break;
        case InstructionCodes.XMLSEQLOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            xmlVal = (BXML) sf.refRegs[i];
            if (xmlVal == null) {
                handleNullRefError(ctx);
                break;
            }
            long index = sf.longRegs[j];
            sf.refRegs[k] = xmlVal.getItem(index);
            break;
        case InstructionCodes.XMLLOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            xmlVal = (BXML<?>) sf.refRegs[i];
            if (xmlVal == null) {
                handleNullRefError(ctx);
                break;
            }
            String qname = sf.stringRegs[j];
            sf.refRegs[k] = xmlVal.children(qname);
            break;
        case InstructionCodes.XMLLOADALL:
            i = operands[0];
            j = operands[1];
            xmlVal = (BXML<?>) sf.refRegs[i];
            if (xmlVal == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.refRegs[j] = xmlVal.children();
            break;
        case InstructionCodes.NEWXMLELEMENT:
        case InstructionCodes.NEWXMLCOMMENT:
        case InstructionCodes.NEWXMLTEXT:
        case InstructionCodes.NEWXMLPI:
        case InstructionCodes.XMLSEQSTORE:
        case InstructionCodes.NEWXMLSEQ:
            execXMLCreationOpcodes(ctx, sf, opcode, operands);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : BXMLQName(org.ballerinalang.model.values.BXMLQName) BXMLAttributes(org.ballerinalang.model.values.BXMLAttributes) BString(org.ballerinalang.model.values.BString)

Aggregations

BString (org.ballerinalang.model.values.BString)1 BXMLAttributes (org.ballerinalang.model.values.BXMLAttributes)1 BXMLQName (org.ballerinalang.model.values.BXMLQName)1