Package com.sun.codemodel

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


        }
    }

   
    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

    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

    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

        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

    }
   
    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

    g.getEvalBlock().add(topSub);

    addProtectedBlock(g, sub, body, inputVariables, workspaceJVars, false);
   
   
    JConditional jc = g.getEvalBlock()._if(complexWriter.invoke("ok").not());
   
    jc._then().add(complexWriter.invoke("reset"));   
    //jc._then().directStatement("System.out.println(\"debug : write ok fail!, inIndex = \" + inIndex);");
    jc._then()._return(JExpr.FALSE);
   
    //jc._else().directStatement("System.out.println(\"debug : write successful, inIndex = \" + inIndex);");   
   
    g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", registeredNames[0]));
View Full Code Here

      if(e != null){
        // if at least one expression must be checked, set up the conditional.
        returnValueType = returnValue.type.toBuilder().setMode(DataMode.OPTIONAL).build();
        out = g.declare(returnValueType);
        e = e.eq(JExpr.lit(0));
        JConditional jc = sub._if(e);
        jc._then().assign(out.getIsSet(), JExpr.lit(0));
        sub = jc._else();
      }
    }

    if(out == null) out = g.declare(returnValueType);
View Full Code Here

    public HoldingContainer visitIfExpression(IfExpression ifExpr, ClassGenerator<?> generator) throws RuntimeException {
      JBlock local = generator.getEvalBlock();

      HoldingContainer output = generator.declare(ifExpr.getMajorType());

      JConditional jc = null;
      JBlock conditionalBlock = new JBlock(false, false);
      IfCondition c = ifExpr.ifCondition;

      HoldingContainer holdingContainer = c.condition.accept(this, generator);
      if (jc == null) {
        if (holdingContainer.isOptional()) {
          jc = conditionalBlock._if(holdingContainer.getIsSet().eq(JExpr.lit(1)).cand(holdingContainer.getValue().eq(JExpr.lit(1))));
        } else {
          jc = conditionalBlock._if(holdingContainer.getValue().eq(JExpr.lit(1)));
        }
      } else {
        if (holdingContainer.isOptional()) {
          jc = jc._else()._if(holdingContainer.getIsSet().eq(JExpr.lit(1)).cand(holdingContainer.getValue().eq(JExpr.lit(1))));
        } else {
          jc = jc._else()._if(holdingContainer.getValue().eq(JExpr.lit(1)));
        }
      }

      HoldingContainer thenExpr = c.expression.accept(this, generator);
      if (thenExpr.isOptional()) {
        JConditional newCond = jc._then()._if(thenExpr.getIsSet().ne(JExpr.lit(0)));
        JBlock b = newCond._then();
        b.assign(output.getHolder(), thenExpr.getHolder());
        //b.assign(output.getIsSet(), thenExpr.getIsSet());
      } else {
        jc._then().assign(output.getHolder(), thenExpr.getHolder());
      }

      HoldingContainer elseExpr = ifExpr.elseExpression.accept(this, generator);
      if (elseExpr.isOptional()) {
        JConditional newCond = jc._else()._if(elseExpr.getIsSet().ne(JExpr.lit(0)));
        JBlock b = newCond._then();
        b.assign(output.getHolder(), elseExpr.getHolder());
        //b.assign(output.getIsSet(), elseExpr.getIsSet());
      } else {
        jc._else().assign(output.getHolder(), elseExpr.getHolder());
      }
View Full Code Here

        generator.getEvalBlock().add(writer.invoke("setPosition").arg(outIndex));
        String copyMethod = inputContainer.isSingularRepeated() ? "copyAsValueSingle" : "copyAsValue";
        generator.getEvalBlock().add(inputContainer.getHolder().invoke(copyMethod).arg(writer));
        if (e.isSafe()) {
          HoldingContainer outputContainer = generator.declare(Types.REQUIRED_BIT);
          JConditional ifOut = generator.getEvalBlock()._if(writer.invoke("ok"));
          ifOut._then().assign(outputContainer.getValue(), JExpr.lit(1));
          ifOut._else().assign(outputContainer.getValue(), JExpr.lit(0));
          return outputContainer;
        }
      } else {
        String setMethod = e.isSafe() ? "setSafe" : "set";

        String isSafeMethod = "isSafe";

        JInvocation setMeth;
        if (Types.usesHolderForGet(inputContainer.getMajorType())) {
          setMeth = vv.invoke("getMutator").invoke(setMethod).arg(outIndex).arg(inputContainer.getHolder());
        } else {
          setMeth = vv.invoke("getMutator").invoke(setMethod).arg(outIndex).arg(inputContainer.getValue());
        }

        if (e.isSafe()) {
          HoldingContainer outputContainer = generator.declare(Types.REQUIRED_BIT);
          block.assign(outputContainer.getValue(), JExpr.lit(1));
          if (inputContainer.isOptional()) {
            // block._if(vv.invoke("getMutator").invoke(setMethod).arg(outIndex).not())._then().assign(outputContainer.getValue(),
            // JExpr.lit(0));
            JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
            block = jc._then();
            jc._else()._if(vv.invoke("getMutator").invoke(isSafeMethod).arg(outIndex).not())._then()
                .assign(outputContainer.getValue(), JExpr.lit(0));
          }
          block._if(setMeth.not())._then().assign(outputContainer.getValue(), JExpr.lit(0));
          return outputContainer;
        } else {
          if (inputContainer.isOptional()) {
            // block.add(vv.invoke("getMutator").invoke(setMethod).arg(outIndex));
            JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
            block = jc._then();
          }
          block.add(setMeth);
        }

      }
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JConditional

Copyright © 2018 www.massapicom. 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.