Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/lib/propertyset/UnmodifiablePropertySet.java


1   /*
2   ================================================================================
3   
4     FILE:  UnmodifiablePropertySet.java
5     
6     PROJECT:
7     
8       Virtuoso Utilities
9     
10    CONTENTS:
11    
12      Unmodifiable PropertySet wrapper
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.lib.propertyset;
43  
44  
45  import com.virtuosotechnologies.lib.base.ConstrainedKey;
46  import com.virtuosotechnologies.lib.util.EventBroadcastHelper;
47  
48  
49  /**
50   * A PropertySet that wraps another PropertySet and doesn't allow modifications
51   */
52  public class UnmodifiablePropertySet
53  implements PropertySet
54  {
55    private EventBroadcastHelper propertyBroadcaster_;
56    private PropertySet parent_;
57    private PropertySetListener listener_;
58    
59    
60    /**
61     * Constructor
62     */
63    public UnmodifiablePropertySet(
64      PropertySet parent)
65    {
66      parent_ = parent;
67      propertyBroadcaster_ = new EventBroadcastHelper(PropertySetListener.class);
68      parent_.addPropertySetListener(
69        listener_ = new PropertySetListener()
70        {
71          public void propertySetChanged(
72            PropertySetEvent ev)
73          {
74            propertyBroadcaster_.fireEvent(
75              PropertySetListener.PROPERTYSET_CHANGED_METHOD,
76              new PropertySetEvent(UnmodifiablePropertySet.this, false,
77                ev.getKey(), ev.getOldValue(), ev.getNewValue()));
78          }
79        });
80    }
81    
82    
83    /**
84     * Get a property.
85     *
86     * @param key key object for the property
87     * @return value for the property
88     */
89    public Object getValue(
90      ConstrainedKey key)
91    {
92      return parent_.getValue(key);
93    }
94    
95    
96    /**
97     * Get the default value for a property, or null if there is no default.
98     *
99     * @param key key object for the property
100    * @return default value for the property
101    */
102   public Object getDefaultValue(
103     ConstrainedKey key)
104   {
105     return parent_.getValue(key);
106   }
107   
108   
109   /**
110    * Set a property.
111    *
112    * @param key key object for the property.
113     * @param value new value for the property.
114    */
115   public void putValue(
116     ConstrainedKey key,
117     Object value)
118   {
119     throw new UnsupportedOperationException();
120   }
121   
122   
123   /**
124    * Reset a property to the default. Sets it to null if there is no default.
125    *
126    * @param key key object for the property
127    */
128   public void resetValue(
129     ConstrainedKey key)
130   {
131     throw new UnsupportedOperationException();
132   }
133   
134   
135   /**
136    * Add a PropertySetListener. Listeners should be added via weak
137    * references.
138    *
139    * @param listener new listener
140    */
141   public void addPropertySetListener(
142     PropertySetListener listener)
143   {
144     propertyBroadcaster_.addListenerWeak(listener);
145   }
146   
147   
148   /**
149    * Remove a PropertySetListener. Does nothing if the listener is
150    * not already present.
151    *
152    * @param listener listener to remove
153    */
154   public void removePropertySetListener(
155     PropertySetListener listener)
156   {
157     propertyBroadcaster_.removeListener(listener);
158   }
159 }