1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.plugins;
19
20 import org.apache.log4j.spi.ComponentBase;
21 import org.apache.log4j.spi.LoggerRepository;
22
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.beans.PropertyChangeSupport;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public abstract class PluginSkeleton extends ComponentBase implements Plugin {
45
46
47
48 protected String name = "plugin";
49
50
51
52
53 protected boolean active;
54
55
56
57
58
59 private PropertyChangeSupport propertySupport =
60 new PropertyChangeSupport(this);
61
62
63
64
65 protected PluginSkeleton() {
66 super();
67 }
68
69
70
71
72
73
74 public String getName() {
75 return name;
76 }
77
78
79
80
81
82
83
84 public void setName(final String newName) {
85 String oldName = this.name;
86 this.name = newName;
87 propertySupport.firePropertyChange("name", oldName, this.name);
88 }
89
90
91
92
93
94
95 public LoggerRepository getLoggerRepository() {
96 return repository;
97 }
98
99
100
101
102
103
104
105
106 public void setLoggerRepository(final LoggerRepository repository) {
107 Object oldValue = this.repository;
108 this.repository = repository;
109 firePropertyChange("loggerRepository", oldValue, this.repository);
110 }
111
112
113
114
115
116
117 public synchronized boolean isActive() {
118 return active;
119 }
120
121
122
123
124
125
126
127
128 public boolean isEquivalent(final Plugin testPlugin) {
129 return (repository == testPlugin.getLoggerRepository())
130 && ((this.name == null && testPlugin.getName() == null)
131 || (this.name != null
132 && name.equals(testPlugin.getName())))
133 && this.getClass().equals(testPlugin.getClass());
134 }
135
136
137
138
139
140
141 public final void addPropertyChangeListener(
142 final PropertyChangeListener listener) {
143 propertySupport.addPropertyChangeListener(listener);
144 }
145
146
147
148
149
150
151
152 public final void addPropertyChangeListener(
153 final String propertyName,
154 final PropertyChangeListener listener) {
155 propertySupport.addPropertyChangeListener(propertyName, listener);
156 }
157
158
159
160
161
162
163 public final void removePropertyChangeListener(
164 final PropertyChangeListener listener) {
165 propertySupport.removePropertyChangeListener(listener);
166 }
167
168
169
170
171
172
173
174 public final void removePropertyChangeListener(
175 final String propertyName,
176 final PropertyChangeListener listener) {
177 propertySupport.removePropertyChangeListener(propertyName, listener);
178 }
179
180
181
182
183
184
185 protected final void firePropertyChange(
186 final PropertyChangeEvent evt) {
187 propertySupport.firePropertyChange(evt);
188 }
189
190
191
192
193
194
195
196
197 protected final void firePropertyChange(
198 final String propertyName,
199 final boolean oldValue,
200 final boolean newValue) {
201 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
202 }
203
204
205
206
207
208
209
210
211 protected final void firePropertyChange(
212 final String propertyName,
213 final int oldValue, final int newValue) {
214 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
215 }
216
217
218
219
220
221
222
223
224 protected final void firePropertyChange(
225 final String propertyName,
226 final Object oldValue,
227 final Object newValue) {
228 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
229 }
230 }