Class Resource.Builder
java.lang.Object
org.glassfish.jersey.server.model.Resource.Builder
- Enclosing class:
Resource
Resource model component builder.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set
<Resource.Builder> private final List
<Resource.Data> private boolean
private final Set
<ResourceMethod.Builder> private final Resource.Builder
private String
private final List
<ResourceMethod.Data> private ResourceMethod.Data
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Builder()
private
private
Builder
(String path, Resource.Builder parentResource) private
Builder
(Resource.Builder parentResource) -
Method Summary
Modifier and TypeMethodDescriptionaddChildResource
(String relativePath) Add a new child resource to the resource.void
addChildResource
(Resource resource) Add an existing Resource as a child resource of current resource.Add a new arbitrary method model to the resource.Add a new method model to the resource for processing requests of the specified HTTP method.addMethod
(ResourceMethod resourceMethod) Add a new method model that is a copy of the givenresourceMethod
.private boolean
areAllMembersExtended
(List<Resource.Data> mergedChildResources) build()
Build a new resource model.private Resource.Data
extended
(boolean extended) Set the flag indicating whether the resource is extended or is a core of exposed RESTful API.private boolean
isEmpty()
(package private) boolean
Get the flag indicating whether the resource method is extended or is a core of exposed RESTful API.private List
<Resource.Data> mergeResources
(List<Resource.Data> resources) Merge methods from a given resource model into this resource model builder.mergeWith
(Resource.Builder resourceBuilder) Merge methods from a given resource model builder into this resource model builder.private Resource.Builder
mergeWith
(Resource.Data resourceData) Define a new name of the built resource.private void
onBuildChildResource
(Resource.Builder childResourceBuilder, Resource.Data childResourceData) (package private) void
onBuildMethod
(ResourceMethod.Builder builder, ResourceMethod.Data methodData) Called when a new resource, sub-resource and sub-resource locator method was built and should be registered with the resource builder.Define a new path for the built resource.private void
private void
void
replaceChildResource
(Resource replacedResource, Resource newResource) Replace an existing child resource with a newly supplied one.private String
toString()
updateMethod
(ResourceMethod resourceMethod) Get a method builder for an existing resource method.
-
Field Details
-
names
-
path
-
methodBuilders
-
childResourceBuilders
-
childResources
-
resourceMethods
-
subResourceLocator
-
handlerClasses
-
handlerInstances
-
parentResource
-
extended
private boolean extended
-
-
Constructor Details
-
Builder
-
Builder
-
Builder
-
Builder
private Builder()
-
-
Method Details
-
isEmpty
private boolean isEmpty() -
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
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
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
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
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
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
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
Add an existing Resource as a child resource of current resource.- Parameters:
resource
- Resource to be added as child resource.
-
replaceChildResource
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
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
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
OPTIONS
resource methods
added bymodel processors
orapplication.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
- Iftrue
then resource is marked as extended.- Returns:
- updated builder object.
- Since:
- 2.5.1
- See Also:
-
isExtended
boolean isExtended()Get the flag indicating whether the resource method is extended or is a core of exposed RESTful API.- Returns:
true
if the method is extended.
-
mergeWith
-
mergeWith
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 beenexplicitly 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.
-
onBuildMethod
Called when a new resource, sub-resource and sub-resource locator method was built and should be registered with the resource builder.This is a friend call-back API exposed for a use by a
ResourceMethod.Builder
.- Parameters:
builder
- builder instance that built the method.methodData
- new resource, sub-resource or sub-resource locator
-
onBuildChildResource
private void onBuildChildResource(Resource.Builder childResourceBuilder, Resource.Data childResourceData) -
mergeResources
-
buildResourceData
-
areAllMembersExtended
-
build
Build a new resource model.- Returns:
- new (immutable) resource model.
-
processMethodBuilders
private void processMethodBuilders() -
processChildResourceBuilders
private void processChildResourceBuilders() -
toString
-
shortToString
-