Class Resource.Builder

java.lang.Object
org.glassfish.jersey.server.model.Resource.Builder
Enclosing class:
Resource

public static final class Resource.Builder extends Object
Resource model component builder.
  • Method Details

    • name

      public Resource.Builder name(String name)
      Define a new name of the built resource.

      The resource model name is typically used for reporting purposes (e.g. validation etc.).

      Parameters:
      name - new name of the resource.
      Returns:
      updated builder object.
      See Also:
    • path

      public Resource.Builder path(String path)
      Define a new path for the built resource.

      NOTE: Invoking this method marks a resource as a root resource.

      Parameters:
      path - new path for the resource.
      Returns:
      updated builder object.
    • addMethod

      public ResourceMethod.Builder addMethod(String httpMethod)
      Add a new method model to the resource for processing requests of the specified HTTP method.

      The returned builder is automatically bound to the the resource. It is not necessary to invoke the build() method on the method builder after setting all the data. This will be done automatically when the resource is built.

      Parameters:
      httpMethod - HTTP method that will be processed by the method.
      Returns:
      a new resource method builder.
    • addMethod

      public ResourceMethod.Builder addMethod()
      Add a new arbitrary method model to the resource.

      The returned builder is automatically bound to the the resource. It is not necessary to invoke the build() method on the method builder after setting all the data. This will be done automatically when the resource is built.

      Returns:
      a new resource method builder.
    • addMethod

      public ResourceMethod.Builder addMethod(ResourceMethod resourceMethod)
      Add a new method model that is a copy of the given resourceMethod.

      The returned builder is automatically bound to the the resource. It is not necessary to invoke the build() method on the method builder after setting all the data. This will be done automatically when the resource is built.

      Parameters:
      resourceMethod - The resource method based on which the new method builder should be created.
      Returns:
      a new resource method builder.
    • updateMethod

      public ResourceMethod.Builder updateMethod(ResourceMethod resourceMethod)
      Get a method builder for an existing resource method.

      The original method is removed from the resource and a builder based on it is added.

      Parameters:
      resourceMethod - The resource method to be replaced by a builder.
      Returns:
      a new resource method builder.
      Throws:
      IllegalArgumentException - in case the method to be updated is not registered in this resource builder.
      Since:
      2.18
    • addChildResource

      public Resource.Builder addChildResource(String relativePath)
      Add a new child resource to the resource.

      The returned builder is automatically bound to the the resource. It is not necessary to invoke the build() method on the resource builder after setting all the data. This will be done automatically when the resource is built.

      Parameters:
      relativePath - The path of the new child resource relative to this resource.
      Returns:
      child resource builder.
      Throws:
      IllegalStateException - in case the child resource for this path exists already.
    • addChildResource

      public void addChildResource(Resource resource)
      Add an existing Resource as a child resource of current resource.
      Parameters:
      resource - Resource to be added as child resource.
    • replaceChildResource

      public void replaceChildResource(Resource replacedResource, Resource newResource)
      Replace an existing child resource with a newly supplied one.
      Parameters:
      replacedResource - old resource to be replaced.
      newResource - new resource to add.
      Throws:
      IllegalArgumentException - in case there is no such child resource to be replaced.
      Since:
      2.18
    • mergeWith

      public Resource.Builder mergeWith(Resource resource)
      Merge methods from a given resource model into this resource model builder.
      Parameters:
      resource - to be merged into this resource model builder.
      Returns:
      updated builder object.
    • extended

      public Resource.Builder extended(boolean extended)
      Set the flag indicating whether the resource is extended or is a core of exposed RESTful API.

      The method defines the flag available at Resource.isExtended().

      Extended resource model components are helper components that are not considered as a core of a RESTful API. These can be for example OPTIONS resource methods added by model processors or application.wadl resource producing the WADL. Both resource are rather supportive than the core of RESTful API.

      If not set the resource will not be defined as extended by default.

      Parameters:
      extended - If true then resource is marked as extended.
      Returns:
      updated builder object.
      Since:
      2.5.1
      See Also:
    • mergeWith

      public Resource.Builder mergeWith(Resource.Builder resourceBuilder)
      Merge methods from a given resource model builder into this resource model builder.

      NOTE: Any "open" method builders in the supplied resourceBuilder that have not been explicitly converted to method models will be closed as part of this merge operation before merging the resource builder instances.

      Parameters:
      resourceBuilder - to be merged into this resource model builder.
      Returns:
      updated builder object.
    • build

      public Resource build()
      Build a new resource model.
      Returns:
      new (immutable) resource model.
    • toString

      public String toString()
      Overrides:
      toString in class Object