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;
018
019 import org.apache.logging.log4j.Logger;
020 import org.apache.logging.log4j.core.config.plugins.Plugin;
021 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
022 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
023 import org.apache.logging.log4j.core.config.plugins.PluginValue;
024 import org.apache.logging.log4j.status.StatusLogger;
025
026 /**
027 * Represents a key/value pair in the configuration.
028 */
029 @Plugin(name = "property", category = "Core", printObject = true)
030 public 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 * Create a Property.
060 * @param key The key.
061 * @param value The value.
062 * @return A Property.
063 */
064 @PluginFactory
065 public static Property createProperty(@PluginAttr("name") final String key,
066 @PluginValue("value") final String value) {
067 if (key == null) {
068 LOGGER.error("Property key cannot be null");
069 }
070 return new Property(key, value);
071 }
072
073 @Override
074 public String toString() {
075 return name + "=" + value;
076 }
077 }