1 23 package org.enhydra.kelp.common.dods; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 import org.enhydra.tool.common.ToolException; 28 import org.enhydra.tool.common.FileUtil; 29 import org.enhydra.tool.common.PathHandle; 30 import org.enhydra.tool.common.event.ProgressListener; 31 import org.enhydra.tool.archive.ArchiveException; 32 import org.enhydra.tool.archive.ArchiveTool; 33 import org.enhydra.tool.archive.JarPlan; 34 import org.enhydra.tool.archive.WarPlan; 35 36 import org.enhydra.kelp.KelpInfo; 38 import org.enhydra.kelp.common.AbstractEchoGenerator; 39 import org.enhydra.kelp.common.Constants; 40 import org.enhydra.kelp.common.PathUtil; 41 import org.enhydra.kelp.common.PropUtil; 42 import org.enhydra.kelp.common.event.WriteEvent; 43 import org.enhydra.kelp.common.event.WriteListener; 44 import org.enhydra.kelp.common.node.OtterProject; 45 import org.enhydra.kelp.common.node.OtterNode; 46 import org.enhydra.kelp.common.node.OtterNodeFactory; 47 import org.enhydra.kelp.common.node.OtterTextFileNode; 48 import org.enhydra.kelp.common.node.OtterFolderNode; 49 import org.enhydra.kelp.common.node.OtterTemplateNode; 50 51 import java.awt.Component ; 53 import java.awt.Window ; 54 import java.io.File ; 55 import java.util.StringTokenizer ; 56 import java.util.ResourceBundle ; 57 import javax.swing.JOptionPane ; 58 import org.enhydra.kelp.common.AbstractEchoBuilder; 59 60 public class DodsGenerate extends AbstractEchoBuilder { 62 63 static ResourceBundle res = 64 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 66 private OtterNode[] inputNodes = null; 68 private Window owner = null; 69 private boolean doneDialog = false; 70 71 public static void preBuild(Object source, OtterProject project, 72 WriteListener listener) { 73 PathHandle path = null; 74 WriteEvent event = null; 75 76 path = PathHandle.createPathHandle(project.getDeployRootPath()); 77 if (!path.isDirectory()) { 78 path.getFile().mkdirs(); 79 event = new WriteEvent(source, WriteEvent.OUTPUT, 80 "Created directory: " + path.getPath()); 81 listener.onWrite(event); 82 } 83 } 84 85 public DodsGenerate() { 86 super(null); 87 } 88 89 public DodsGenerate(WriteListener listener) { 90 super(listener); 91 } 92 93 public DodsGenerate(WriteListener listener, boolean buffer) { 94 super(listener, buffer); 95 } 96 97 public void setInputNodes(OtterNode[] n) { 98 inputNodes = n; 99 } 100 101 public OtterNode[] getInputNodes() { 102 return inputNodes; 103 } 104 105 public void generate() { 106 107 Generator generator = null; 108 109 110 generator = new Generator(getWriteListener()); 111 generator.setProject(getProject()); 112 generator.setEcho(isEcho()); 113 generator.buildInCurrentThread(); 114 115 } 116 117 121 public void buildImpl() { 122 123 Exception ex = null; 124 125 try { 126 echo(new String ()); 127 refreshProgress(5, res.getString("Generate_starting")); 128 echo(res.getString("_Generate_starting")); 129 130 if (isFresh()) { 131 generate(); 132 } 133 echo("--- Kelp Generator finished --- "); 134 } catch (Exception e) { 135 ex = e; 136 echo(ex); 137 } 138 refreshProgress(100, new String ()); 139 if (isDoneDialog()) { 140 StringBuffer buf = new StringBuffer (); 141 142 if (ex == null) { 143 buf.append("Generate Complete"); 144 } else { 145 buf.append("Exception during generate:\n"); 146 if (ex.getMessage() == null) { 147 buf.append(ex.toString()); 148 } else { 149 buf.append(ex.getMessage()); 150 } 151 buf.append("\n"); 152 buf.append("See messages for more information.\n"); 153 } 154 JOptionPane.showMessageDialog(getOwner(), buf.toString()); 155 } 156 } 157 158 160 protected void setOwner(Window w) { 161 owner = w; 162 } 163 164 protected Window getOwner() { 165 return owner; 166 } 167 168 protected boolean isDoneDialog() { 169 boolean canDone = doneDialog; 170 171 if (getOwner() == null) { 172 canDone = false; 173 } 174 return canDone; 175 } 176 177 protected void setDoneDialog(boolean d) { 178 doneDialog = d; 179 } 180 181 private void invoke(AbstractEchoGenerator generator) { 184 ProgressListener[] pl = getProgressListeners(); 185 186 if (pl != null) { 187 for (int i = 0; i < pl.length; i++) { 188 generator.addProgressListener(pl[i]); 189 } 190 } 191 generator.setProject(getProject()); 192 generator.setEcho(isEcho()); 193 generator.buildInCurrentThread(); 194 if (pl != null) { 195 for (int i = 0; i < pl.length; i++) { 196 generator.removeProgressListener(pl[i]); 197 } 198 } 199 } 200 201 } 202 | Popular Tags |