1 23 package org.enhydra.kelp.common.xmlc; 24 25 import org.enhydra.xml.xmlc.XMLCException; 27 28 import org.enhydra.tool.common.FileUtil; 30 import org.enhydra.tool.common.PathHandle; 31 32 import org.enhydra.kelp.common.AbstractNodeBuilder; 34 import org.enhydra.kelp.common.Constants; 35 import org.enhydra.kelp.common.Writer; 36 import org.enhydra.kelp.common.event.WriteListener; 37 import org.enhydra.kelp.common.map.Mapper; 38 import org.enhydra.kelp.common.node.OtterTextFileNode; 39 import org.enhydra.kelp.common.node.OtterImageFileNode; 40 import org.enhydra.kelp.common.node.OtterProject; 41 import org.enhydra.kelp.common.node.OtterNode; 42 import org.enhydra.kelp.common.node.OtterXMLCNode; 43 44 45 import java.io.IOException ; 47 import java.io.PrintWriter ; 48 import java.io.File ; 49 import java.util.ResourceBundle ; 50 import java.text.MessageFormat ; 51 52 public class XMLCNodeBuilder extends AbstractNodeBuilder { 53 static ResourceBundle res = 54 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 56 66 public XMLCNodeBuilder(WriteListener[] listeners) { 67 super(listeners); 68 } 69 70 public XMLCNodeBuilder(WriteListener listener, boolean buffer) { 71 super(listener, buffer); 72 } 73 74 75 79 public void buildImpl() { 80 if (getNodes().length >= 1) { 81 makeSelected(); 82 } 83 } 84 85 private void makeSelected() { 87 int allCount = getNodes().length; 88 int selectCount = 0; 89 double selectIndex = 0.0; 90 XMLCRunner runner = new XMLCRunner(); 91 92 refreshProgress(5, res.getString("XMLC_starting_")); 93 runner.setTraceWriter(getEchoWriter()); 94 for (int i = 0; i < allCount; i++) { 95 OtterXMLCNode xmlcNode = null; 96 97 xmlcNode = (OtterXMLCNode) getNodes()[i]; 98 if (xmlcNode.isSelected()) { 99 selectCount++; 100 } 101 } 102 for (int i = 0; i < allCount; i++) { 103 OtterXMLCNode xmlcNode = null; 104 105 xmlcNode = (OtterXMLCNode) getNodes()[i]; 106 xmlcNode.setException(null); 107 if (!isFresh()) { 108 break; 109 } 110 try { 111 if (xmlcNode.isSelected() && isFresh()) { 112 File sourceDoc = null; 113 PathHandle sourcePath = null; 114 String message = new String (); 115 int progValue = 0; 116 Integer [] counts = new Integer [0]; 117 118 selectIndex++; 119 progValue = (int) (5.0 120 + (80.0 121 * (selectIndex / selectCount))); 122 counts = new Integer [2]; 123 counts[0] = new Integer ((int) selectIndex); 124 counts[1] = new Integer (selectCount); 125 message = 126 MessageFormat.format(res.getString("XMLC_processing"), 127 counts); 128 refreshProgress(progValue, message); 129 sourcePath = 130 PathHandle.createPathHandle(xmlcNode.getMetaDataHandler().getInputDocument()); 131 if (sourcePath.getFile().exists()) { 132 if (isEcho()) { 133 getEchoWriter().println(res.getString("Compiling_")); 134 getEchoWriter().println(Constants.TAB4 135 + sourcePath.getPath()); 136 } 137 xmlcNode.preCompile(); 138 runner.setNode(xmlcNode); 139 runner.compile(); 140 } else { 141 if (isEcho()) { 142 getEchoWriter().println(res.getString("Source_document_not") 143 + sourcePath.getPath()); 144 } 145 } 146 } 147 } catch (XMLCException e) { 148 e.printStackTrace(); 149 xmlcNode.setException(e); 150 if (isEcho()) { 151 getEchoWriter().println(new String ()); 152 } 153 } catch (Throwable e) { 154 xmlcNode.setException(e); 155 if (isEcho()) { 156 getEchoWriter().println(new String ()); 157 } 158 } 159 } 160 if (isFresh()) { 161 refreshProgress(90, res.getString("XMLC_gathering")); 162 if (isEcho()) { 163 printResults(); 164 } 165 printExceptions(); 166 refreshProgress(95, res.getString("XMLC_complete")); 167 if (isEcho()) { 168 getEchoWriter().println(new String ()); 169 getEchoWriter().println(res.getString("_XMLC_complete_")); 170 getEchoWriter().println(new String ()); 171 } 172 } else { 173 refreshProgress(90, res.getString("XMLC_interrupted")); 174 printExceptions(); 175 getEchoWriter().println(new String ()); 176 getEchoWriter().println(res.getString("_XMLC_interrupted_")); 177 getEchoWriter().println(new String ()); 178 } 179 refreshProgress(100, res.getString("XMLC_complete")); 180 } 181 182 186 public void printResults() { 187 int eCount = 0; 188 int totalCount = getNodes().length; 189 int selectCount = 0; 190 PathHandle path = null; 191 192 getEchoWriter().println(new String ()); 193 getEchoWriter().println(res.getString("Gathering_results_")); 194 for (int i = 0; i < totalCount; i++) { 195 if (getNodes()[i].isSelected() 196 && getNodes()[i].getException() != null) { 197 eCount++; 198 } 199 } 200 sleepInSeconds(0.5); 201 for (int i = 0; i < totalCount; i++) { 202 if (getNodes()[i].isSelected()) { 203 selectCount++; 204 } 205 } 206 if (eCount < selectCount) { 207 getEchoWriter().println(new String ()); 208 getEchoWriter().println(res.getString("New_java_files_")); 209 for (int i = 0; i < totalCount; i++) { 210 OtterXMLCNode xmlcNode = (OtterXMLCNode) getNodes()[i]; 211 212 sleepInSeconds(0.1); 213 if (!isFresh()) { 214 break; 215 } 216 if (xmlcNode.isSelected() && xmlcNode.isNewJavaFound()) { 217 xmlcNode.replaceGeneratedSource(xmlcNode.getMetaDataHandler().getRecompilation()); 218 path = 219 PathHandle.createPathHandle(xmlcNode.getMetaDataHandler().getJavaClassSource()); 220 getEchoWriter().println(Constants.TAB2 + path.getPath()); 221 } 222 } 223 } 224 sleepInSeconds(0.1); 225 } 226 227 } 228 | Popular Tags |