/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl; import java.util.Map; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode; import com.google.common.base.Preconditions; public class ImmutableAugmentationNodeBuilder extends AbstractImmutableDataContainerNodeBuilder { public static DataContainerNodeBuilder create() { return new ImmutableAugmentationNodeBuilder(); } @Override public DataContainerNodeBuilder withChild( DataContainerChild child) { // Check nested augments Preconditions.checkArgument(child instanceof AugmentationNode == false, "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(), nodeIdentifier == null ? this : nodeIdentifier); return super.withChild(child); } @Override public AugmentationNode build() { return new ImmutableAugmentationNode(nodeIdentifier, value); } static final class ImmutableAugmentationNode extends AbstractImmutableDataContainerNode implements AugmentationNode { ImmutableAugmentationNode(InstanceIdentifier.AugmentationIdentifier nodeIdentifier, Map> children) { super(children, nodeIdentifier); } } }