2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.impl.write.registry;
19 import com.google.common.annotations.VisibleForTesting;
20 import com.google.common.collect.ImmutableMap;
21 import io.fd.honeycomb.translate.util.AbstractSubtreeManagerRegistryBuilderBuilder;
22 import io.fd.honeycomb.translate.util.YangDAG;
23 import io.fd.honeycomb.translate.write.Writer;
24 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
25 import io.fd.honeycomb.translate.write.registry.WriterRegistry;
26 import io.fd.honeycomb.translate.write.registry.WriterRegistryBuilder;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import javax.annotation.Nonnull;
33 import javax.annotation.concurrent.NotThreadSafe;
35 import java.util.stream.Collectors;
38 * Builder for {@link FlatWriterRegistry} allowing users to specify inter-writer relationships.
41 public final class FlatWriterRegistryBuilder
42 extends AbstractSubtreeManagerRegistryBuilderBuilder<Writer<? extends DataObject>, WriterRegistry>
43 implements ModifiableWriterRegistryBuilder, WriterRegistryBuilder {
45 private static final Logger LOG = LoggerFactory.getLogger(FlatWriterRegistryBuilder.class);
47 public FlatWriterRegistryBuilder(@Nonnull final YangDAG yangDAG) {
52 protected Writer<? extends DataObject> getSubtreeHandler(final @Nonnull Set<InstanceIdentifier<?>> handledChildren,
53 final @Nonnull Writer<? extends DataObject> writer) {
54 return SubtreeWriter.createForWriter(handledChildren, writer);
58 protected Writer<? extends DataObject> getWildcardedSubtreeHandler(@Nonnull Writer<? extends DataObject> handler) {
59 return SubtreeWriter.createWildcardedForWriter(handler);
63 * Create FlatWriterRegistry with writers ordered according to submitted relationships.
66 public WriterRegistry build() {
67 final ImmutableMap<InstanceIdentifier<?>, Writer<?>> mappedWriters = getMappedHandlers();
68 LOG.debug("Building writer registry with writers: {}",
69 mappedWriters.keySet().stream()
70 .map(InstanceIdentifier::getTargetType)
71 .map(Class::getSimpleName)
72 .collect(Collectors.joining(", ")));
73 LOG.trace("Building writer registry with writers: {}", mappedWriters);
74 return new FlatWriterRegistry(mappedWriters);
79 protected ImmutableMap<InstanceIdentifier<?>, Writer<? extends DataObject>> getMappedHandlers() {
80 return super.getMappedHandlers();