Examples of JConditional


Examples of com.sun.codemodel.JConditional

    private JVar createVar(String value, Class<?> cls, boolean nillable) {
        JVar var;
        if (nillable) {
            var = method.body().decl(model._ref(cls), "value" + varCount++, JExpr._null());
            JConditional cond = method.body()._if(xsrVar.invoke("isXsiNil").not());
           
            JInvocation invocation = xsrVar.invoke(value);
            cond._then().assign(var, invocation);
        } else {
            var = method.body().decl(model._ref(cls), "value" + varCount++, xsrVar.invoke(value));
        }
       
        return var;
View Full Code Here

Examples of com.sun.codemodel.JConditional

        JBlock loop = b._while(depthVar.gte(targetDepthVar.minus(JExpr.lit(1)))).body();
       
        b = loop._if(event.eq(JExpr.lit(XMLStreamConstants.START_ELEMENT)))._then();

       
        JConditional ifDepth = b._if(depthVar.eq(targetDepthVar));
       
        writeElementReader(elements, ifDepth._then(), false);
       
        if (allowUnknown) {
            writeElementReader(buildContext.getGlobalElements(), ifDepth._else(), true);
        }
       
        JConditional ifHasNext = loop._if(xsrVar.invoke("hasNext"));
        ifHasNext._then().assign(event, xsrVar.invoke("next"));
        ifHasNext._then().assign(depthVar, xsrVar.invoke("getDepth"));
        ifHasNext._else()._break();
    }
View Full Code Here

Examples of com.sun.codemodel.JConditional

        b = loop.body();
        JVar attName = b.decl(model._ref(String.class), "attName", xsrVar.invoke("getAttributeLocalName").arg(var));
        JVar attNs = b.decl(model._ref(String.class), "attNs", xsrVar.invoke("getAttributeNamespace").arg(var));
        JVar attValue = b.decl(model._ref(String.class), "attValue", xsrVar.invoke("getAttributeValue").arg(var));
       
        JConditional cond = null;
       
        for (Map.Entry<QName, AttributeParserBuilderImpl> e : attributes.entrySet()) {
            QName name = e.getKey();
            AttributeParserBuilderImpl builder = e.getValue();
           
            JExpression localInv = attName.eq(JExpr.lit(name.getLocalPart()));
            String ns = name.getNamespaceURI();
            JExpression nsInv = JExpr.lit(name.getNamespaceURI()).eq(attNs);
           
            if (ns.equals("")) {
                nsInv = nsInv.cor(attNs.eq(JExpr._null()));
            }
           
            JExpression qnameCompare = localInv.cand(nsInv);

            if (cond == null) {
                cond = b._if(qnameCompare);
            } else {
                cond = cond._else()._if(qnameCompare);
            }
           
            JMethod nextMethod = builder.getMethod();
           
            JInvocation invocation = JExpr.invoke(nextMethod).arg(xsrVar).arg(rtContextVar);
            for (JVar v : builder.variables) {
                invocation.arg(v);
            }
           
            nextMethod.param(model._ref(String.class), "_attValue");
            invocation.arg(attValue);
           
            nextMethod.body().add(builder.codeBlock);
           
            if (root && builder.returnType != null) {
                cond._then()._return(invocation);
            } else {
                cond._then().add(invocation);
            }
           
            // TODO: throw exception if unknown elements are encountered and allowUnknown == false
            builder.write();
        }
View Full Code Here

Examples of com.sun.codemodel.JConditional

    private void writeXsiChecks(JBlock b) {
        if(getXsiTypes().isEmpty())
            return; // no @xsi:type to look for.

        JVar xsiType = b.decl(model._ref(QName.class), "xsiType", xsrVar.invoke("getXsiType"));
        JConditional cond = b._if(xsiType.ne(JExpr._null()));
       
        writeXsiChecks(cond._then(), xsiType);
    }
View Full Code Here

