01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.core;
16:
17: import org.araneaframework.Component;
18: import org.araneaframework.Message;
19: import org.araneaframework.core.util.ExceptionUtil;
20:
21: /**
22: * {@link Message} that is sent to and operates on every {@link Component} in hierarchy.
23: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
24: */
25: public abstract class BroadcastMessage implements Message {
26: private Class componentClass;
27:
28: public BroadcastMessage() {
29: }
30:
31: /**
32: * Specifies component class for which
33: * {@link BroadcastMessage#execute(Component)} will be called.
34: *
35: * @since 1.1.1
36: */
37: public BroadcastMessage(Class componentClass) {
38: this .componentClass = componentClass;
39: }
40:
41: /**
42: * Sends method that causes {@link BroadcastMessage#execute(Component)} to be called for
43: * each {@link Component} in hierarchy.
44: *
45: * @see org.araneaframework.Message#send(java.lang.Object, org.araneaframework.Component)
46: */
47: public final void send(Object id, Component component) {
48: component._getComponent().propagate(this );
49:
50: try {
51: if (componentClass == null
52: || componentClass.isAssignableFrom(component
53: .getClass()))
54: this .execute(component);
55: } catch (Exception e) {
56: throw ExceptionUtil.uncheckException(e);
57: }
58: }
59:
60: /**
61: * Method that is called on each {@link Component} present in the {@link Component} hierarchy
62: * where this {@link BroadcastMessage} is propagated.
63: *
64: * @param component {@link Component} this {@link BroadcastMessage} has reached
65: */
66: protected abstract void execute(Component component)
67: throws Exception;
68: }
|