1 17 package org.apache.servicemix.jbi.view; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.jbi.event.EndpointEvent; 22 import org.apache.servicemix.jbi.event.EndpointListener; 23 24 import javax.jbi.servicedesc.ServiceEndpoint; 25 26 32 public abstract class EndpointViewRenderer implements EndpointListener { 33 34 private static final Log log = LogFactory.getLog(EndpointViewRenderer.class); 35 36 private boolean dirty; 37 private boolean rerenderOnChange = true; 38 39 public void render() throws Exception { 40 doRender(); 41 dirty = false; 42 } 43 44 public void internalEndpointRegistered(EndpointEvent event) { 45 viewIsDirty(event.getEndpoint()); 46 } 47 48 public void internalEndpointUnregistered(EndpointEvent event) { 49 viewIsDirty(event.getEndpoint()); 50 } 51 52 public void externalEndpointRegistered(EndpointEvent event) { 53 viewIsDirty(event.getEndpoint()); 54 } 55 56 public void externalEndpointUnregistered(EndpointEvent event) { 57 viewIsDirty(event.getEndpoint()); 58 } 59 60 public void linkedEndpointRegistered(EndpointEvent event) { 61 viewIsDirty(event.getEndpoint()); 62 } 63 64 public void linkedEndpointUnregistered(EndpointEvent event) { 65 viewIsDirty(event.getEndpoint()); 66 } 67 68 public void remoteEndpointRegistered(EndpointEvent event) { 69 viewIsDirty(event.getEndpoint()); 70 } 71 72 public void remoteEndpointUnregistered(EndpointEvent event) { 73 viewIsDirty(event.getEndpoint()); 74 } 75 76 public boolean isRerenderOnChange() { 79 return rerenderOnChange; 80 } 81 82 public void setRerenderOnChange(boolean rerenderOnChange) { 83 this.rerenderOnChange = rerenderOnChange; 84 } 85 86 public boolean isDirty() { 87 return dirty; 88 } 89 90 protected abstract void doRender() throws Exception ; 93 94 protected void viewIsDirty(ServiceEndpoint endpoint) { 95 dirty = true; 96 if (rerenderOnChange) { 97 try { 98 render(); 99 } 100 catch (Exception e) { 101 log.warn("Failed to render view: " + e, e); 102 } 103 } 104 } 105 106 } 107 | Popular Tags |