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;
28 import java.util.stream.Collectors;
29 import javax.annotation.Nonnull;
30 import javax.annotation.concurrent.NotThreadSafe;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Builder for {@link FlatWriterRegistry} allowing users to specify inter-writer relationships.
40 public final class FlatWriterRegistryBuilder
41 extends AbstractSubtreeManagerRegistryBuilderBuilder<Writer<? extends DataObject>, WriterRegistry>
42 implements ModifiableWriterRegistryBuilder, WriterRegistryBuilder {
44 private static final Logger LOG = LoggerFactory.getLogger(FlatWriterRegistryBuilder.class);
46 public FlatWriterRegistryBuilder(@Nonnull final YangDAG yangDAG) {
51 protected Writer<? extends DataObject> getSubtreeHandler(final @Nonnull Set<InstanceIdentifier<?>> handledChildren,
52 final @Nonnull Writer<? extends DataObject> writer) {
53 return SubtreeWriter.createForWriter(handledChildren, writer);
57 * Create FlatWriterRegistry with writers ordered according to submitted relationships.
60 public WriterRegistry build() {
61 final ImmutableMap<InstanceIdentifier<?>, Writer<?>> mappedWriters = getMappedHandlers();
62 LOG.debug("Building writer registry with writers: {}",
63 mappedWriters.keySet().stream()
64 .map(InstanceIdentifier::getTargetType)
65 .map(Class::getSimpleName)
66 .collect(Collectors.joining(", ")));
67 LOG.trace("Building writer registry with writers: {}", mappedWriters);
68 return new FlatWriterRegistry(mappedWriters);
73 protected ImmutableMap<InstanceIdentifier<?>, Writer<? extends DataObject>> getMappedHandlers() {
74 return super.getMappedHandlers();