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 */
017package org.apache.logging.log4j.core.config;
018
019import org.apache.logging.log4j.Logger;
020import org.apache.logging.log4j.core.config.plugins.Plugin;
021import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
022import org.apache.logging.log4j.core.config.plugins.PluginFactory;
023import org.apache.logging.log4j.core.config.plugins.PluginValue;
024import org.apache.logging.log4j.status.StatusLogger;
025
026/**
027 * Represents a key/value pair in the configuration.
028 */
029@Plugin(name = "property", category = Node.CATEGORY, printObject = true)
030public final class Property {
031
032    private static final Logger LOGGER = StatusLogger.getLogger();
033
034    private final String name;
035    private final String value;
036
037    private Property(final String name, final String value) {
038        this.name = name;
039        this.value = value;
040    }
041
042    /**
043     * Returns the property name.
044     * @return the property name.
045     */
046    public String getName() {
047        return name;
048    }
049
050    /**
051     * Returns the property value.
052     * @return the value of the property.
053     */
054    public String getValue() {
055        return value;
056    }
057
058    /**
059     * Creates a Property.
060     * 
061     * @param name The key.
062     * @param value The value.
063     * @return A Property.
064     */
065    @PluginFactory
066    public static Property createProperty(
067            @PluginAttribute("name") final String name,
068            @PluginValue("value") final String value) {
069        if (name == null) {
070            LOGGER.error("Property name cannot be null");
071        }
072        return new Property(name, value);
073    }
074
075    @Override
076    public String toString() {
077        return name + '=' + value;
078    }
079}