1 19 20 package org.netbeans.api.project.libraries; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeEvent ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.MissingResourceException ; 29 import java.util.ResourceBundle ; 30 import org.netbeans.modules.project.libraries.LibraryAccessor; 31 import org.netbeans.spi.project.libraries.LibraryImplementation; 32 import org.openide.ErrorManager; 33 import org.openide.util.NbBundle; 34 35 46 public final class Library { 47 48 public static final String PROP_NAME = "name"; public static final String PROP_DESCRIPTION = "description"; public static final String PROP_CONTENT = "content"; 52 private LibraryImplementation impl; 54 55 private List <PropertyChangeListener > listeners; 56 57 61 private Library (LibraryImplementation impl) { 62 this.impl = impl; 63 this.impl.addPropertyChangeListener (new PropertyChangeListener () { 64 public void propertyChange(PropertyChangeEvent evt) { 65 String propName = evt.getPropertyName(); 66 Library.this.fireChange (propName,evt.getOldValue(),evt.getNewValue()); 67 } 68 }); 69 } 71 83 public List <URL > getContent(final String volumeType) { 84 return this.impl.getContent (volumeType); 85 } 87 88 89 96 public String getName() { 97 return impl.getName(); 98 } 100 101 106 public String getDescription () { 107 return this.getLocalizedString(this.impl.getLocalizingBundle(),this.impl.getDescription()); 108 } 109 110 111 117 public String getDisplayName () { 118 return this.getLocalizedString(this.impl.getLocalizingBundle(),this.impl.getName()); 119 } 120 121 122 128 public String getType () { 129 return this.impl.getType(); 130 } 131 132 133 public boolean equals(Object obj) { 135 if (obj == this) return true; 136 if (obj instanceof Library) { 137 Library peer = (Library) obj; 138 return peer.impl.equals(impl); 139 } 140 return false; 141 } 142 143 public int hashCode() { 145 return impl.hashCode(); 146 } 147 148 152 public synchronized void addPropertyChangeListener (PropertyChangeListener listener) { 153 if (this.listeners == null) 154 this.listeners = new ArrayList <PropertyChangeListener >(); 155 this.listeners.add (listener); 156 } 157 158 162 public synchronized void removePropertyChangeListener (PropertyChangeListener listener) { 163 if (this.listeners == null) 164 return; 165 this.listeners.remove (listener); 166 } 167 168 169 LibraryImplementation getLibraryImplementation () { 170 return this.impl; 171 } 172 173 private void fireChange (String propertyName, Object oldValue, Object newValue) { 174 List <PropertyChangeListener > ls; 175 synchronized (this) { 176 if (this.listeners == null) 177 return; 178 ls = new ArrayList <PropertyChangeListener >(listeners); 179 } 180 PropertyChangeEvent event = new PropertyChangeEvent (this, propertyName, oldValue, newValue); 181 for (PropertyChangeListener l : ls) { 182 l.propertyChange(event); 183 } 184 } 185 186 187 private String getLocalizedString (String bundleName, String key) { 188 if (key == null) { 189 return null; 190 } 191 if (bundleName == null) { 192 return key; 193 } 194 ResourceBundle bundle; 195 try { 196 bundle = NbBundle.getBundle(bundleName); 197 } catch (MissingResourceException mre) { 198 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, mre); 200 return key; 201 } 202 try { 203 return bundle.getString(key); 204 } catch (MissingResourceException mre) { 205 return key; 207 } 208 } 209 210 static { 211 LibraryAccessor.DEFAULT = new LibraryAccessor () { 212 public Library createLibrary (LibraryImplementation impl) { 213 return new Library (impl); 214 } 215 }; 216 } 217 218 } 220 | Popular Tags |