1 /*
2 * File: AbstractWidget.java
3 * Created: 22.10.2006 17:11:19
4 *
5 * Copyright 2006 Michal Burda.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 package net.sf.webmancer.widget;
23
24 import net.sf.webmancer.base.Event;
25 import net.sf.webmancer.model.IModelBuilder;
26 import net.sf.webmancer.model.ModelingException;
27 import net.sf.webmancer.util.ContractChecker;
28
29 /**
30 * @author Michal Burda
31 */
32 public abstract class AbstractWidget implements IWidget {
33 /**
34 *
35 */
36 private String name;
37
38 /**
39 *
40 */
41 private IWidget parent;
42
43 /**
44 * @param name
45 */
46 public AbstractWidget() {
47 super();
48 }
49
50 /**
51 * @see net.sf.webmancer.widget.IWidget#getBeanName()
52 */
53 public String getBeanName() {
54 assert this.name != null;
55 return this.name;
56 }
57
58 /**
59 * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
60 */
61 public void setBeanName(String name) {
62 ContractChecker.mustNotBeEmpty(name, "name");
63 this.name = name;
64 }
65
66 /**
67 * @see net.sf.webmancer.widget.IWidget#handleEvent(net.sf.webmancer.base.Event)
68 */
69 public void handleEvent(final Event event) {
70 }
71
72 /**
73 * @see net.sf.webmancer.widget.IWidget#getParent()
74 */
75 public IWidget getParent() {
76 return this.parent;
77 }
78
79 /**
80 * @see net.sf.webmancer.widget.IWidget#setParent(net.sf.webmancer.widget.IWidget)
81 */
82 public void setParent(IWidget parent) {
83 ContractChecker.mustNotBeNull(parent, "parent");
84 this.parent = parent;
85 }
86
87 /**
88 * @see net.sf.webmancer.widget.IWidget#putEvent(net.sf.webmancer.base.Event)
89 */
90 public void putEvent(Event event) {
91 if (this.parent != null) {
92 this.parent.putEvent(event);
93 } else {
94 throw new IllegalStateException("Cannot put event - parent is null");
95 }
96 }
97
98 /**
99 * @see java.lang.Object#toString()
100 */
101 @Override
102 public String toString() {
103 return this.getBeanName() + ":" + this.getClass().getName();
104 }
105
106 /**
107 * @see net.sf.webmancer.model.IModelable#build(net.sf.webmancer.model.IModelBuilder)
108 */
109 public abstract void build(IModelBuilder builder) throws ModelingException;
110
111 }