Class Resources


  • public final class Resources
    extends Object
    This class contains methods for creating and manipulating connection factories and connections.
    • Field Detail

      • FIELD_VALUE_ALL_PTR

        public static final JsonPointer FIELD_VALUE_ALL_PTR
        JsonPointer used in fields to denote "all fields", i.e., no filtering.
    • Method Detail

      • filterResource

        public static JsonValue filterResource​(JsonValue resource,
                                               Collection<JsonPointer> fields)
        Returns a JSON object containing only the specified fields from the provided JSON value. If the list of fields is empty then the value is returned unchanged.

        NOTE: this method only performs a shallow copy of extracted fields, so changes to the filtered JSON value may impact the original JSON value, and vice-versa.

        Parameters:
        resource - The JSON value whose fields are to be filtered.
        fields - The list of fields to be extracted.
        Returns:
        The filtered JSON value.
      • filterResource

        public static ResourceResponse filterResource​(ResourceResponse resource,
                                                      Collection<JsonPointer> fields)
        Returns a JSON object containing only the specified fields from the provided resource. If the list of fields is empty then the resource is returned unchanged.

        NOTE: this method only performs a shallow copy of extracted fields, so changes to the filtered resource may impact the original resource, and vice-versa.

        Parameters:
        resource - The resource whose fields are to be filtered.
        fields - The list of fields to be extracted.
        Returns:
        The filtered resource.
      • newInternalConnection

        public static Connection newInternalConnection​(RequestHandler handler)
        Creates a new connection to a RequestHandler.
        Parameters:
        handler - The request handler to which client requests should be forwarded.
        Returns:
        The new internal connection.
        Throws:
        NullPointerException - If handler was null.
      • newInternalConnectionFactory

        public static ConnectionFactory newInternalConnectionFactory​(RequestHandler handler)
        Creates a new connection factory which binds internal client connections to RequestHandlers.
        Parameters:
        handler - The request handler to which client requests should be forwarded.
        Returns:
        The new internal connection factory.
        Throws:
        NullPointerException - If handler was null.
      • newHandler

        public static RequestHandler newHandler​(Object provider)
        Creates a new RequestHandler backed by the supplied provider. The provider can be an instance of an interface resource handler, and annotated resource handler or an annotated request handler. The type of the provider will be determined from the org.forgerock.api.annotations.RequestHandler#variant annotation property, or from the type of interface implemented.

        Sub-paths that are declared using the org.forgerock.api.annotations.Path annotation will also be routed through the returned handler.

        This method uses the same logic as newCollection(Object), newSingleton(Object) and newAnnotatedRequestHandler(Object) to create the underlying RequestHandlers.

        Parameters:
        provider - The provider instance.
        Returns:
        The constructed handler.
      • newCollection

        @Deprecated
        public static RequestHandler newCollection​(Object provider)
        Deprecated.
        Use newHandler(Object) instead.
        Returns a new request handler which will forward requests on to the provided collection resource provider. Incoming requests which are not appropriate for a resource collection or resource instance will result in a bad request error being returned to the client.
        Parameters:
        provider - The collection resource provider. Either an implementation of CollectionResourceProvider or a POJO annotated with annotations from org.forgerock.api.annotations.
        Returns:
        A new request handler which will forward requests on to the provided collection resource provider.
      • newSingleton

        @Deprecated
        public static RequestHandler newSingleton​(Object provider)
        Deprecated.
        Use newHandler(Object) instead.
        Returns a new request handler which will forward requests on to the provided singleton resource provider. Incoming requests which are not appropriate for a singleton resource (e.g. query) will result in a bad request error being returned to the client.
        Parameters:
        provider - The singleton resource provider. Either an implementation of SingletonResourceProvider or a POJO annotated with annotations from org.forgerock.api.annotations.
        Returns:
        A new request handler which will forward requests on to the provided singleton resource provider.
      • newAnnotatedRequestHandler

        @Deprecated
        public static RequestHandler newAnnotatedRequestHandler​(Object provider)
        Deprecated.
        Use newHandler(Object) instead.
        Returns a new request handler which will forward requests on to the provided annotated request handler.
        Parameters:
        provider - The POJO annotated with annotations from org.forgerock.api.annotations.
        Returns:
        A new request handler which will forward requests on to the provided annotated POJO.
      • uncloseable

        public static Connection uncloseable​(Connection connection)
        Returns an uncloseable view of the provided connection. Attempts to call Connection.close() will be ignored.
        Parameters:
        connection - The connection whose close method is to be disabled.
        Returns:
        An uncloseable view of the provided connection.
      • uncloseable

        public static ConnectionFactory uncloseable​(ConnectionFactory factory)
        Returns an uncloseable view of the provided connection factory. Attempts to call ConnectionFactory.close() will be ignored.
        Parameters:
        factory - The connection factory whose close method is to be disabled.
        Returns:
        An uncloseable view of the provided connection factory.