org.openide.util.lookup.implspi

## Class NamedServicesProvider

- java.lang.Object
- - org.openide.util.lookup.implspi.NamedServicesProvider

-     public abstract class NamedServicesProvider
      extends Object

  Infrastructure provider interface for those who control the overall registration of services in the system. The first instance of this interface found in `Lookup.getDefault()` is consulted when providing answers to `Lookups.forPath(java.lang.String)` queries. Current implementation is not ready for multiple instances of this interface (the first one wins) and also changing the instances during runtime.
  The basic implementation of this interface is provided in Filesystem API and recognizes the .instance files registered in XML layers. As such one can rely on .instance files being recognized in unit tests, if the Filesystem API is included. The implementation is then refined in Settings API to handle also .settings files. Again, including this module in unit tests ensures .settings files files are recognized.
  Since:
    8.1
  Author:
    Jaroslav Tulach

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `NamedServicesProvider()` Throws an exception.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract Lookup` | `create(String path)` Create the lookup for given path.
    `static Lookup` | `createLookupFor(Object obj)` Allows the providers to donate a special lookup for a given object.
    `static Lookup` | `forPath(String path)`
    `static <T> T` | `getConfigObject(String filePath, Class<T> type)` Finds a config object under given path.
    `protected Lookup` | `lookupFor(Object obj)` Method for providers to work in orchestration with `createLookupFor(java.lang.Object)`.
    `protected <T> T` | `lookupObject(String path, Class<T> type)` Finds a config object under given path.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NamedServicesProvider

          protected NamedServicesProvider()

      Throws an exception. Prevents unwanted instantiation of this class by unknown subclasses.

  - ### Method Detail

    - #### forPath

          public static Lookup forPath(String path)

    - #### getConfigObject

          public static <T> T getConfigObject(String filePath,
                                              Class<T> type)

      Finds a config object under given path.
      Parameters:
        `filePath` - path to .instance or .settings file
        `type` - the requested type for given object
      Returns:
        either null or instance of requested type
      Since:
        8.10

    - #### createLookupFor

          public static Lookup createLookupFor(Object obj)

      Allows the providers to donate a special lookup for a given object. Right now it is used only for obtaining `FileObject.getLookup`.
      Parameters:
        `obj` - the object to find lookup for
      Returns:
        `null` or new lookup to be associated with the `obj`
      Since:
        8.17

    - #### create

          protected abstract Lookup create(String path)

      Create the lookup for given path. Called as a result of query to `Lookups.forPath(java.lang.String)`.
      Parameters:
        `path` - the identification of the path
      Returns:
        the lookup representing objects in this path.

    - #### lookupObject

          protected <T> T lookupObject(String path,
                                       Class<T> type)

      Finds a config object under given path. Called from `FileUtil#getConfigObject`.
      Parameters:
        `filePath` - path to .instance or .settings file
        `type` - the requested type for given object
      Returns:
        either null or instance of requested type
      Since:
        8.10

    - #### lookupFor

          protected Lookup lookupFor(Object obj)

      Method for providers to work in orchestration with `createLookupFor(java.lang.Object)`. By default return `null`.
      Parameters:
        `obj` - the object to find lookup for
      Returns:
        `null` or new lookup to be associated with the `obj`
      Since:
        8.17

Copyright © 2025 API Design. All Rights Reserved.