KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > libraries > ui > ProxyLibraryImplementation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.libraries.ui;
21
22 import java.net.URL JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.beans.PropertyChangeSupport JavaDoc;
27 import java.beans.PropertyChangeListener JavaDoc;
28 import java.beans.PropertyChangeEvent JavaDoc;
29
30 import org.netbeans.spi.project.libraries.LibraryImplementation;
31 import org.openide.util.WeakListeners;
32 /**
33  *
34  * @author tom
35  */

36 public class ProxyLibraryImplementation implements LibraryImplementation, PropertyChangeListener JavaDoc {
37
38     private final LibraryImplementation original;
39     private final LibrariesModel model;
40     private Map JavaDoc<String JavaDoc,List JavaDoc<URL JavaDoc>> newContents;
41     private String JavaDoc newName;
42     private String JavaDoc newDescription;
43     private PropertyChangeSupport JavaDoc support;
44
45     /** Creates a new instance of ProxyLibraryImplementation */
46     public ProxyLibraryImplementation (LibraryImplementation original, LibrariesModel model) {
47         assert original != null && model != null;
48         this.original = original;
49         this.model = model;
50         this.original.addPropertyChangeListener(WeakListeners.create(PropertyChangeListener JavaDoc.class, this, this.original));
51         this.support = new PropertyChangeSupport JavaDoc (this);
52     }
53     
54     public LibraryImplementation getOriginal () {
55         return this.original;
56     }
57     
58     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
59         this.support.addPropertyChangeListener(l);
60     }
61     
62     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
63         this.support.removePropertyChangeListener(l);
64     }
65     
66     public String JavaDoc getType() {
67         return this.original.getType ();
68     }
69     
70     
71     public synchronized List JavaDoc<URL JavaDoc> getContent(String JavaDoc volumeType) throws IllegalArgumentException JavaDoc {
72         List JavaDoc<URL JavaDoc> result = null;
73         if (newContents == null || (result = newContents.get(volumeType)) == null) {
74             return this.original.getContent (volumeType);
75         }
76         else {
77             return result;
78         }
79     }
80     
81     public synchronized String JavaDoc getDescription() {
82         if (this.newDescription != null) {
83             return this.newDescription;
84         }
85         else {
86             return this.original.getDescription();
87         }
88     }
89     
90     public synchronized String JavaDoc getName() {
91         if (this.newName != null) {
92             return this.newName;
93         }
94         else {
95             return this.original.getName ();
96         }
97     }
98     
99     public synchronized void setContent(String JavaDoc volumeType, List JavaDoc<URL JavaDoc> path) throws IllegalArgumentException JavaDoc {
100         if (this.newContents == null) {
101             this.newContents = new HashMap JavaDoc<String JavaDoc,List JavaDoc<URL JavaDoc>>();
102         }
103         this.newContents.put (volumeType, path);
104         this.model.modifyLibrary(this);
105         this.support.firePropertyChange(PROP_CONTENT,null,null); //NOI18N
106
}
107     
108     public synchronized void setDescription(String JavaDoc text) {
109         String JavaDoc oldDescription = this.newDescription == null ? this.original.getDescription() : this.newDescription;
110         this.newDescription = text;
111         this.model.modifyLibrary(this);
112         this.support.firePropertyChange(PROP_DESCRIPTION,oldDescription,this.newDescription); //NOI18N
113
}
114     
115     public synchronized void setName(String JavaDoc name) {
116         String JavaDoc oldName = this.newName == null ? this.original.getName() : this.newName;
117         this.newName = name;
118         this.model.modifyLibrary(this);
119         this.support.firePropertyChange(PROP_NAME,oldName,this.newName); //NOI18N
120
}
121
122
123     public String JavaDoc getLocalizingBundle() {
124         return this.original.getLocalizingBundle();
125     }
126
127     public void setLocalizingBundle(String JavaDoc resourceName) {
128         throw new UnsupportedOperationException JavaDoc();
129     }
130
131     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
132         this.support.firePropertyChange(evt.getPropertyName(),evt.getOldValue(),evt.getNewValue());
133     }
134
135
136     public final int hashCode() {
137         return this.original.hashCode();
138     }
139
140     public final boolean equals(Object JavaDoc obj) {
141         if (obj instanceof ProxyLibraryImplementation) {
142             return this.original.equals(((ProxyLibraryImplementation)obj).getOriginal());
143         }
144         else
145             return false;
146     }
147
148     public final String JavaDoc toString() {
149         return "Proxy for: " + this.original.toString(); //NOI18N
150
}
151
152 }
153
Popular Tags