io.rxmicro.cdi.Resource Maven / Gradle / Ivy
Show all versions of rxmicro-cdi Show documentation
/*
* Copyright (c) 2020. https://rxmicro.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.rxmicro.cdi;
import io.rxmicro.cdi.resource.ResourceConverter;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.SOURCE;
/**
* Indicates the need to inject the external resource into the annotated class field or method parameter.
*
*
* External resource is:
*
* - File
* - Directory
* - Classpath resource
* - URL Resource
* - etc
*
*
*
* The RxMicro framework uses blocking API to inject resource during startup!
*
* @author nedis
* @see Inject
* @see Autowired
* @since 0.6
*/
@Documented
@Retention(SOURCE)
@Target({FIELD, CONSTRUCTOR, METHOD, PARAMETER})
public @interface Resource {
/**
* If {@code true}, and the appropriate resource is not found, the RxMicro framework will skip injection of this
* method or field rather than produce an error.
*
*
* When applied to a field, any default value already assigned to the field will remain for optional injection.
*
*
* (The RxMicro framework will not actively null out the field).
*
* @return {@code true} if current injection point is optional
*/
boolean optional() default false;
/**
* Returns the resource path.
*
*
* Example of valid resource paths:
*
* - {@code /home/rxmicro/config.json}
* - {@code /home/rxmicro/config.properties}
* - {@code file:///home/rxmicro/config.json}
* - {@code file:///home/rxmicro/config.properties}
* - {@code classpath:config.json}
* - {@code classpath:config.properties}
*
*
* @return the resource path
*/
String value();
/**
* Returns the custom resource converter class.
*
*
* If converter class is not specified, the RxMicro framework tries to detect valid resource converter automatically.
*
*
* Autodetect resource converter rules:
*
* -
* {@link io.rxmicro.cdi.resource.ClasspathJsonArrayResourceConverter} is used if:
*
* - Resource path starts with {@code classpath:} prefix
* - Resource path ends with {@code json} extension
* - Annotated by @{@link Resource} annotation field has {@link java.util.List}{@code
*
*
* -
* {@link io.rxmicro.cdi.resource.ClasspathJsonObjectResourceConverter} is used if:
*
* - Resource path starts with {@code classpath:} prefix
* - Resource path ends with {@code json} extension
* - Annotated by @{@link Resource} annotation field has {@link java.util.Map}{@code
} type
*
*
* -
* {@link io.rxmicro.cdi.resource.ClasspathPropertiesResourceConverter} is used if:
*
* - Resource path starts with {@code classpath:} prefix
* - Resource path ends with {@code properties} extension
*
*
* -
* {@link io.rxmicro.cdi.resource.FileJsonArrayResourceConverter} is used if:
*
* - Resource path starts with {@code file://} prefix or prefix is missing
* - Resource path ends with {@code json} extension
* - Annotated by @{@link Resource} annotation field has {@link java.util.List}{@code
*
*
* -
* {@link io.rxmicro.cdi.resource.FileJsonObjectResourceConverter} is used if:
*
* - Resource path starts with {@code file://} prefix or prefix is missing
* - Resource path ends with {@code json} extension
* - Annotated by @{@link Resource} annotation field has {@link java.util.Map}{@code
} type
*
*
* -
* {@link io.rxmicro.cdi.resource.FilePropertiesResourceConverter} is used if:
*
* - Resource path starts with {@code file://} prefix or prefix is missing
* - Resource path ends with {@code properties} extension
*
*
*
*
*
* @return the custom resource converter class
* @see io.rxmicro.cdi.resource.ClasspathJsonArrayResourceConverter
* @see io.rxmicro.cdi.resource.ClasspathJsonObjectResourceConverter
* @see io.rxmicro.cdi.resource.ClasspathPropertiesResourceConverter
* @see io.rxmicro.cdi.resource.FileJsonArrayResourceConverter
* @see io.rxmicro.cdi.resource.FileJsonObjectResourceConverter
* @see io.rxmicro.cdi.resource.FilePropertiesResourceConverter
*/
Class extends ResourceConverter> converterClass() default ResourceConverter.class;
}