1 package org.apache.ojb.broker.ant; 2 3 17 18 import java.io.File ; 19 import java.io.FileWriter ; 20 21 import org.apache.ddlutils.io.DataDtdWriter; 22 import org.apache.ddlutils.model.Database; 23 import org.apache.ojb.broker.metadata.DescriptorRepository; 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.Task; 27 28 34 public class WriteDtdToFileCommand extends Command 35 { 36 37 private File _outputFile; 38 39 44 public void setOutputFile(File outputFile) 45 { 46 _outputFile = outputFile; 47 } 48 49 52 public boolean isRequiringModel() 53 { 54 return true; 55 } 56 57 60 public void execute(Task task, Database dbModel, DescriptorRepository objModel) throws BuildException 61 { 62 if (_outputFile == null) 63 { 64 throw new BuildException("No output file specified"); 65 } 66 if (_outputFile.exists() && !_outputFile.canWrite()) 67 { 68 throw new BuildException("Cannot overwrite output file "+_outputFile.getAbsolutePath()); 69 } 70 71 try 72 { 73 FileWriter outputWriter = new FileWriter (_outputFile); 74 DataDtdWriter dtdWriter = new DataDtdWriter(); 75 DdlUtilsDataHandling handling = new DdlUtilsDataHandling(); 76 77 handling.setModel(dbModel, objModel); 78 handling.getDataDTD(outputWriter); 79 outputWriter.close(); 80 task.log("Written DTD to "+_outputFile.getAbsolutePath(), Project.MSG_INFO); 81 } 82 catch (Exception ex) 83 { 84 throw new BuildException("Failed to write to output file "+_outputFile.getAbsolutePath(), ex); 85 } 86 } 87 } 88 | Popular Tags |