Class DefaultHttpAnnotationParser<T extends HttpComponent<T>>
java.lang.Object
eu.cloudnetservice.driver.network.http.annotation.parser.DefaultHttpAnnotationParser<T>
- Type Parameters:
T- the type of http component associated with this parser.
- All Implemented Interfaces:
HttpAnnotationParser<T>
public final class DefaultHttpAnnotationParser<T extends HttpComponent<T>>
extends Object
implements HttpAnnotationParser<T>
The default implementation of a http annotation parser.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classA processor for the@FirstRequestQueryParamannotation.private static final classA processor for the@RequestBodyannotation.private static final classA processor for the@RequestHeaderannotation.private static final classA processor for the@RequestPathParamannotation.private static final classA processor for the@RequestPathannotation.private static final classA processor for the@RequestQueryParamannotation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Tstatic final Stringstatic final Stringprivate final Deque<HttpAnnotationProcessor> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultHttpAnnotationParser(T component) Constructs a new DefaultHttpAnnotationParser instance. -
Method Summary
Modifier and TypeMethodDescriptionGet an unmodifiable view of all annotation processors which were registered to this parser.applyDefault(@NonNull String defaultValue, @Nullable String actualValue) Returns the actual value if present, or the default value of an annotation.Get the http component which is associated with this parser.parseAndRegister(@NonNull Class<?> handlerClass) Parses all non-static http handlers methods annotated with@HttpRequestHandlerin the given class instance.parseAndRegister(@NonNull Object handlerInstance) Parses all non-static http handlers methods annotated with@HttpRequestHandlerin the given class instance.Registers an annotation processor to this parser.Registers all processors for the default provided http handling annotations.Unregisters an annotation processor from this parser if previously registered.unregisterAnnotationProcessors(@NonNull ClassLoader classLoader) Unregisters all annotation processors from this parser whose classes were loaded by the given class loader.static <T extends HttpComponent<T>>
@NonNull HttpAnnotationParser<T>withDefaultProcessors(T com) Constructs a new DefaultHttpAnnotationParser instance and registers all processors for the default provided http handling annotations.
-
Field Details
-
DEFAULTS_TO_NULL_MASK
- See Also:
-
PARAM_INVOCATION_HINT_KEY
- See Also:
-
component
-
processors
-
-
Constructor Details
-
DefaultHttpAnnotationParser
Constructs a new DefaultHttpAnnotationParser instance.- Parameters:
component- the component instance with which this parser is associated.- Throws:
NullPointerException- if the given component is null.
-
-
Method Details
-
applyDefault
@Nullable private static @Nullable Object applyDefault(@NonNull @NonNull String defaultValue, @Nullable @Nullable String actualValue) Returns the actual value if present, or the default value of an annotation. If the default value equals to__NULL__then null is returned, else the given default value.- Parameters:
defaultValue- the defined default value to unmask.actualValue- the actual value which is present from the request.- Returns:
- the actual value if present or the unmasked version of the default value.
- Throws:
NullPointerException- if the given default value is null.
-
withDefaultProcessors
@NonNull public static <T extends HttpComponent<T>> @NonNull HttpAnnotationParser<T> withDefaultProcessors(@NonNull T com) Constructs a new DefaultHttpAnnotationParser instance and registers all processors for the default provided http handling annotations.- Parameters:
com- the component instance with which this parser is associated.- Returns:
- the newly created HttpAnnotationParser instance.
- Throws:
NullPointerException- if the given component is null.
-
registerDefaultProcessors
Registers all processors for the default provided http handling annotations.- Returns:
- the same instance as used to call the method, for chaining.
-
httpComponent
Get the http component which is associated with this parser. All handlers parsed using this parser will get registered into that component.- Specified by:
httpComponentin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Returns:
- the http component associated with this parser.
-
annotationProcessors
@NonNull public @UnmodifiableView @NonNull Collection<HttpAnnotationProcessor> annotationProcessors()Get an unmodifiable view of all annotation processors which were registered to this parser.- Specified by:
annotationProcessorsin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Returns:
- all annotation processors registered to this parser.
-
registerAnnotationProcessor
@NonNull public @NonNull HttpAnnotationParser<T> registerAnnotationProcessor(@NonNull @NonNull HttpAnnotationProcessor processor) Registers an annotation processor to this parser.- Specified by:
registerAnnotationProcessorin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Parameters:
processor- the processor to register.- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterAnnotationProcessor
@NonNull public @NonNull HttpAnnotationParser<T> unregisterAnnotationProcessor(@NonNull @NonNull HttpAnnotationProcessor processor) Unregisters an annotation processor from this parser if previously registered.- Specified by:
unregisterAnnotationProcessorin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Parameters:
processor- the processor to unregister.- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterAnnotationProcessors
@NonNull public @NonNull HttpAnnotationParser<T> unregisterAnnotationProcessors(@NonNull @NonNull ClassLoader classLoader) Unregisters all annotation processors from this parser whose classes were loaded by the given class loader.- Specified by:
unregisterAnnotationProcessorsin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Parameters:
classLoader- the loader of the processor classes to unregister.- Returns:
- the same instance as used to call the method, for chaining.
-
parseAndRegister
@NonNull public @NonNull HttpAnnotationParser<T> parseAndRegister(@NonNull @NonNull Class<?> handlerClass) Parses all non-static http handlers methods annotated with@HttpRequestHandlerin the given class instance. This method will call all previously registered annotation processors and build context preprocessors from them, then register the final parsed handler to the http component associated with this parser.- Specified by:
parseAndRegisterin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Parameters:
handlerClass- the class in which the handler methods to register are located.- Returns:
- the same instance as used to call the method, for chaining.
-
parseAndRegister
@NonNull public @NonNull HttpAnnotationParser<T> parseAndRegister(@NonNull @NonNull Object handlerInstance) Parses all non-static http handlers methods annotated with@HttpRequestHandlerin the given class instance. This method will call all previously registered annotation processors and build context preprocessors from them, then register the final parsed handler to the http component associated with this parser.- Specified by:
parseAndRegisterin interfaceHttpAnnotationParser<T extends HttpComponent<T>>- Parameters:
handlerInstance- the instance of the class in which the handler methods to register are located.- Returns:
- the same instance as used to call the method, for chaining.
-