View Javadoc

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  
18  package org.apache.log4j.rule;
19  
20  import java.beans.PropertyChangeEvent;
21  import java.beans.PropertyChangeListener;
22  import java.beans.PropertyChangeSupport;
23  import java.io.Serializable;
24  
25  
26  /***
27   * An abstract Rule class that provides the PropertyChange support plumbing.
28   *
29   * @author Paul Smith (psmith@apache.org)
30   * @author Scott Deboy (sdeboy@apache.org)
31   */
32  public abstract class AbstractRule implements Rule, Serializable {
33      /***
34       * Serialization id.
35       */
36    static final long serialVersionUID = -2844288145563025172L;
37  
38      /***
39       * PropertySupport instance.
40       */
41    private PropertyChangeSupport propertySupport =
42      new PropertyChangeSupport(this);
43  
44      /***
45       * Add property change listener.
46       * @param l listener.
47       */
48    public void addPropertyChangeListener(final PropertyChangeListener l) {
49      propertySupport.addPropertyChangeListener(l);
50    }
51  
52      /***
53       * Remove property change listener.
54       * @param l listener.
55       */
56    public void removePropertyChangeListener(final PropertyChangeListener l) {
57      propertySupport.removePropertyChangeListener(l);
58    }
59  
60      /***
61       * Send property change notification to attached listeners.
62       * @param propertyName property name.
63       * @param oldVal old value.
64       * @param newVal new value.
65       */
66    protected void firePropertyChange(
67      final String propertyName,
68      final Object oldVal,
69      final Object newVal) {
70      propertySupport.firePropertyChange(propertyName, oldVal, newVal);
71    }
72  
73    /***
74     * Send property change notification to attached listeners.
75     * @param evt property change event.
76     */
77    public void firePropertyChange(final PropertyChangeEvent evt) {
78      propertySupport.firePropertyChange(evt);
79    }
80  }