KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > libraries > DefaultLibraryImplementation


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;
21
22 import java.net.URL JavaDoc;
23 import org.netbeans.spi.project.libraries.LibraryImplementation;
24 import java.util.*;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27
28 public final class DefaultLibraryImplementation implements LibraryImplementation {
29
30     private String JavaDoc description;
31
32     private Map<String JavaDoc,List<URL JavaDoc>> contents;
33
34     // library 'binding name' as given by user
35
private String JavaDoc name;
36
37     private String JavaDoc libraryType;
38
39     private String JavaDoc localizingBundle;
40
41     private List<PropertyChangeListener JavaDoc> listeners;
42
43     /**
44      * Create new LibraryImplementation supporting given <tt>library</tt>.
45      */

46     public DefaultLibraryImplementation (String JavaDoc libraryType, String JavaDoc[] volumeTypes) {
47         assert libraryType != null && volumeTypes != null;
48         this.libraryType = libraryType;
49         this.contents = new HashMap<String JavaDoc,List<URL JavaDoc>>();
50         for (String JavaDoc vtype : volumeTypes) {
51             this.contents.put(vtype, Collections.<URL JavaDoc>emptyList());
52         }
53     }
54
55
56     public String JavaDoc getType() {
57         return libraryType;
58     }
59
60     public void setName(final String JavaDoc name) throws UnsupportedOperationException JavaDoc {
61         String JavaDoc oldName = this.name;
62         this.name = name;
63         this.firePropertyChange (PROP_NAME, oldName, this.name);
64     }
65
66     public String JavaDoc getName() {
67         return name;
68     }
69
70     public List<URL JavaDoc> getContent(String JavaDoc contentType) throws IllegalArgumentException JavaDoc {
71         List<URL JavaDoc> content = contents.get(contentType);
72         if (content == null)
73             throw new IllegalArgumentException JavaDoc ();
74         return Collections.unmodifiableList (content);
75     }
76
77     public void setContent(String JavaDoc contentType, List<URL JavaDoc> path) throws IllegalArgumentException JavaDoc {
78         if (path == null) {
79             throw new IllegalArgumentException JavaDoc ();
80         }
81         if (this.contents.keySet().contains(contentType)) {
82             this.contents.put(contentType, new ArrayList<URL JavaDoc>(path));
83             this.firePropertyChange(PROP_CONTENT,null,null);
84         } else {
85             throw new IllegalArgumentException JavaDoc ("Volume '"+contentType+
86                 "' is not support by this library. The only acceptable values are: "+contents.keySet());
87         }
88     }
89
90     public String JavaDoc getDescription () {
91             return this.description;
92     }
93
94     public void setDescription (String JavaDoc text) {
95         String JavaDoc oldDesc = this.description;
96         this.description = text;
97         this.firePropertyChange (PROP_DESCRIPTION, oldDesc, this.description);
98     }
99
100     public String JavaDoc getLocalizingBundle() {
101         return this.localizingBundle;
102     }
103
104     public void setLocalizingBundle(String JavaDoc resourceName) {
105         this.localizingBundle = resourceName;
106     }
107
108     public synchronized void addPropertyChangeListener (PropertyChangeListener JavaDoc l) {
109         if (this.listeners == null)
110             this.listeners = new ArrayList<PropertyChangeListener JavaDoc>();
111         this.listeners.add (l);
112     }
113
114     public synchronized void removePropertyChangeListener (PropertyChangeListener JavaDoc l) {
115         if (this.listeners == null)
116             return;
117         this.listeners.remove (l);
118     }
119
120     public String JavaDoc toString () {
121         return "LibraryImplementation[Name="+this.name+"]"; //NOI18N
122
}
123
124     private void firePropertyChange (String JavaDoc propName, Object JavaDoc oldValue, Object JavaDoc newValue) {
125         List<PropertyChangeListener JavaDoc> ls;
126         synchronized (this) {
127             if (this.listeners == null)
128                 return;
129             ls = new ArrayList<PropertyChangeListener JavaDoc>(listeners);
130         }
131         PropertyChangeEvent JavaDoc event = new PropertyChangeEvent JavaDoc (this, propName, oldValue, newValue);
132         for (PropertyChangeListener JavaDoc l : ls) {
133             l.propertyChange(event);
134         }
135     }
136 }
137
Popular Tags