This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 47498
Collapse All | Expand All

(-)src/org/netbeans/api/project/libraries/Library.java (-2 / +11 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 20-25 Link Here
20
import java.util.List;
20
import java.util.List;
21
import java.util.MissingResourceException;
21
import java.util.MissingResourceException;
22
import java.util.ResourceBundle;
22
import java.util.ResourceBundle;
23
import org.netbeans.modules.project.libraries.LibraryAccessor;
23
import org.netbeans.spi.project.libraries.LibraryImplementation;
24
import org.netbeans.spi.project.libraries.LibraryImplementation;
24
import org.openide.ErrorManager;
25
import org.openide.ErrorManager;
25
import org.openide.util.NbBundle;
26
import org.openide.util.NbBundle;
Lines 50-56 Link Here
50
     * Creates new library instance
51
     * Creates new library instance
51
     *
52
     *
52
     */
53
     */
53
    Library (LibraryImplementation impl) {
54
    private Library (LibraryImplementation impl) {
54
        this.impl = impl;
55
        this.impl = impl;
55
        this.impl.addPropertyChangeListener (new PropertyChangeListener () {
56
        this.impl.addPropertyChangeListener (new PropertyChangeListener () {
56
            public void propertyChange(PropertyChangeEvent evt) {
57
            public void propertyChange(PropertyChangeEvent evt) {
Lines 197-202 Link Here
197
            // OK, not required to be there.
198
            // OK, not required to be there.
198
            return key;
199
            return key;
199
        }
200
        }
201
    }
202
    
203
    static {
204
        LibraryAccessor.DEFAULT = new LibraryAccessor () {
205
            public Library createLibrary (LibraryImplementation impl) {
206
                return new Library (impl);
207
            }
208
        };
200
    }
209
    }
201
210
202
} // end Library
211
} // end Library
(-)src/org/netbeans/api/project/libraries/LibraryManager.java (-2 / +37 lines)
Lines 7-20 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
14
package org.netbeans.api.project.libraries;
14
package org.netbeans.api.project.libraries;
15
15
16
16
17
import java.io.IOException;
17
import org.netbeans.api.project.libraries.Library;
18
import org.netbeans.api.project.libraries.Library;
19
import org.netbeans.modules.project.libraries.WriteableLibraryProvider;
20
import org.netbeans.spi.project.libraries.LibraryFactory;
18
import org.netbeans.spi.project.libraries.LibraryImplementation;
21
import org.netbeans.spi.project.libraries.LibraryImplementation;
19
import org.netbeans.spi.project.libraries.LibraryProvider;
22
import org.netbeans.spi.project.libraries.LibraryProvider;
20
import org.openide.util.Lookup;
23
import org.openide.util.Lookup;
Lines 98-104 Link Here
98
                this.currentStorages.add (storage);
101
                this.currentStorages.add (storage);
99
                LibraryImplementation[] impls = storage.getLibraries();
102
                LibraryImplementation[] impls = storage.getLibraries();
100
                for (int i=0; i<impls.length; i++) {                    
103
                for (int i=0; i<impls.length; i++) {                    
101
                    l.add(new Library (impls[i]));
104
                    l.add(LibraryFactory.createLibrary (impls[i]));
102
                }                
105
                }                
103
            }
106
            }
104
            for (Iterator it = removed.iterator(); it.hasNext();) {
107
            for (Iterator it = removed.iterator(); it.hasNext();) {
Lines 110-115 Link Here
110
            this.cache = l;
113
            this.cache = l;
111
        }
114
        }
112
        return (Library[]) this.cache.toArray(new Library[this.cache.size()]);
115
        return (Library[]) this.cache.toArray(new Library[this.cache.size()]);
116
    }
117
    
118
    
119
    /**
120
     * Installs new library
121
     * @param library to be installed, the library has to be created
122
     * with registered {@link org.netbeans.spi.project.libraries.LibraryTypeProvider}.
123
     * @throws IOException when library can be stored
124
     * @throws IllegalArgumentException if the library is not recognized by any 
125
     * {@link org.netbeans.spi.project.libraries.LibraryTypeProvider}
126
     * @since org.netbeans.modules.project.libraries/1 1.10
127
     */
128
    public void addLibrary (Library library) throws IOException, IllegalArgumentException {
129
        Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template (WriteableLibraryProvider.class));
130
        Collection/*<WriteableLibraryProvider>*/ providers = result.allInstances();
131
        assert providers.size() == 1;
132
        ((WriteableLibraryProvider)providers.iterator().next()).addLibrary(library.getLibraryImplementation());
133
    }
134
    
135
    /**
136
     * Removes installed library 
137
     * @param library to be removed. 
138
     * @throws IOException when library can not be deleted.
139
     * @throws IllegalArgumentException when library is not installed in writeable 
140
     * {@link org.netbeans.spi.project.libraries.LibraryProvider}
141
     * @since org.netbeans.modules.project.libraries/1 1.10
142
     */
