Class Resource.Builder
- java.lang.Object
-
- org.glassfish.jersey.server.model.Resource.Builder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource.BuilderaddChildResource(String relativePath)Add a new child resource to the resource.voidaddChildResource(Resource resource)Add an existing Resource as a child resource of current resource.ResourceMethod.BuilderaddMethod()Add a new arbitrary method model to the resource.ResourceMethod.BuilderaddMethod(String httpMethod)Add a new method model to the resource for processing requests of the specified HTTP method.ResourceMethod.BuilderaddMethod(ResourceMethod resourceMethod)Add a new method model that is a copy of the givenresourceMethod.Resourcebuild()Build a new resource model.Resource.Builderextended(boolean extended)Set the flag indicating whether the resource is extended or is a core of exposed RESTful API.Resource.BuildermergeWith(Resource resource)Merge methods from a given resource model into this resource model builder.Resource.BuildermergeWith(Resource.Builder resourceBuilder)Merge methods from a given resource model builder into this resource model builder.Resource.Buildername(String name)Define a new name of the built resource.Resource.Builderpath(String path)Define a new path for the built resource.voidreplaceChildResource(Resource replacedResource, Resource newResource)Replace an existing child resource with a newly supplied one.StringtoString()ResourceMethod.BuilderupdateMethod(ResourceMethod resourceMethod)Get a method builder for an existing resource method.
-
-
-
Method Detail
-
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:
Resource.getName()
-
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 thebuild()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 thebuild()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 givenresourceMethod. The returned builder is automatically bound to the the resource. It is not necessary to invoke thebuild()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 thebuild()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 atResource.isExtended().Extended resource model components are helper components that are not considered as a core of a RESTful API. These can be for example
OPTIONSresource methodsadded bymodel processorsorapplication.wadlresource 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- Iftruethen resource is marked as extended.- Returns:
- updated builder object.
- Since:
- 2.5.1
- See Also:
ExtendedResource
-
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
resourceBuilderthat have not beenexplicitly converted to method modelswill 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.
-
-