1 28 29 package com.idaremedia.antx.print; 30 31 import java.io.IOException ; 32 import java.io.OutputStream ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 37 import com.idaremedia.antx.AntX; 38 import com.idaremedia.antx.ErrorSnapshot; 39 import com.idaremedia.antx.helpers.Strings; 40 import com.idaremedia.antx.helpers.Tk; 41 import com.idaremedia.antx.starters.EchoThingTask; 42 43 63 64 public final class EchoErrorTask extends EchoThingTask 65 { 66 69 public EchoErrorTask() 70 { 71 super(AntX.print); 72 } 73 74 75 78 public EchoErrorTask(String iam) 79 { 80 super(iam); 81 } 82 83 84 88 public void setSnapshotId(String refId) 89 { 90 setThingRefId(refId); 91 } 92 93 94 98 public final String getSnapshotRefId() 99 { 100 return getThingRefId(); 101 } 102 103 104 109 public void setThrownId(String refId) 110 { 111 setThingRefId(refId); 112 } 113 114 115 120 public final String getThrownRefId() 121 { 122 return getThingRefId(); 123 } 124 125 126 130 protected String getThingRefParameterName() 131 { 132 return "thrownid|snapshotid"; 133 } 134 135 136 144 public final Object getReferencedErrorThing() 145 throws BuildException 146 { 147 verifyInProject_("getErrorRef"); 148 149 String refid = getThingRefId(); 150 String error = null; 151 152 Object o = getProject().getReference(refid); 153 154 if (o==null) { 155 error = uistrs().get("task.missing.refid", refid); 156 } 157 else if (!(o instanceof Exception ) && !(o instanceof ErrorSnapshot)) { 158 error = uistrs().get("task.bad.refid", refid, 159 Exception .class.getName()+"|"+ErrorSnapshot.class.getName(), 160 o.getClass().getName()); 161 } 162 if (error!=null) { 163 log(error,Project.MSG_ERR); 164 throw new BuildException(error,getLocation()); 165 } 166 return o; 167 } 168 169 170 177 public void setProperties(String nameList) 178 { 179 require_(nameList!=null,"setprops- nonzro list"); 180 m_propertiesList= nameList; 181 } 182 183 184 189 public final String getPropertiesNameList() 190 { 191 return m_propertiesList; 192 } 193 194 195 199 protected void echoThing() 200 { 201 OutputStream out= getOutputStream(); 202 try { 203 Object thing = getReferencedErrorThing(); 204 205 String name; 206 if (thing instanceof ErrorSnapshot) { 207 name = ((ErrorSnapshot)thing).getName(); 208 } else { 209 name = Tk.leafNameFrom(thing.getClass()); 210 } 211 212 DisplayRequest dr= new DisplayRequest(getProject(),name,thing); 213 dr.setFilter(getPropertiesNameList()); 214 215 m_displayWorker.print(dr,out); 216 217 if (tryAntLog(out)) { 218 log(getAntLogString(out),getMsgLevel().getNativeIndex()); 219 } 220 221 } catch(IOException ioX) { 222 String ermsg = uistrs().get("task.echo.unable"); 223 log(ermsg,Project.MSG_ERR); 224 throw new BuildException(ermsg,getLocation()); 225 226 } finally { 227 try { out.close(); } catch(Exception X){} 228 out=null; 229 } 230 } 231 232 233 237 protected void verifyCanExecute_(String calr) 238 { 239 super.verifyCanExecute_(calr); 240 getReferencedErrorThing(); } 242 243 244 private String m_propertiesList= Strings.ALL; 245 private final ErrorPrinter m_displayWorker = new ErrorPrinter(); 246 } 247 248 249 | Popular Tags |