Class RestMixin
- Direct Known Subclasses:
DumpsMixin,ErrorMixin,FaviconMixin,HealthMixin,HtdocMixin,InfoMixin,LoggersMixin,MetricsMixin,NavigationMixin,SeoMixin,StatsMixin,VersionMixin,WellKnownMixin
RestServlet
(servlet flavor) and RestResource (child-resource flavor), completing the
servlet / resource / mixin naming triad.
A mixin is a plain @Rest-annotated POJO whose @RestOp methods are pulled
into a host servlet/resource context when the host declares
@Rest(mixins=ThatMixin.class). Mixins compose through the existing sub-context
model; RestMixin does not change that composition mechanism.
Opt-in, not mandatory:
Extending RestMixin is optional. A bare @Rest POJO with no base class remains a
fully-supported mixin (annotation-only configuration), exactly as before — the framework reads
such mixins reflectively. Capability mixins that ship without state (e.g. the api-docs pack) stay
base-less; the new single-responsibility op-mixins extend this base to make the triad membership
explicit.
Builder support:
The fluent programmatic-builder surface (RestBuilder/ RestMixin.Builder) lets a mixin be configured
programmatically rather than (or in addition to) by annotation — builder-supplied values take precedence
over @Rest annotation values. Use builder(Class) for the common case, or subclass
RestMixin.Builder for capability mixins that add their own setters.
Reaching the host resource:
Because a mixin's @RestOp methods are bound to a per-mixin RestContext sub-context (the
sub-context has no children of its own), host-level introspection performed against the mixin's own
context comes back empty. getHostContext() bridges that gap: it returns the RestContext of
the host (mixed-into) resource so a mixin op can enumerate the host's child resources, swagger, stats, etc.
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRestMixin.Builder<R extends RestMixin,SELF extends RestMixin.Builder<R, SELF>> Fluent builder for programmatically configuring aRestMixinsubclass.static final classRestMixin.DefaultBuilder<R extends RestMixin>Concrete default leaf builder returned bybuilder(Class)for the common (non-subclassed) case. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedRestMixin(RestBuilder<?> builder) Builder-injection constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends RestMixin>
RestMixin.DefaultBuilder<R>Creates a new fluent builder for programmatically configuring an instance of the specified mixin type.Returns theRestContextof the host (mixed-into) resource this mixin is composed into.RestBuilder<?>Returns the programmatic configuration builder stashed on this mixin, ornull if none.protected voidsetContext(RestContext value) Captures the per-mixinRestContextsub-context this mixin instance is bound to.
-
Constructor Details
-
RestMixin
protected RestMixin()Default constructor. -
RestMixin
Builder-injection constructor.- Parameters:
builder- The programmatic configuration builder. May benull .
-
-
Method Details
-
getRestBuilder
Returns the programmatic configuration builder stashed on this mixin, ornull if none.- Returns:
- The stashed builder, or
null if none was injected.
-
builder
Creates a new fluent builder for programmatically configuring an instance of the specified mixin type.- Type Parameters:
R- The mixin type.- Parameters:
type- The mixin type to build. Must not benull .- Returns:
- A new builder.
-
setContext
Captures the per-mixinRestContextsub-context this mixin instance is bound to.Invoked reflectively by the host's
RestContext.buildMixinContext(...)while composing the mixin (mirroring thesetContext(RestContext)contract honored byRestServletandRestResourcefor child resources). The supplied context is the mixin sub-context whoseparentis the host — that linkage is whatgetHostContext()reads.- Parameters:
value- The mixin sub-context. Must not benull .
-
getHostContext
Returns theRestContextof the host (mixed-into) resource this mixin is composed into.A mixin's
@RestOpmethods are bound to a per-mixin sub-context that has no children of its own; this accessor returns the host context so a mixin op (or config-time code) can introspect the host — most commonly its child resources viaRestContext.getRestChildren()for the navigation page. It is backed by the mixin sub-context's already-populatedparent linkage, so it is usable at config time and does not depend on an in-flight request.Edge cases:
- Standalone / no host — when a
RestMixinsubclass is instantiated directly rather than composed via@Rest(mixins=...), this returnsnull, mirroringRestContext.getParentContext()'s top-level contract. Callers needing host-only behavior should null-check. - Nested mixins — under nested
@Rest(mixins=...)the flat-inheritance rule collects every mixin as a mixin of the single top-level host, so this returns that top-level host (never an intermediate mixin).
- Returns:
- The host resource's
RestContext, ornullwhen this mixin is not composed into a host. - Since:
- 10.0.0
- Standalone / no host — when a
-