Examples of com.sun.codemodel.JConditional

       
        writeXsiChecks(cond._then(), xsiType);
    }

    private void writeXsiChecks(JBlock b, JVar xsiType) {
        JConditional xsiCond = null;
       
        for (Map.Entry<QName, ElementParserBuilderImpl> e : getXsiTypes().entrySet()) {
            QName name = e.getKey();
           
            ElementParserBuilderImpl builder = e.getValue();
           
            JExpression localInv = xsiType.invoke("getLocalPart").eq(JExpr.lit(name.getLocalPart()));
            String ns = name.getNamespaceURI();
            JExpression nsInv = JExpr.lit(name.getNamespaceURI()).eq(xsiType.invoke("getNamespaceURI"));
            if (ns.equals("")) {
                nsInv = nsInv.cor(xsiType.invoke("getNamespaceURI").eq(JExpr._null()));
            }
           
            JExpression qnameCompare = localInv.cand(nsInv);

            if (xsiCond == null) {
                xsiCond = b._if(qnameCompare);
            } else {
                xsiCond = xsiCond._else()._if(qnameCompare);
            }
           
            JBlock block = xsiCond._then();
           
            writeElementReader(builder, block, false);
           
            if (builder.returnType == null) {
                block._return();
View Full Code Here

Examples of com.sun.codemodel.JConditional

        }
    }

   
    private void writeElementReader(Map<QName, ElementParserBuilderImpl> els, JBlock b, boolean global) {
        JConditional cond = null;
       
        if (depth == 1 && !global && checkXsiTypes) {
            writeXsiChecks(b);
        }
       
        for (Map.Entry<QName, ElementParserBuilderImpl> e : els.entrySet()) {
            QName name = e.getKey();
            ElementParserBuilderImpl builder = e.getValue();
           
            JExpression localInv = xsrVar.invoke("getLocalName").eq(JExpr.lit(name.getLocalPart()));
            String ns = name.getNamespaceURI();
            JExpression nsInv = JExpr.lit(name.getNamespaceURI()).eq(xsrVar.invoke("getNamespaceURI"));
            if (ns.equals("")) {
                nsInv = nsInv.cor(xsrVar.invoke("getNamespaceURI").eq(JExpr._null()));
            }
           
            JExpression qnameCompare = localInv.cand(nsInv);

            if (cond == null) {
                cond = b._if(qnameCompare);
            } else {
                cond = cond._else()._if(qnameCompare);
            }
           
            JBlock block = cond._then();
           
            writeElementReader(builder, block, global);
        }
       
        for (Map.Entry<QName, ElementCall> e : elementCalls.entrySet()) {
            QName name = e.getKey();
            ElementCall call = e.getValue();
            ElementParserBuilderImpl builder = call.getElement();
           
            JExpression localInv = xsrVar.invoke("getLocalName").eq(JExpr.lit(name.getLocalPart()));
            String ns = name.getNamespaceURI();
            JExpression nsInv = JExpr.lit(name.getNamespaceURI()).eq(xsrVar.invoke("getNamespaceURI"));
            if (ns.equals("")) {
                nsInv = nsInv.cor(xsrVar.invoke("getNamespaceURI").eq(JExpr._null()));
            }
           
            JExpression qnameCompare = localInv.cand(nsInv);

            if (cond == null) {
                cond = b._if(qnameCompare);
            } else {
                cond = cond._else()._if(qnameCompare);
            }
           
            JBlock block = cond._then();
           
            JMethod nextMethod = builder.getMethod();
            JInvocation invocation = JExpr.invoke(nextMethod).arg(xsrVar).arg(rtContextVar);
            for (JExpression var : call.getVars()) {
                invocation.arg(var);
            }
            block.add(invocation);
            if (builder != this)
                builder.write();
        }
       
        if (anyElement != null) {
            JBlock anyBlock = b;
            if (cond != null) {
                anyBlock = cond._else().block();
            }
           
            writeElementReader(anyElement, anyBlock, false);
        }
    }
View Full Code Here

Examples of com.sun.codemodel.JConditional

    public ElementWriterBuilder newCondition(JExpression condition) {
        return newCondition(condition, objectVar.type());
    }
   
    public ElementWriterBuilder newCondition(JExpression condition, JType type) {
        JConditional conditional = currentBlock._if(condition);
        JBlock block = conditional._then();
       
        JMethod m = buildContext.getNextWriteMethod(writerClass);
        JVar newObjectVar = addBasicArgs(m,
            type, "_" + type.name().replaceAll("\\[", "").replace("]", ""));
View Full Code Here

Examples of com.sun.codemodel.JConditional

    public ElementWriterBuilder writeElement(QName name) {
        return writeElement(name, objectVar.type(), objectVar);
    }

    public ElementWriterBuilder writeElement(QName name, JExpression condition, JType type, JExpression var) {
        JConditional conditional = currentBlock._if(condition);
        JBlock block = conditional._then();
       
        return writeElement(name, type, var, block);
    }
View Full Code Here

Examples of com.sun.codemodel.JConditional

        return new AttributeWriterBuilder(this, name, m, newObjectVar);
    }

    public void writeNilIfNull() {
        JBlock ifBlock = currentBlock;
        JConditional cond2 = ifBlock._if(getObject().eq(JExpr._null()));
        JBlock nullBlock2 = cond2._then();
        nullBlock2.add(xswVar.invoke("writeXsiNil"));
        nullBlock2._return();
    }
View Full Code Here

Examples of com.sun.codemodel.JConditional

    }
   
    public void writeAs(Class cls, boolean nillable) {
        if (!cls.isPrimitive()) {
            JBlock block = currentBlock;
            JConditional cond = block._if(getObject().ne(JExpr._null()));
            JBlock newBlock = cond._then();
            setCurrentBlock(newBlock);
           
            writeAs(cls);
           
            if (nillable) {
                newBlock = cond._else();
                newBlock.add(xswVar.invoke("writeXsiNil"));
                setCurrentBlock(newBlock);
            }
            setCurrentBlock(block);
        } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.