001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.project.libraries;
043:
044: import java.net.URL;
045: import org.netbeans.spi.project.libraries.LibraryImplementation;
046: import java.util.*;
047: import java.beans.PropertyChangeListener;
048: import java.beans.PropertyChangeEvent;
049:
050: public final class DefaultLibraryImplementation implements
051: LibraryImplementation {
052:
053: private String description;
054:
055: private Map<String, List<URL>> contents;
056:
057: // library 'binding name' as given by user
058: private String name;
059:
060: private String libraryType;
061:
062: private String localizingBundle;
063:
064: private List<PropertyChangeListener> listeners;
065:
066: /**
067: * Create new LibraryImplementation supporting given <tt>library</tt>.
068: */
069: public DefaultLibraryImplementation(String libraryType,
070: String[] volumeTypes) {
071: assert libraryType != null && volumeTypes != null;
072: this .libraryType = libraryType;
073: this .contents = new HashMap<String, List<URL>>();
074: for (String vtype : volumeTypes) {
075: this .contents.put(vtype, Collections.<URL> emptyList());
076: }
077: }
078:
079: public String getType() {
080: return libraryType;
081: }
082:
083: public void setName(final String name)
084: throws UnsupportedOperationException {
085: String oldName = this .name;
086: this .name = name;
087: this .firePropertyChange(PROP_NAME, oldName, this .name);
088: }
089:
090: public String getName() {
091: return name;
092: }
093:
094: public List<URL> getContent(String contentType)
095: throws IllegalArgumentException {
096: List<URL> content = contents.get(contentType);
097: if (content == null)
098: throw new IllegalArgumentException();
099: return Collections.unmodifiableList(content);
100: }
101:
102: public void setContent(String contentType, List<URL> path)
103: throws IllegalArgumentException {
104: if (path == null) {
105: throw new IllegalArgumentException();
106: }
107: if (this .contents.keySet().contains(contentType)) {
108: this .contents.put(contentType, new ArrayList<URL>(path));
109: this .firePropertyChange(PROP_CONTENT, null, null);
110: } else {
111: throw new IllegalArgumentException(
112: "Volume '"
113: + contentType
114: + "' is not support by this library. The only acceptable values are: "
115: + contents.keySet());
116: }
117: }
118:
119: public String getDescription() {
120: return this .description;
121: }
122:
123: public void setDescription(String text) {
124: String oldDesc = this .description;
125: this .description = text;
126: this .firePropertyChange(PROP_DESCRIPTION, oldDesc,
127: this .description);
128: }
129:
130: public String getLocalizingBundle() {
131: return this .localizingBundle;
132: }
133:
134: public void setLocalizingBundle(String resourceName) {
135: this .localizingBundle = resourceName;
136: }
137:
138: public synchronized void addPropertyChangeListener(
139: PropertyChangeListener l) {
140: if (this .listeners == null)
141: this .listeners = new ArrayList<PropertyChangeListener>();
142: this .listeners.add(l);
143: }
144:
145: public synchronized void removePropertyChangeListener(
146: PropertyChangeListener l) {
147: if (this .listeners == null)
148: return;
149: this .listeners.remove(l);
150: }
151:
152: public @Override
153: String toString() {
154: return "DefaultLibraryImplementation[" + name + "]"; // NOI18N
155: }
156:
157: private void firePropertyChange(String propName, Object oldValue,
158: Object newValue) {
159: List<PropertyChangeListener> ls;
160: synchronized (this ) {
161: if (this .listeners == null)
162: return;
163: ls = new ArrayList<PropertyChangeListener>(listeners);
164: }
165: PropertyChangeEvent event = new PropertyChangeEvent(this ,
166: propName, oldValue, newValue);
167: for (PropertyChangeListener l : ls) {
168: l.propertyChange(event);
169: }
170: }
171: }
|