KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > libraries > LibraryProviderImpl


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.java.j2seplatform.libraries;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import org.netbeans.spi.project.libraries.LibraryImplementation;
28 import org.openide.util.Lookup;
29
30 /**
31  * Implementation of library provider for unit testing.
32  *
33  * @author David Konecny
34  */

35 public class LibraryProviderImpl implements org.netbeans.spi.project.libraries.LibraryProvider {
36
37     private ArrayList JavaDoc libs = new ArrayList JavaDoc();
38     private PropertyChangeSupport JavaDoc support;
39     
40     private static final LibraryProviderImpl DEFAULT = new LibraryProviderImpl();
41     
42     public static LibraryProviderImpl getDefault() {
43         assert DEFAULT != null;
44         return DEFAULT;
45     }
46     
47     private LibraryProviderImpl() {
48         support = new PropertyChangeSupport JavaDoc(this);
49     }
50     
51     public void addLibrary(LibraryImplementation library) throws IOException JavaDoc {
52         libs.add(library);
53         fireChange();
54     }
55     
56     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
57         support.addPropertyChangeListener(listener);
58     }
59     
60     public LibraryImplementation[] getLibraries() {
61         return (LibraryImplementation[])libs.toArray(new LibraryImplementation[libs.size()]);
62     }
63     
64     public void init() throws IOException JavaDoc {
65     }
66     
67     public void removeLibrary(LibraryImplementation library) throws IOException JavaDoc {
68         boolean res = libs.remove(library);
69         assert res : "Removing library which is not in this provider "+library;
70         fireChange();
71     }
72     
73     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
74         support.removePropertyChangeListener(listener);
75     }
76
77     private void fireChange() {
78         support.firePropertyChange("xxx", null, null);
79     }
80     
81 }
82
Popular Tags