Package org.jitterbit.integration.structure.crom

Examples of org.jitterbit.integration.structure.crom.CROM


  {
    DatabaseTarget dbTarget=null;
    String dataFileName=params.dataFile;
    boolean success = false;
    try {
          CROM root = DbUtils.createCromTree(params.jtrFile);
          CROM table=root;
          boolean bIsFlat=table.isFlat();
          if(bIsFlat)table=root.getChild(0);
      dbTarget=new DatabaseTarget(params);
      dbTarget.writeLog("Read structure file: ", params.jtrFile);
          dbTarget.defineBeginEndQuote(root);
          dbTarget.bIncludeNulls=params.includeNulls;
            OutputStreamWriter targetDataFile=null;
            TextDocReader reader=null;
          try {
              dbTarget.runPreTargetStatement(params);
            targetDataFile= new OutputStreamWriter(new FileOutputStream(dataFileName+".final"),"UTF-8");//new RandomAccessFile(new File(dataFileName+".final"),"rw");
          reader=new TextDocReader(new File(dataFileName), "UTF-8");
          dbTarget.writeLog("Processing target file: ", dataFileName);
          JbNode jbRoot=reader.parse_all();
          List<JbNode> rows=jbRoot.m_children;
              for(JbNode row: rows){
                String line=row.getStr(reader);
                  char override=dbTarget.parseCsvValues(line);

                  if(!bIsFlat){
                      String id=dbTarget.values.get(0);
                      table=DbUtils.findTable(id, table);
                  }

                  dbTarget.loadColumns(table, bIsFlat);
                  CROM identity=dbTarget.preWriteToDb(table);
                  if(dbTarget.writeToDb(table, override) != MODE.INSERT)identity=null;
                  if(identity!=null)dbTarget.postWriteToDb(table, identity);
                  table.writeDbRecord(targetDataFile);
              }
              success = true;
View Full Code Here


    if(m_parent!=null)m_parent.m_children.add(this);
  }

  public JbNode getChild(CROM childCrom0){
    for(JbNode child: m_children){
      CROM childCrom=child.getCrom();
      if(childCrom==null)return null;
      if(childCrom==childCrom0)return child;
    }
    return null;
  }
View Full Code Here

    return null;
  }

  public JbNode getChild(String name){
    for(JbNode child: m_children){
      CROM childCrom=child.getCrom();
      if(childCrom==null)continue;
      if(childCrom.getName().equals(name))return child;
    }
    return null;
  }
View Full Code Here

    }
    return null;
  }

  JbNode getParent(CROM crom0, CROM newLoopCrom){
    CROM parentCrom0=getCrom();
    assert(parentCrom0!=null);
    CROM parentCrom=crom0.getParent();
    Stack<CROM>parentCromStack=new Stack<CROM>();
    while(parentCrom!=parentCrom0){
      parentCromStack.push(parentCrom);
      parentCrom=parentCrom.getParent();
    }
    JbNode parent=this;
    while(parentCromStack.size()>0){
      CROM crom=parentCromStack.pop();
      JbNode node=parent.getChild(crom);
      if(node==null){
        node=new JbNode(parent, crom, 0L, 0L);
      }
      if(crom.isLoopNode()){
        int nChildren=node.m_children.size();
        if(nChildren==0 || crom==newLoopCrom){
          node=new JbNode(parent, 0L, 0L);
        }
      }
View Full Code Here

    m_id=crom;
  }


  void addToStringBuilder(DocParser reader, StringBuilder sb, String indent) throws Exception {
    CROM crom=getCrom();
    if(crom!=null && crom.isValueLeaf())return;
    sb.append(indent).append(toString(reader));
    sb.append('\n');
    for(JbNode child: m_children){
      child.addToStringBuilder(reader, sb, indent+" ");
    }
View Full Code Here

    }
  }

  public String toString(DocParser parser) throws Exception {
    StringBuilder sb=new StringBuilder();
    CROM crom=null;
    boolean skipDisplaayValues=false;
    if(m_id instanceof Integer){
      crom=(CROM)m_parent.m_id;
      if(crom!=null){
        if(crom.isOneOfNode()){
          sb.append("OneOf");
        }
        else {
          sb.append(crom.getName());
        }
      }
      sb.append("[").append(m_id).append("] ");
    }
    else if(m_id instanceof CROM){
      crom=(CROM)m_id;
      if(crom.isValueLeaf()){
        sb.append("Value: ");
      }
      else {
        skipDisplaayValues=crom.isLoopNode();
        String name=crom.isOneOfNode()?"OneOf":crom.getName();
        if(name.isEmpty())name="_DbRoot";
        String marker="";
        if(crom.isAtLeastOneNode())marker="+";
        else if(crom.isCollectionNode())marker="*";
        else if(crom.isOptionalNode())marker="?";
        sb.append("[").append(name).append(marker).append("] ");
      }
    }
    else if(m_id instanceof String){
      return parser.getStr(m_pos, m_length);
View Full Code Here

  public void doSearch(List<Object>list, String searchString_lowercase, DocReader reader) throws IOException {
    if(reader==null)return;
    List<String> values=reader.parser.splitValues(this, false);

    CROM crom_element=getCrom();

    Iterator<CROM> it=crom_element.getChildren().iterator();
    CROM vaCrom=CROM.getNextValueAttribute(it);

    if (values != null && !values.isEmpty()) {
            for (String s : values) {
                if (vaCrom == null)break;
                if (s!= null && s.toLowerCase().indexOf(searchString_lowercase) >= 0){
View Full Code Here

        sb.append(k).append(';');
      }
      sb.append("]");
    }
    else if(m_id instanceof CROM){
      CROM crom=(CROM)m_id;
      if(crom.isValueLeaf()){
        sb.append("Value[").append(crom.getParent().getName()).append("]");
      }
      else {
        sb.append("DTD[").append(crom.getName()).append("]");
      }
    }
    else if(m_id instanceof String){
      sb.append("Node[").append((String)m_id).append("]");
    }
View Full Code Here

  public void convertSubElementsToXmlDataNode(JbNode jbNode, CROM_Tree crom_tree, StringBuilder sb) {
    NodePatternMatchMaker mm=null;
    try {
      int nChildren=jbNode.m_children.size();
      CROM crom=jbNode.getCrom();
      if(crom==null){
        throw new Exception("convert child nodes to xml subelements failed. Cannot find the structure node for the node.");
      }
      mm=getNodePatternMatchMaker(crom, crom_tree);
      CROM[] cromArray=mm.findCroms(jbNode.m_children, this, jbNode, sb);
View Full Code Here

      String xsiType=node0.getXmlAttributeValue(this, "xsi:type");
      if(!xsiType.isEmpty()){
                crom0=findDerivedType(crom0, crom_tree, xsiType);
      }
    }
    CROM parentCrom0=node0.m_parent.getCrom();
    if(parentCrom0==null){
      throw new RuntimeException("failed to move, the parent CROM is not yet defined, the parent is "+node0.m_parent.getName()+", the target crom is "+crom0);
    }
    Stack<CROM> parentCromStack=new Stack<CROM>();
    assert(parentCrom0.isAncestorOf(crom0));
    CROM parentCrom=crom0.getParent();
    while(parentCrom!=null && parentCrom!=parentCrom0){
      parentCromStack.push(parentCrom);
      parentCrom=parentCrom.getParent();
    }
    JbNode parent=node0.m_parent;
    JbNode parentSaved=parent;

    while(parentCromStack.size()>0){
      CROM crom=parentCromStack.pop();
      JbNode jbNode_dtd=parent.getChild(crom);
      if(jbNode_dtd==null){
        jbNode_dtd=new JbNode(parent, crom, 0L, 0L); // dtd
      }
      if(crom.isLoopNode()){
        JbNode instance;
        int i=jbNode_dtd.m_children.size();
        if(i==0
          ||crom.isSubstitutionGroupHead()
          ||crom.isDerivedTypeHolder()
          ){
          instance=new JbNode(jbNode_dtd, 0L, 0L); // add instance
        }
        else {
          instance=jbNode_dtd.m_children.get(i-1);
          CROM child=parentCromStack.size()>0? parentCromStack.peek(): crom0;
          if(crom.isOneOfNode()){
            if(child!=null && instance.getChild(child)==null){
              instance=new JbNode(jbNode_dtd, 0L, 0L);
            }
          }
View Full Code Here

TOP

Related Classes of org.jitterbit.integration.structure.crom.CROM

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.