Netbeans RCP: external layer.xml

A Netbeans RCP application might benefit from an additional layer.xml file stored outside of application bundles. A network directory or a http server may provide some layer.xml with centralized or corporated configuration or user profiles, maintained the network administrator.

This article was first published at techtavern.wordpress.com

There are two solutions to add an additional layer.xml file to your application. Both solutions are provided by Netbeans RCP Toys at github.

LayerProvider

Register a LayerProvider using the @ServiceProvider(service = LayerProvider.class) annotation. The platform calls all LayerProvider.registerLayers(Collection<? super URL>) to populate the collection with URLs to additional layer files. This URL may refer a local file or a remote over HTTP. As this method is called early, your application might not yet know the URL. For example, it does not work for command line argument as they have not been parsed then LayerProvider.registerLayers() is called. This approach is file as long as your URLs are declared as static constants.

This solution is demonstrated by the Platform-Layer-Property example at Netbeans RCP Toys, which extracts the additional layer.xml URL from a system property.

Dynamic FileSystem

Register your own FileSystem instance using the @ServiceProvider(service = FileSystem.class) annotation. It will be instantiated early, but a FileSystem instance may change it content later when the additional layer.xml path is known. A custom and changeable FileSystem implementation is quite complex. Fortunately, the platform provides the DynamicLayer that may be extended to emulate the custom and changeable behavior.