1 19 package org.openharmonise.rm; 20 21 import java.io.*; 22 23 import org.openharmonise.commons.xml.*; 24 import org.openharmonise.rm.publishing.*; 25 import org.openharmonise.rm.resources.publishing.*; 26 import org.w3c.dom.*; 27 28 29 36 public abstract class HarmoniseException extends Exception implements Publishable { 37 38 41 public static final String TAG_EXCEPTION = "Exception"; 42 43 46 public static final String TAG_MESSAGE = "Message"; 47 48 51 public static final String TAG_STACKTRACE = "Stacktrace"; 52 53 54 58 public HarmoniseException() { 59 super(); 60 } 61 62 68 public HarmoniseException(String s) { 69 super(s); 70 } 71 72 79 public HarmoniseException(String s, Throwable e) { 80 super(s,e); 81 } 82 83 88 public HarmoniseException(Throwable e) { 89 super(e); 90 } 91 92 97 public void printOriginalStackTrace(PrintWriter out) { 98 if (getCause() != null) { 99 getCause().printStackTrace(out); 100 } 101 } 102 103 108 public void printOriginalStackTrace(PrintStream out) { 109 if (getCause() != null) { 110 getCause().printStackTrace(out); 111 } 112 } 113 114 121 public Element publish(XMLDocument xmlDoc) { 122 return publishThrowable(this,xmlDoc); 123 } 124 125 128 public Element publish(Template template, HarmoniseOutput output, State state) 129 throws PublishException { 130 Element resultEl = null; 131 132 133 try { 134 resultEl = 135 publish(template.getTemplateRootElement(), output, state); 136 } catch (DataAccessException e) { 137 throw new PublishException(e.getLocalizedMessage()); 138 } 139 140 return resultEl; 141 } 142 143 146 public Element publish(Element topEl, HarmoniseOutput output, State state) 147 throws PublishException { 148 return publish(output); 149 } 150 151 154 public void populate(Element xmlElement, State state) 155 throws PopulateException { 156 158 } 159 160 163 public String getTagName() { 164 return TAG_EXCEPTION; 165 } 166 167 176 private Element publishThrowable(Throwable thrown, XMLDocument xmlDoc) { 177 Element exEl = xmlDoc.createElement(TAG_EXCEPTION); 178 Element msgEl = xmlDoc.createElement(TAG_MESSAGE); 179 Element trcEl = xmlDoc.createElement(TAG_STACKTRACE); 180 msgEl.appendChild(xmlDoc.createTextNode(thrown.getMessage())); 181 exEl.appendChild(msgEl); 182 StringWriter swriter = new StringWriter(); 183 PrintWriter out = new PrintWriter(swriter); 184 thrown.printStackTrace(out); 185 trcEl.appendChild(xmlDoc.createTextNode(swriter.toString())); 186 out.close(); 187 exEl.appendChild(trcEl); 188 189 Throwable cause = thrown.getCause(); 190 191 if(cause != null) { 192 exEl.appendChild(publishThrowable(cause,xmlDoc)); 193 } 194 195 return exEl; 196 } 197 198 } | Popular Tags |