Index: src/org/netbeans/api/project/libraries/Library.java =================================================================== RCS file: /cvs/projects/libraries/src/org/netbeans/api/project/libraries/Library.java,v retrieving revision 1.6 diff -u -r1.6 Library.java --- src/org/netbeans/api/project/libraries/Library.java 25 Oct 2004 20:53:40 -0000 1.6 +++ src/org/netbeans/api/project/libraries/Library.java 13 Jan 2005 13:58:55 -0000 @@ -7,7 +7,7 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -20,6 +20,7 @@ import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.netbeans.modules.project.libraries.LibraryAccessor; import org.netbeans.spi.project.libraries.LibraryImplementation; import org.openide.ErrorManager; import org.openide.util.NbBundle; @@ -50,7 +51,7 @@ * Creates new library instance * */ - Library (LibraryImplementation impl) { + private Library (LibraryImplementation impl) { this.impl = impl; this.impl.addPropertyChangeListener (new PropertyChangeListener () { public void propertyChange(PropertyChangeEvent evt) { @@ -197,6 +198,14 @@ // OK, not required to be there. return key; } + } + + static { + LibraryAccessor.DEFAULT = new LibraryAccessor () { + public Library createLibrary (LibraryImplementation impl) { + return new Library (impl); + } + }; } } // end Library Index: src/org/netbeans/api/project/libraries/LibraryManager.java =================================================================== RCS file: /cvs/projects/libraries/src/org/netbeans/api/project/libraries/LibraryManager.java,v retrieving revision 1.4 diff -u -r1.4 LibraryManager.java --- src/org/netbeans/api/project/libraries/LibraryManager.java 26 Apr 2004 10:04:07 -0000 1.4 +++ src/org/netbeans/api/project/libraries/LibraryManager.java 13 Jan 2005 13:58:55 -0000 @@ -7,14 +7,17 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.api.project.libraries; +import java.io.IOException; import org.netbeans.api.project.libraries.Library; +import org.netbeans.modules.project.libraries.WriteableLibraryProvider; +import org.netbeans.spi.project.libraries.LibraryFactory; import org.netbeans.spi.project.libraries.LibraryImplementation; import org.netbeans.spi.project.libraries.LibraryProvider; import org.openide.util.Lookup; @@ -98,7 +101,7 @@ this.currentStorages.add (storage); LibraryImplementation[] impls = storage.getLibraries(); for (int i=0; i*/ providers = result.allInstances(); + assert providers.size() == 1; + ((WriteableLibraryProvider)providers.iterator().next()).addLibrary(library.getLibraryImplementation()); + } + + /** + * Removes installed library + * @param library to be removed. + * @throws IOException when library can not be deleted. + * @throws IllegalArgumentException when library is not installed in writeable + * {@link org.netbeans.spi.project.libraries.LibraryProvider} + * @since org.netbeans.modules.project.libraries/1 1.10 + */ + public void removeLibrary (Library library) throws IOException, IllegalArgumentException { + Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template (WriteableLibraryProvider.class)); + Collection/**/ providers = result.allInstances(); + assert providers.size() == 1; + ((WriteableLibraryProvider)providers.iterator().next()).removeLibrary(library.getLibraryImplementation()); } /** Index: src/org/netbeans/modules/project/libraries/LibraryAccessor.java =================================================================== RCS file: src/org/netbeans/modules/project/libraries/LibraryAccessor.java diff -N src/org/netbeans/modules/project/libraries/LibraryAccessor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/project/libraries/LibraryAccessor.java 13 Jan 2005 13:58:56 -0000 @@ -0,0 +1,34 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.project.libraries; + +import org.netbeans.api.project.libraries.Library; +import org.netbeans.spi.project.libraries.LibraryImplementation; + +/** + * + * @author Tomas Zezula + */ +public abstract class LibraryAccessor { + + public static LibraryAccessor DEFAULT; + + // force loading of Library class. That will set DEFAULT variable. + static { + Object o = Library.class; + } + + public abstract Library createLibrary (LibraryImplementation libraryImplementation); + +} Index: src/org/netbeans/spi/project/libraries/LibraryFactory.java =================================================================== RCS file: src/org/netbeans/spi/project/libraries/LibraryFactory.java diff -N src/org/netbeans/spi/project/libraries/LibraryFactory.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/spi/project/libraries/LibraryFactory.java 13 Jan 2005 13:58:56 -0000 @@ -0,0 +1,43 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.spi.project.libraries; + +import org.netbeans.api.project.libraries.Library; +import org.netbeans.modules.project.libraries.LibraryAccessor; + +/** + * Most general way to create {@link Library} instances. + * You are not permitted to create them directly; instead you implement + * {@link LibraryImplementation} and use this factory. + * See also {@link org.netbeans.spi.project.libraries.support.LibrariesSupport} + * for easier ways to create {@link LibraryImplementation}. + * @since org.netbeans.modules.project.libraries/1 1.10 + * @author Tomas Zezula + */ +public class LibraryFactory { + + private LibraryFactory() { + } + + + /** + * Creates Library for LibraryImplementation + * @param libraryImplementation the library SPI object + * @return Library API instance + */ + public static Library createLibrary (LibraryImplementation libraryImplementation) { + return LibraryAccessor.DEFAULT.createLibrary(libraryImplementation); + } + +} Index: src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java =================================================================== RCS file: /cvs/projects/libraries/src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java,v retrieving revision 1.2 diff -u -r1.2 LibrariesSupport.java --- src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java 16 Mar 2004 15:35:01 -0000 1.2 +++ src/org/netbeans/spi/project/libraries/support/LibrariesSupport.java 13 Jan 2005 13:58:56 -0000 @@ -12,8 +12,10 @@ */ package org.netbeans.spi.project.libraries.support; +import org.netbeans.modules.project.libraries.LibraryTypeRegistry; import org.netbeans.spi.project.libraries.LibraryImplementation; import org.netbeans.modules.project.libraries.DefaultLibraryImplementation; +import org.netbeans.spi.project.libraries.LibraryTypeProvider; /** * SPI Support class. @@ -33,5 +35,26 @@ */ public static LibraryImplementation createLibraryImplementation (String libraryType, String[] volumeTypes) { return new DefaultLibraryImplementation (libraryType, volumeTypes); + } + + /** + * Returns registered {@link LibraryTypeProvider} for given library type. This method + * is mostly used by {@link org.netbeans.spi.project.libraries.LibraryProvider} implementators. + * @param libraryType the type of library for which the provider should be returned. + * @return {@link LibraryTypeProvider} for given library type or null, if none is registered. + * @since org.netbeans.modules.project.libraries/1 1.10 + */ + public static LibraryTypeProvider getLibraryTypeProvider (String libraryType) { + return LibraryTypeRegistry.getDefault().getLibraryTypeProvider(libraryType); + } + + /** + * Returns all registered {@link LibraryTypeProvider}s. This method + * is mostly used by {@link org.netbeans.spi.project.libraries.LibraryProvider} implementators. + * @return an array of {@link LibraryTypeProvider}, never returns null. + * @since org.netbeans.modules.project.libraries/1 1.10 + */ + public static LibraryTypeProvider[] getLibraryTypeProviders () { + return LibraryTypeRegistry.getDefault().getLibraryTypeProviders(); } }