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.builder.api;
018
019import java.util.ArrayList;
020import java.util.LinkedHashMap;
021import java.util.List;
022import java.util.Map;
023
024/**
025 * Container for building Configurations. This class is not normally directly manipulated by users
026 * of the Assembler API.
027 * @since 2.4
028 */
029public class Component {
030
031    private final Map<String, String> attributes = new LinkedHashMap<>();
032    private final List<Component> components = new ArrayList<>();
033    private final String pluginType;
034    private final String value;
035
036    public Component(final String pluginType) {
037        this(pluginType, null, null);
038    }
039
040    public Component(final String pluginType, final String name) {
041        this(pluginType, name, null);
042    }
043
044    public Component(final String pluginType, final String name, final String value) {
045        this.pluginType = pluginType;
046        this.value = value;
047        if (name != null && name.length() > 0) {
048            attributes.put("name", name);
049        }
050    }
051
052    public Component() {
053        this.pluginType = null;
054        this.value = null;
055    }
056
057
058    public String addAttribute(final String key, final String newValue) {
059        return attributes.put(key, newValue);
060    }
061
062    public void addComponent(final Component component) {
063        components.add(component);
064    }
065
066    public Map<String, String> getAttributes() {
067        return attributes;
068    }
069
070    public List<Component> getComponents() {
071        return components;
072    }
073
074    public String getPluginType() {
075        return pluginType;
076    }
077
078    public String getValue() {
079        return value;
080    }
081 }