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