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 public final void addPropertyChangeListener(
141 final PropertyChangeListener listener) {
142 propertySupport.addPropertyChangeListener(listener);
143 }
144
145
146
147
148
149
150 public final void addPropertyChangeListener(
151 final String propertyName,
152 final PropertyChangeListener listener) {
153 propertySupport.addPropertyChangeListener(propertyName, listener);
154 }
155
156
157
158
159
160 public final void removePropertyChangeListener(
161 final PropertyChangeListener listener) {
162 propertySupport.removePropertyChangeListener(listener);
163 }
164
165
166
167
168
169
170 public final void removePropertyChangeListener(
171 final String propertyName,
172 final PropertyChangeListener listener) {
173 propertySupport.removePropertyChangeListener(propertyName, listener);
174 }
175
176
177
178
179
180 protected final void firePropertyChange(
181 final PropertyChangeEvent evt) {
182 propertySupport.firePropertyChange(evt);
183 }
184
185
186
187
188
189
190
191 protected final void firePropertyChange(
192 final String propertyName,
193 final boolean oldValue,
194 final boolean newValue) {
195 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
196 }
197
198
199
200
201
202
203
204 protected final void firePropertyChange(
205 final String propertyName,
206 final int oldValue, final int newValue) {
207 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
208 }
209
210
211
212
213
214
215
216 protected final void firePropertyChange(
217 final String propertyName,
218 final Object oldValue,
219 final Object newValue) {
220 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
221 }
222 }