143
    public void removeLibrary (Library library) throws IOException, IllegalArgumentException {
144
        Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template (WriteableLibraryProvider.class));
145
        Collection/*<WriteableLibraryProvider>*/ providers = result.allInstances();
146
        assert providers.size() == 1;
147
        ((WriteableLibraryProvider)providers.iterator().next()).removeLibrary(library.getLibraryImplementation());
113
    }
148
    }
114
149
115
    /**
150
    /**
(-)src/org/netbeans/modules/project/libraries/LibraryAccessor.java (+34 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.project.libraries;
15
16
import org.netbeans.api.project.libraries.Library;
17
import org.netbeans.spi.project.libraries.LibraryImplementation;
18
19
/**
20
 *
21
 * @author Tomas Zezula
22
 */
23
public abstract class LibraryAccessor {
24
    
25
    public static LibraryAccessor DEFAULT;
26
    
27
    // force loading of Library class. That will set DEFAULT variable.
28
    static {
29
        Object o = Library.class;
30
    }
31
    
32
    public abstract Library createLibrary (LibraryImplementation libraryImplementation);
33
    
34
}
(-)src/org/netbeans/spi/project/libraries/LibraryFactory.java (+43 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.project.libraries;
15
16
import org.netbeans.api.project.libraries.Library;
17
import org.netbeans.modules.project.libraries.LibraryAccessor;
18
19
/**
20
 * Most general way to create {@link Library} instances.
21
 * You are not permitted to create them directly; instead you implement
22
 * {@link LibraryImplementation} and use this factory.
23
 * See also {@link org.netbeans.spi.project.libraries.support.LibrariesSupport}
24
 * for easier ways to create {@link LibraryImplementation}.
25
 * @since org.netbeans.modules.project.libraries/1 1.10
26
 * @author Tomas Zezula
27
 */
28
public class LibraryFactory {
29
    
30
    private LibraryFactory() {
31
    }
32
    
33
    
34
    /**
35
     * Creates Library for LibraryImplementation
36
     * @param libraryImplementation the library SPI object
37
     * @return Library API instance
38
     */
39
    public static Library createLibrary (LibraryImplementation libraryImplementation) {
40
        return LibraryAccessor.DEFAULT.createLibrary(libraryImplementation);
41
    }
42
    
43
}
(-)src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java (+23 lines)
Lines 12-19 Link Here
12
 */
12
 */
13
package org.netbeans.spi.project.libraries.support;
13
package org.netbeans.spi.project.libraries.support;
14
14
15
import org.netbeans.modules.project.libraries.LibraryTypeRegistry;
15
import org.netbeans.spi.project.libraries.LibraryImplementation;
16
import org.netbeans.spi.project.libraries.LibraryImplementation;
16
import org.netbeans.modules.project.libraries.DefaultLibraryImplementation;
17
import org.netbeans.modules.project.libraries.DefaultLibraryImplementation;
18
import org.netbeans.spi.project.libraries.LibraryTypeProvider;
17
19
18
/**
20
/**
19
 * SPI Support class.
21
 * SPI Support class.
Lines 33-37 Link Here
33
     */
35
     */
34
    public static LibraryImplementation createLibraryImplementation (String libraryType, String[] volumeTypes) {
36
    public static LibraryImplementation createLibraryImplementation (String libraryType, String[] volumeTypes) {
35
        return new DefaultLibraryImplementation (libraryType, volumeTypes);
37
        return new DefaultLibraryImplementation (libraryType, volumeTypes);
38
    }
39
    
40
    /**
41
     * Returns registered {@link LibraryTypeProvider} for given library type. This method 
42
     * is mostly used by {@link org.netbeans.spi.project.libraries.LibraryProvider} implementators.
43
     * @param libraryType  the type of library for which the provider should be returned.
44
     * @return {@link LibraryTypeProvider} for given library type or null, if none is registered.
45
     * @since org.netbeans.modules.project.libraries/1 1.10
46
     */
47
    public static LibraryTypeProvider getLibraryTypeProvider (String libraryType) {
48
        return LibraryTypeRegistry.getDefault().getLibraryTypeProvider(libraryType);
49
    }
50
    
51
    /**
52
     * Returns all registered {@link LibraryTypeProvider}s. This method 
53
     * is mostly used by {@link org.netbeans.spi.project.libraries.LibraryProvider} implementators.
54
     * @return an array of {@link LibraryTypeProvider}, never returns null.
55
     * @since org.netbeans.modules.project.libraries/1 1.10
56
     */
57
    public static LibraryTypeProvider[] getLibraryTypeProviders () {
58
        return LibraryTypeRegistry.getDefault().getLibraryTypeProviders();
36
    }
59
    }
37
}
60
}

Return to bug 47498