All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rxmicro.cdi.Resource Maven / Gradle / Ivy

Go to download

The module that is an implementation of the Dependency Injection design pattern, that is integrated to the RxMicro framework.

The newest version!
/*
 * 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.CLASS;

/**
 * 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(CLASS) @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: *