/* * 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 org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; import com.google.common.base.Preconditions; public final class ImmutableLeafSetNodeSchemaAwareBuilder extends ImmutableLeafSetNodeBuilder { private final LeafListSchemaNode schema; private ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) { this.schema = Preconditions.checkNotNull(schema); super.withNodeIdentifier(new InstanceIdentifier.NodeIdentifier(schema.getQName())); } public ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema, final ImmutableLeafSetNode node) { super(node); this.schema = Preconditions.checkNotNull(schema); // FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier())); super.withNodeIdentifier(new InstanceIdentifier.NodeIdentifier(schema.getQName())); } public static ListNodeBuilder> create(final LeafListSchemaNode schema) { return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema); } public static ListNodeBuilder> create(final LeafListSchemaNode schema, final LeafSetNode node) { if (!(node instanceof ImmutableLeafSetNode)) { throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass())); } return new ImmutableLeafSetNodeSchemaAwareBuilder(schema, (ImmutableLeafSetNode) node); } @Override public ListNodeBuilder> withChildValue(final T value) { // TODO check value type return super.withChildValue(value); } @Override public ListNodeBuilder> withChild(final LeafSetEntryNode child) { Preconditions.checkArgument(schema.getQName().equals(child.getNodeType()), "Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType()); return super.withChild(child); } @Override public ListNodeBuilder> withNodeIdentifier(final InstanceIdentifier.NodeIdentifier nodeIdentifier) { throw new UnsupportedOperationException("Node identifier created from schema"); } }