ramanathan1504 commented on code in PR #4116:
URL: https://github.com/apache/logging-log4j2/pull/4116#discussion_r3570862580
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentBuilder.java:
##########
@@ -17,104 +17,214 @@
package org.apache.logging.log4j.core.config.builder.impl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.builder.api.Component;
import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
+import org.jspecify.annotations.NonNull;
+import org.jspecify.annotations.Nullable;
+import org.osgi.annotation.versioning.ProviderType;
/**
- * Generic component that captures attributes and Components in preparation
for assembling the Appender's
- * Component.
+ * Generic base default {@link ComponentBuilder} implementation that captures
attributes and children
+ * which are used to build a new {@link Component} instance.
*
+ * @param <T> the type of the component builder
+ * @param <CB> the type of the configuration builder
* @since 2.4
*/
+@ProviderType
class DefaultComponentBuilder<T extends ComponentBuilder<T>, CB extends
ConfigurationBuilder<? extends Configuration>>
implements ComponentBuilder<T> {
private final CB builder;
- private final String type;
+ private final String pluginType;
private final Map<String, String> attributes = new LinkedHashMap<>();
private final List<Component> components = new ArrayList<>();
- private final String name;
- private final String value;
-
- public DefaultComponentBuilder(final CB builder, final String type) {
- this(builder, null, type, null);
+ private final @Nullable String name;
+ private final @Nullable String value;
+
+ /**
+ * Constructs a new instance with the given configuration builder and
plugin-type with {@code null} name and value.
+ * @param builder the configuration builder
+ * @param pluginType the plugin-type of the component being built
+ * @throws NullPointerException if either {@code builder} or {@code type}
argument is null
+ */
+ public DefaultComponentBuilder(final CB builder, final String pluginType) {
+ this(builder, pluginType, null, null);
}
- public DefaultComponentBuilder(final CB builder, final String name, final
String type) {
- this(builder, name, type, null);
+ /**
+ * Constructs a new instancer with the given configuration builder,
plugin-type, name, and {@code null} value.
+ * @param builder the configuration builder
+ * @param pluginType the plugin-type of the component being built
+ * @param name the component name
+ * @throws NullPointerException if either {@code builder} or {@code type}
argument is null
+ */
+ public DefaultComponentBuilder(final CB builder, final String pluginType,
final @Nullable String name) {
+ this(builder, pluginType, name, null);
}
-
- public DefaultComponentBuilder(final CB builder, final String name, final
String type, final String value) {
- this.type = type;
- this.builder = builder;
+ /**
+ * Constructs a new instance with the given configuration builder,
plugin-type, name and value.
+ * @param builder the configuration builder
+ * @param pluginType the type (plugin-type) of the component being built
+ * @param name the component name
+ * @param value the component value
+ * @throws NullPointerException if either {@code builder} or {@code type}
argument is null
+ */
+ public DefaultComponentBuilder(
+ final CB builder, final String pluginType, final @Nullable String
name, final @Nullable String value) {
+ super();
+ this.builder = Objects.requireNonNull(builder, "The 'builder' argument
must not be null.");
+ this.pluginType = Objects.requireNonNull(pluginType, "The 'type'
argument must not be null.");
this.name = name;
this.value = value;
}
+ /** {@inheritDoc} */
@Override
- public T addAttribute(final String key, final boolean value) {
- return put(key, Boolean.toString(value));
+ public Component build() {
+ final Component component = new Component(pluginType, name, value);
+ component.getAttributes().putAll(attributes);
+ component.getComponents().addAll(components);
+ return component;
}
+ /** {@inheritDoc} */
@Override
- public T addAttribute(final String key, final Enum<?> value) {
- return put(key, value.name());
+ public T addComponent(final ComponentBuilder<?> builder) {
+ Objects.requireNonNull(builder, "The 'builder' argument must not be
null.");
+ components.add(builder.build());
+ return self();
}
+ /** {@inheritDoc} */
@Override
- public T addAttribute(final String key, final int value) {
- return put(key, Integer.toString(value));
+ public @NonNull CB getBuilder() {
Review Comment:
@vy b4cd155
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]