    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements. See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache license, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License. You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the license for the specific language governing permissions and
    015     * limitations under the license.
    016     */
    017    package org.apache.logging.log4j.core.config.plugins;
    018
    019    import java.lang.annotation.Documented;
    020    import java.lang.annotation.ElementType;
    021    import java.lang.annotation.Retention;
    022    import java.lang.annotation.RetentionPolicy;
    023    import java.lang.annotation.Target;
    024
    025    import org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor;
    026    import org.apache.logging.log4j.util.Strings;
    027
    028    /**
    029     * Identifies a Plugin Attribute and its default value. Note that only one of the defaultFoo attributes will be
    030     * used based on the type this annotation is attached to. Thus, for primitive types, the default<i>Type</i>
    031     * attribute will be used for some <i>Type</i>. However, for more complex types (including enums), the default
    032     * string value is used instead and should correspond to the string that would correctly convert to the appropriate
    033     * enum value using {@link Enum#valueOf(Class, String) Enum.valueOf}.
    034     */
    035    @Documented
    036    @Retention(RetentionPolicy.RUNTIME)
    037    @Target({ElementType.PARAMETER, ElementType.FIELD})
    038    @PluginVisitorStrategy(PluginAttributeVisitor.class)
    039    public @interface PluginAttribute {
    040
    041        /**
    042         * Specifies the default boolean value to use.
    043         */
    044        boolean defaultBoolean() default false;
    045
    046        /**
    047         * Specifies the default byte value to use.
    048         */
    049        byte defaultByte() default 0;
    050
    051        /**
    052         * Specifies the default byte value to use.
    053         */
    054        char defaultChar() default 0;
    055
    056        /**
    057         * Specifies the default {@link Class} value to use.
    058         */
    059        Class<?> defaultClass() default Object.class;
    060
    061        /**
    062         * Specifies the default double floating point value to use.
    063         */
    064        double defaultDouble() default 0.0d;
    065
    066        /**
    067         * Specifies the default floating point value to use.
    068         */
    069        float defaultFloat() default 0.0f;
    070
    071        /**
    072         * Specifies the default integer value to use.
    073         */
    074        int defaultInt() default 0;
    075
    076        /**
    077         * Specifies the default long value to use.
    078         */
    079        long defaultLong() default 0L;
    080
    081        /**
    082         * Specifies the default long value to use.
    083         */
    084        short defaultShort() default 0;
    085
    086        /**
    087         * Specifies the default value this attribute should use if none is provided or if the provided value is invalid.
    088         */
    089        String defaultString() default Strings.EMPTY;
    090
    091        // TODO: could we allow a blank value and infer the attribute name through reflection?
    092        /**
    093         * Specifies the name of the attribute (case-insensitive) this annotation corresponds to.
    094         */
    095        String value();
    096
    097        /**
    098         * Indicates that this attribute is a sensitive one that shouldn't be logged directly. Such attributes will instead
    099         * be output as a hashed value.
    100         */
    101        boolean sensitive() default false;
    102
    103    }