KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > view > EndpointViewRenderer


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
27  * A base class for renderings of endpoints which can re-render whenever something
28  * changes or mark things as dirty so that they can be re-rendered on demand or in a time based way
29  *
30  * @version $Revision: 432921 $
31  */

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 JavaDoc {
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     // Properties
77
// -------------------------------------------------------------------------
78
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     // Implementation methods
91
// -------------------------------------------------------------------------
92
protected abstract void doRender() throws Exception JavaDoc;
93
94     protected void viewIsDirty(ServiceEndpoint endpoint) {
95         dirty = true;
96         if (rerenderOnChange) {
97             try {
98                 render();
99             }
100             catch (Exception JavaDoc e) {
101                 log.warn("Failed to render view: " + e, e);
102             }
103         }
104     }
105
106 }
107
Popular Tags