/* * Created on May 21, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package CDBuilder.couplingSyntaxEditor.convertToXML; import java.io.CharArrayReader; import java.io.PushbackReader; import java.util.LinkedList; import CDBuilder.couplingSyntaxEditor.cseScanner; /** * * @author Sherwin Sim and Lucie Zhao * @version 1 May - Aug 2003 * */ public class containerCollect { private LinkedList bacon; private char[] harry = new char[100]; private String top = "[top]"; private String link = "Link"; private String components = "components"; private String in = "in"; private String out = "out"; public static boolean runOnce; public containerCollect() { runOnce = false; } public LinkedList collect(CharArrayReader scanner) { boolean done = false; boolean finishedScan = false; boolean finishContainerfill = false; boolean detailScan = false; boolean possible = false; String typeOfCont = null; String typeOfItem = null; int counter = 0; char test; bacon = new LinkedList(); String temp = null; PushbackReader scanner2 = new PushbackReader(scanner); try { while(!finishedScan) { test =(char)scanner2.read(); if( test == (char)cseScanner.EOF) finishedScan = true; if( test == '%') { detailScan = true; counter = 0; typeOfCont = "comment"; } if( test == ']') { harry[counter] = test; if( harry[0] =='[' && harry[counter] ==']') { temp = new String(harry, 1,counter-1); typeOfCont = "container"; counter = 0; detailScan = true; finishContainerfill = false; while( test != '\n') { test = (char)scanner2.read(); } } } if(!Character.isWhitespace(test) && detailScan != true) { harry[counter] = test; counter++; } if(detailScan == true) { detailScan = false; if(typeOfCont == "container") { Container cont = new Container(temp); while(!finishContainerfill) { test = (char)scanner2.read(); if(test =='[' || test == (char)cseScanner.EOF) { finishContainerfill = true; //scanner2.unread(test); //scanner.; } if(test ==':' || test =='\n' || test == '%' ) { String checker = new String(harry, 0, counter); if(checker.compareTo(link)==0) { possible = true; counter = 0; typeOfItem = "Link"; } else if(checker.compareTo(components) ==0) { possible = true; counter = 0; typeOfItem = "components"; } else if(checker.compareTo(in) == 0) { possible = true; counter = 0; typeOfItem = "in"; } else if(checker.compareTo(out) == 0) { possible = true; counter = 0; typeOfItem = "out"; } else if(test == ('%')) { possible = true; counter = 0; typeOfItem = "comment"; } else if (test == ':') { possible = true; counter = 0; typeOfItem = checker; } else { counter = 0; harry = new char[100]; possible = false; } } else { if(!Character.isWhitespace(test)) { harry[counter] = test; counter++; } } if(possible == true) { boolean collectingInfo = true; harry = new char[100]; while (collectingInfo) { test = (char)scanner2.read(); if(test != '\n') { harry[counter] = test; counter++; } else { collectingInfo = false; String newData = new String(harry, 0, counter); CouplingObject newObj = new CouplingObject(newData,typeOfItem); cont.addItem(newObj); harry = new char[100]; counter = 0; } } possible = false; } } if(finishContainerfill == true) bacon.add(cont); } if(typeOfCont == "comment") { boolean commentCollect = true; harry = new char[100]; while(commentCollect) { test = (char)scanner2.read(); if(test !='\n') { harry[counter] = test; counter++; } else { commentCollect = false; String commentInfo = new String(harry, 0, counter); CouplingObject commentObj = new CouplingObject(commentInfo,"comment"); bacon.add(commentObj); harry= new char[100]; counter = 0; } } } } } } finally { System.out.println(bacon); return bacon; } } }