1 23 24 package org.enhydra.xml.xmlc.driver; 25 import java.io.File ; 26 27 import org.enhydra.xml.driver.TestCaseBase; 28 import org.enhydra.xml.xmlc.XMLCFactory; 29 import org.enhydra.xml.xmlc.XMLCStdFactory; 30 import org.enhydra.xml.xmlc.XMLObject; 31 import org.enhydra.xml.xmlc.deferredparsing.XMLCDeferredParsingFactory; 32 33 35 42 public class TestDOMSource { 43 44 private TestCaseBase fTest; 45 46 47 private XmlcTestParams fParams; 48 49 50 File fInputFile; 51 String fUnqualClassName; 52 Class fImpls; 53 54 59 private XMLCFactory fFactory; 60 private String fClassName; 61 62 67 public TestDOMSource(TestCaseBase test, 68 XmlcTestParams params, 69 File inputFile, 70 String unqualClassName, 71 Class impls) { 72 fTest = test; 73 fParams = params; 74 fInputFile = inputFile; 75 fUnqualClassName = unqualClassName; 76 fClassName = fTest.getTestPackage() + "." + unqualClassName; 77 fImpls = impls; 78 } 79 80 81 public File getInputFile() { 82 return fInputFile; 83 } 84 85 89 private void compile() { 90 File outFile = fTest.getResultFile(fUnqualClassName, 91 XmlcTestCaseBase.COMPILE_OUTPUT_EXT); 92 File expectFile = fTest.getExpectedFile(fUnqualClassName, 93 XmlcTestCaseBase.COMPILE_OUTPUT_EXT); 94 95 ExecXmlc execXmlc = new ExecXmlc(fTest, fParams); 96 execXmlc.addOpt(ExecXmlc.OPT_CLASS, fClassName); 97 if (fImpls != null) { 98 execXmlc.addOpt(ExecXmlc.OPT_IMPLEMENTS, 99 fImpls.getName()); 100 } 101 execXmlc.addOpt(ExecXmlc.OPT_DEST_DIR, fTest.getClassRoot()); 102 execXmlc.addClassPath(fTest.getClassRoot()); 103 execXmlc.setSrcFile(fInputFile); 104 execXmlc.compile(outFile); 105 fTest.getDiffer().diff(expectFile, outFile); 106 } 107 108 111 public synchronized XMLObject create() { 112 if (fFactory == null) { 113 compile(); 114 115 if (fParams.getIsDeferredParsing()) { 116 java.io.PrintWriter writer 117 = new java.io.PrintWriter (new java.io.OutputStreamWriter (System.err)); 118 org.enhydra.xml.xmlc.StreamXMLCLogger logger 119 = new org.enhydra.xml.xmlc.StreamXMLCLogger(writer, writer, writer); 120 121 fFactory = new XMLCDeferredParsingFactory (null, fTest.createClassLoader(), null); } else { 123 fFactory = new XMLCStdFactory(fTest.createClassLoader(), null); } 125 } 126 return fFactory.create(fClassName); 127 } 128 } 129 | Popular Tags |