Changeset 4618
- Timestamp:
- Oct 30, 2008, 11:41:41 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java
r4512 r4618 444 444 445 445 /** 446 Get information about the last error that happened 447 when rendering an extension point. 448 @param id The id of the extension point 449 @return The error, or null if no error information is available 450 @since 2.9 451 */ 452 public Throwable getLastExtensionPointError(String id) 453 { 454 return registry.getLastExtensionPointError(id); 455 } 456 457 /** 446 458 Enable/disable an extension point. 447 459 @param extensionPointId The ID of the extension point to enable/disable … … 494 506 { 495 507 return registry.getExtension(id); 508 } 509 510 /** 511 Get information about the last error that happened 512 when rendering an extension. 513 @param id The id of the extension 514 @return The error, or null if no error information is available 515 @since 2.9 516 */ 517 public Throwable getLastExtensionError(String id) 518 { 519 return registry.getLastExtensionError(id); 496 520 } 497 521 -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/service/Services.java
r4512 r4618 115 115 ExtensionsFilter filter = extension == null ? 116 116 settings : new SingleExtensionFilter(extension.getId()); 117 return (ExtensionsInvoker<ServiceControllerAction>)ExtensionsControl.useExtensions(null, filter, EXTENSION_POINT_ID); 117 ExtensionsInvoker<?> invoker = ExtensionsControl.useExtensions(null, filter, EXTENSION_POINT_ID); 118 invoker.setClearErrors(true); 119 return (ExtensionsInvoker<ServiceControllerAction>)invoker; 118 120 } 119 121 -
trunk/src/core/net/sf/basedb/util/extensions/ActionIterator.java
r4515 r4618 60 60 // The current context 61 61 private InvokationContext<A> currentContext; 62 private A currentAction; 62 63 63 64 // An iterator over all usable extensions … … 129 130 if (!hasNext) throw new NoSuchElementException(); 130 131 checkNext = true; 131 return actions[offset]; 132 currentAction = actions[offset]; 133 return currentAction; 132 134 } 133 135 /** … … 160 162 /** 161 163 Gets the renderer for the current action. 162 */ 163 Renderer<? super A> getRenderer() 164 @since 2.9 165 */ 166 public Renderer<? super A> getRenderer() 164 167 { 165 168 return currentContext.getRenderer(); 166 169 } 167 170 171 /** 172 Clear any error that has been registered for the current 173 action. 174 @since 2.9 175 @see #setError(Throwable) 176 */ 177 public void clearError() 178 { 179 currentContext.clearError(); 180 } 181 182 /** 183 Register an error for the current action. The error can be retreived 184 with {@link Registry#getLastExtensionError(String)}. 185 @param t The error to register 186 @since 2.9 187 */ 188 public void setError(Throwable t) 189 { 190 currentContext.setError(currentAction, t); 191 } 192 168 193 /** 169 194 Check that the actions array is a not-null, non-empty array … … 190 215 Extension ext = getExtension(); 191 216 ClassCastException cc = new ClassCastException(actions[i] + " -> " + actionClass.getName()); 217 currentContext.setError(actions[i], cc); 192 218 log.error("Action '" + actions[i] + "' created by extension '" + ext.getId() + 193 219 "' is not of the expected class '" + actionClass.getName(), cc); -
trunk/src/core/net/sf/basedb/util/extensions/ExtensionContext.java
r4515 r4618 22 22 package net.sf.basedb.util.extensions; 23 23 24 import net.sf.basedb.util.extensions.Registry.RegisteredExtension; 25 24 26 /** 25 27 Invokation context for an extension. Most … … 35 37 { 36 38 private final ExtensionPointContext<? super A> mainContext; 37 private final Extension<A> extension;39 private final RegisteredExtension<A> extension; 38 40 private Renderer<? super A> renderer; 39 41 private boolean hasCreatedRenderer; 40 42 41 ExtensionContext(ExtensionPointContext<? super A> mainContext, Extension<A> extension)43 ExtensionContext(ExtensionPointContext<? super A> mainContext, RegisteredExtension<A> extension) 42 44 { 43 45 this.mainContext = mainContext; … … 90 92 catch (Throwable t) 91 93 { 94 setError(null, t); 92 95 log.error("Error preparing renderer factory for extension '" + 93 96 extension.getId() + "': " + factory, t); … … 140 143 catch (Throwable t) 141 144 { 145 setError(null, t); 142 146 log.error("Error creating actions for extension '" + 143 147 extension.getId() + "' using factory: " + factory, t); 144 148 } 145 149 return actions; 150 } 151 152 @Override 153 protected void setError(A action, Throwable t) 154 { 155 extension.setError(action, t); 156 } 157 158 @Override 159 protected void clearError() 160 { 161 extension.clearError(); 146 162 } 147 163 // ---------------------------------------- -
trunk/src/core/net/sf/basedb/util/extensions/ExtensionPointContext.java
r4515 r4618 22 22 package net.sf.basedb.util.extensions; 23 23 24 import net.sf.basedb.util.extensions.Registry.RegisteredExtensionPoint; 25 24 26 /** 25 27 Invokation context for an extension point. … … 35 37 private final ClientContext clientContext; 36 38 private final Registry registry; 37 private final ExtensionPoint<? super A> extensionPoint;39 private final RegisteredExtensionPoint<? super A> extensionPoint; 38 40 private Renderer<? super A> renderer; 39 41 private boolean hasCreatedRenderer; 40 42 41 43 ExtensionPointContext(Registry registry, ClientContext clientContext, 42 ExtensionPoint<? super A> extensionPoint)44 RegisteredExtensionPoint<? super A> extensionPoint) 43 45 { 44 46 this.registry = registry; … … 99 101 catch (Throwable t) 100 102 { 103 setError(null, t); 101 104 log.error("Error preparing renderer factory for extension point '" + 102 105 extensionPoint.getId() + "': " + factory, t); … … 133 136 return null; 134 137 } 138 139 @Override 140 protected void setError(A action, Throwable t) 141 { 142 extensionPoint.setError(action, t); 143 } 144 145 @Override 146 protected void clearError() 147 { 148 extensionPoint.clearError(); 149 } 135 150 // ---------------------------------------- 136 151 -
trunk/src/core/net/sf/basedb/util/extensions/ExtensionsInvoker.java
r4515 r4618 23 23 24 24 import java.util.Collection; 25 import java.util.Iterator;26 25 27 26 /** … … 58 57 org.apache.log4j.LogManager.getLogger("net.sf.basedb.util.extensions.ExtensionsInvoker"); 59 58 60 final Collection<InvokationContext<A>> contexts; 59 private final Collection<InvokationContext<A>> contexts; 60 private boolean clearErrors; 61 61 62 62 /** … … 68 68 } 69 69 70 /** 71 Set a flag to indicate if existing errors should be cleared 72 before an action is rendered. If this setting is not enabled (default) 73 old errors are never cleared. 74 @param clearErrors TRUE to clear old errors, FALSE to keep them 75 @since 2.9 76 */ 77 public void setClearErrors(boolean clearErrors) 78 { 79 this.clearErrors = clearErrors; 80 } 81 70 82 /** 71 83 Create an iterator that iterates over all {@link Action}:s created … … 95 107 try 96 108 { 109 if (clearErrors) it.clearError(); 97 110 action = it.next(); 98 111 renderer = it.getRenderer(); … … 105 118 catch (Throwable t) 106 119 { 120 it.setError(t); 107 121 log.error("Could not render action '" + action + "' with renderer '" + 108 122 renderer + "'", t); … … 121 135 public void render(Renderer<A> renderer) 122 136 { 123 Iterator<A> it = iterate();137 ActionIterator<A> it = iterate(); 124 138 while (it.hasNext()) 125 139 { … … 127 141 try 128 142 { 143 if (clearErrors) it.clearError(); 129 144 action = it.next(); 130 145 renderer.render(action); … … 132 147 catch (Throwable t) 133 148 { 149 it.setError(t); 134 150 log.error("Could not render action '" + action + "' with renderer '" + 135 151 renderer + "'", t); -
trunk/src/core/net/sf/basedb/util/extensions/InvokationContext.java
r4515 r4618 111 111 protected abstract A[] getActions(); 112 112 113 /** 114 Register an error for the current extension or extension point. 115 Registered errors can be retrieved by {@link Registry#getLastExtensionError(String)} 116 and {@link Registry#getLastExtensionPointError(String)} 117 @param action The action that caused the error 118 @param t The error 119 @since 2.9 120 */ 121 protected abstract void setError(A action, Throwable t); 122 123 /** 124 Clear the registered error for the current extension or extension point. 125 @since 2.9 126 */ 127 protected abstract void clearError(); 128 113 129 } -
trunk/src/core/net/sf/basedb/util/extensions/Registry.java
r4515 r4618 309 309 310 310 /** 311 Get information about the last error that happened 312 when rendering an extension point. 313 @param id The id of the extension point 314 @return The error, or null if no error information is available 315 @since 2.9 316 */ 317 public Throwable getLastExtensionPointError(String id) 318 { 319 RegisteredExtensionPoint<?> rep = extensionPoints.get(id); 320 return rep == null ? null : rep.getLastError(); 321 } 322 323 /** 311 324 Register an extension. If the extension is already registered, 312 325 the description, position, action factory and renderer factory … … 393 406 return extensions.get(id); 394 407 } 408 409 /** 410 Get information about the last error that happened 411 when rendering an extension. 412 @param id The id of the extension 413 @return The error, or null if no error information is available 414 @since 2.9 415 */ 416 public Throwable getLastExtensionError(String id) 417 { 418 RegisteredExtension<?> ext = extensions.get(id); 419 return ext == null ? null : ext.getLastError(); 420 } 421 395 422 396 423 /** … … 555 582 private boolean allowRendererOverride; 556 583 584 private Throwable lastError; 585 private A lastErrorAction; 586 557 587 /** 558 588 Create a new registered extension point by copying the … … 647 677 { 648 678 return this.extensions.values(); 649 } 679 } 680 681 synchronized void setError(A action, Throwable t) 682 { 683 this.lastErrorAction = action; 684 this.lastError = t; 685 } 686 687 synchronized void clearError() 688 { 689 this.lastError = null; 690 this.lastErrorAction = null; 691 } 692 693 Throwable getLastError() 694 { 695 return lastError; 696 } 650 697 } 651 698 … … 665 712 private RendererFactory<? super A> rendererFactory; 666 713 714 private Throwable lastError; 715 private A lastErrorAction; 716 667 717 /** 668 718 Create a new registered extension by copying the … … 756 806 return rep; 757 807 } 808 809 synchronized void setError(A action, Throwable t) 810 { 811 this.lastErrorAction = action; 812 this.lastError = t; 813 } 814 815 synchronized void clearError() 816 { 817 this.lastError = null; 818 this.lastErrorAction = null; 819 } 820 821 Throwable getLastError() 822 { 823 return lastError; 824 } 758 825 } 759 826 -
trunk/www/admin/extensions/details.jsp
r4510 r4618 33 33 import="net.sf.basedb.util.Values" 34 34 import="net.sf.basedb.core.ItemNotFoundException" 35 import="net.sf.basedb.util.error.ThrowableUtil" 35 36 import="net.sf.basedb.util.extensions.ExtensionPoint" 36 37 import="net.sf.basedb.util.extensions.Extension" … … 169 170 Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ScanResults', 'ScanResults', 600, 480); 170 171 } 172 173 function toggleStacktrace(evt, id) 174 { 175 Main.showHide('stacktrace.' + id); 176 } 177 171 178 </script> 172 179 </base:head> … … 179 186 { 180 187 boolean isEnabled = ec.isEnabled(ext); 181 boolean has Error = extFile != null && extFile.hasError();182 boolean allow = writePermission && !has Error;188 boolean hasRegistrationError = extFile != null && extFile.hasError(); 189 boolean allow = writePermission && !hasRegistrationError; 183 190 %> 184 191 <tbl:button … … 200 207 { 201 208 boolean isEnabled = ec.isEnabled(ep); 202 boolean has Error = epFile != null && epFile.hasError();203 boolean allow = writePermission && !has Error;209 boolean hasRegistrationError = epFile != null && epFile.hasError(); 210 boolean allow = writePermission && !hasRegistrationError; 204 211 %> 205 212 <tbl:button … … 220 227 else if (file != null) 221 228 { 222 boolean has Error = file.hasError();223 boolean allow = writePermission && !has Error;229 boolean hasRegistrationError = file.hasError(); 230 boolean allow = writePermission && !hasRegistrationError; 224 231 %> 225 232 <tbl:button … … 274 281 About about = ext.getAbout(); 275 282 if (about == null) about = new AboutBean(); 276 %> 277 </a> 283 Throwable error = ec.getLastExtensionError(ext.getId()); 284 if (error != null) 285 { 286 %> 287 <div class="error"> 288 <base:icon image="error.gif" 289 onclick="<%="toggleStacktrace(event, '" + ext.getId() + "')"%>" 290 tooltip="Toggle display of detailed stacktrace" 291 style="float: left;" 292 tooltip="Error - click to show full stack trace" 293 /><%=error.getMessage() %> 294 <div id="stacktrace.<%=ext.getId()%>" 295 class="stacktrace" 296 style="display: none;" 297 ><%=ThrowableUtil.stackTraceToString(error)%></div> 298 </div> 299 <% 300 } 301 %> 278 302 <table class="form" cellspacing="0"> 279 303 <tr> … … 340 364 <h4>Extension point</h4> 341 365 <% 366 } 367 Throwable error = ec.getLastExtensionPointError(ep.getId()); 368 if (error != null) 369 { 370 %> 371 <div class="error"> 372 <base:icon image="error.gif" 373 onclick="<%="toggleStacktrace(event, '" + ep.getId() + "')"%>" 374 tooltip="Toggle display of detailed stacktrace" 375 style="float: left;" 376 tooltip="Error - click to show full stack trace" 377 /><%=error.getMessage() %> 378 <div id="stacktrace.<%=ep.getId()%>" 379 class="stacktrace" 380 style="display: none;" 381 ><%=ThrowableUtil.stackTraceToString(error)%></div> 382 </div> 383 <% 342 384 } 343 385 %> -
trunk/www/admin/extensions/tree.jsp
r4510 r4618 49 49 String icon = ec.isEnabled(ep) ? "ExtensionPoint" : "ExtensionPointDisabled"; 50 50 ExtensionsFile f = ec.getFileByExtensionId(id); 51 if (f == null || f.hasError()) icon = "ExtensionPointError"; 51 if (f == null || f.hasError() || ec.getLastExtensionPointError(id) != null) 52 { 53 icon = "ExtensionPointError"; 54 } 52 55 String joust = "ep = JoustMenu.addChildItem(" + parentNode +", '" + icon + "', " + 53 56 "'" + HTML.javaScriptEncode(name) + "', 'extensionPointOnClick(\"" + id + "\")', " + … … 62 65 String icon = ec.isEnabled(ext) ? "Extension" : "ExtensionDisabled"; 63 66 ExtensionsFile f = ec.getFileByExtensionId(id); 64 if (f == null || f.hasError()) icon = "ExtensionError"; 67 if (f == null || f.hasError() || ec.getLastExtensionError(id) != null) 68 { 69 icon = "ExtensionError"; 70 } 65 71 String joust = "ext = JoustMenu.addChildItem(" + parentNode + ", '" + icon + "', " + 66 72 "'" + HTML.javaScriptEncode(name) + "', 'extensionOnClick(\"" + id + "\")', " + -
trunk/www/admin/services/services.jsp
r4320 r4618 4 4 import="net.sf.basedb.core.DbControl" 5 5 import="net.sf.basedb.core.Permission" 6 import="net.sf.basedb.util.error.ThrowableUtil" 6 7 import="net.sf.basedb.util.extensions.ActionIterator" 7 8 import="net.sf.basedb.util.extensions.Extension" 8 9 import="net.sf.basedb.util.extensions.ExtensionsFilter" 9 10 import="net.sf.basedb.util.extensions.ExtensionsInvoker" 11 import="net.sf.basedb.util.extensions.Registry" 10 12 import="net.sf.basedb.clients.web.Base" 11 13 import="net.sf.basedb.clients.web.extensions.ExtensionsControl" … … 46 48 { 47 49 location.href = 'index.jsp?ID=<%=ID%>&cmd=Start&extensionId=' + extensionId; 50 } 51 function toggleStacktrace(evt, extensionId) 52 { 53 Main.showHide('stacktrace.' + extensionId); 48 54 } 49 55 </script> … … 86 92 last = ext; 87 93 boolean isRunning = action.isRunning(); 94 Throwable error = ec.getLastExtensionError(ext.getId()); 95 boolean hasError = error != null; 88 96 %> 89 97 <tbl:row> … … 99 107 </tbl:cell> 100 108 <tbl:cell column="service"><%=action.toString()%></tbl:cell> 101 <tbl:cell column="status"><%=isRunning ? "Running" : "Stopped"%></tbl:cell> 109 <tbl:cell column="status"> 110 <% 111 if (hasError) 112 { 113 %> 114 <div class="error"> 115 <base:icon image="error.gif" 116 onclick="<%="toggleStacktrace(event, '" + ext.getId() + "')"%>" 117 tooltip="Toggle display of detailed stacktrace" 118 style="float: left;" 119 tooltip="Error - click to show full stack trace" 120 /><%=error.getMessage() %> 121 <div id="stacktrace.<%=ext.getId()%>" 122 class="stacktrace" 123 style="display: none;" 124 ><%=ThrowableUtil.stackTraceToString(error)%></div> 125 </div> 126 <% 127 } 128 else 129 { 130 %> 131 <%=isRunning ? "Running" : "Stopped"%> 132 <% 133 } 134 %> 135 </tbl:cell> 102 136 <tbl:cell column="actions"> 103 137 <% -
trunk/www/include/styles/main.css
r4510 r4618 228 228 } 229 229 230 .error .stacktrace { 231 white-space: pre; 232 font-family: monospace; 233 text-align: left; 234 font-size: smaller; 235 background: #ffffd8; 236 color: #000000; 237 padding: 2px; 238 } 239 230 240 .helpmessage { 231 241 background: #E0E0E0;
Note: See TracChangeset
for help on using the changeset viewer.