1 5 package org.enhydra.ant.taskdefs; 6 7 import java.io.File ; 8 import java.util.ArrayList ; 9 import org.apache.tools.ant.BuildException; 10 import org.apache.tools.ant.taskdefs.Touch; 11 import org.apache.tools.ant.types.EnumeratedAttribute; 12 import org.enhydra.dods.Common; 13 14 36 public class DODS_XMLBuilder extends org.apache.tools.ant.taskdefs.Javac { 37 protected File domlFile = null; 38 protected File sourceoutDir = null; 39 protected String database = null; 40 protected boolean forceBuild = false; 41 protected boolean tablesOnly = false; 42 protected String configDir = null; 43 public static class BooleanAttribute extends EnumeratedAttribute { 44 45 48 public String [] getValues() { 49 return (new String [] {"yes", "no", "true", "false" }); 50 } 51 52 public BooleanAttribute() {} 53 } 54 public DODS_XMLBuilder() { 55 domlFile = null; 56 sourceoutDir = null; 57 tablesOnly = false; 58 } 59 60 64 public void execute() throws org.apache.tools.ant.BuildException { 65 66 try { 67 if (configDir != null) { 68 Common.setConfigDir(configDir); 69 } 70 71 } catch (Error e) { 72 throw new BuildException("path to dodsConf.xml must be valid"); 73 } 74 if (domlFile == null) { 75 throw new BuildException("doml attribute must be set!"); 76 } 77 if (sourceoutDir == null) { 78 throw new BuildException("outdir attribute must be set!"); 79 } 80 if (!sourceoutDir.isDirectory()) { 81 throw new BuildException("outdir must be a valid directory!"); 82 } 83 File domlTmp = null; 84 85 if (domlTmp == null) { 86 String s = domlFile.getAbsolutePath().toLowerCase(); 87 int i = s.indexOf(".doml"); 88 89 if (i > -1) { 90 domlTmp = new File (domlFile.getAbsolutePath().substring(0, i) 91 + ".uptodate"); 92 } else { 93 domlTmp = new File (domlFile.getAbsolutePath() + ".uptodate"); 94 } 95 } 96 boolean regen = !sourceoutDir.exists() || !domlTmp.exists() 97 || domlTmp.lastModified() < domlFile.lastModified(); 98 99 if (regen) { 100 (this).project.log("Regenerating DODS files from " + domlFile 101 + "... "); 102 } else { 103 (this).project.log(String.valueOf(((java.lang.Object ) (domlFile))) 104 + " up to date.", 105 2); 106 } 107 if (regen || forceBuild) { 108 109 java.util.ArrayList argsList = new ArrayList (); 110 111 argsList.add((new Boolean (tablesOnly)).toString()); 112 if (database != null) { 113 argsList.add(database); 114 } 115 try { 116 String dodsClassName = "org.enhydra.dods.trans.TransientXMLBuilderFactory"; 117 java.lang.reflect.Method m = null; 118 java.lang.Class c = null; 119 120 try { 121 c = java.lang.Class.forName(dodsClassName); 122 m = c.getMethod("main", new java.lang.Class [] { 123 String [].class 124 }); 125 } catch (java.lang.Exception e) { 126 ((java.lang.Throwable ) (e)).printStackTrace(); 127 throw new BuildException(((java.lang.Throwable ) (e))); 128 } 129 String args[] = (String []) argsList.toArray(((java.lang.Object []) ( 130 new String [argsList.size()]))); 131 132 if (m != null) { 133 m.invoke(((java.lang.Object ) (null)), 134 new java.lang.Object [] { 135 args 136 }); 137 } 138 } catch (java.lang.reflect.InvocationTargetException ite) { 139 ite.printStackTrace(); 140 throw new BuildException(((java.lang.Throwable ) (ite))); 141 } catch (java.lang.Exception e) { 142 ((java.lang.Throwable ) (e)).printStackTrace(); 143 throw new BuildException(((java.lang.Throwable ) (e))); 144 } 145 if (!tablesOnly) { 146 org.apache.tools.ant.taskdefs.Touch touch = new Touch(); 147 148 ((org.apache.tools.ant.ProjectComponent) (touch)).setProject((this).project); 149 touch.setFile(domlTmp); 150 touch.execute(); 151 } 152 } 153 } 154 155 159 public void setDoml(File domlFile) { 160 this.domlFile = domlFile; 161 } 162 163 168 public void setOutdir(File sourceout) { 169 sourceoutDir = sourceout; 170 } 171 172 177 public void setDatabase(String database) { 178 this.database = database; 179 } 180 181 185 public void setTablesonly(boolean isTablesOnly) { 186 tablesOnly = isTablesOnly; 187 } 188 189 193 public void setForce(String force) { 194 forceBuild = (new Boolean (force)).booleanValue(); 195 } 196 197 201 public String getConfigDir() { 202 return configDir; 203 } 204 205 208 public void setConfigDir(String string) { 209 configDir = string; 210 } 211 } 212 | Popular Tags |