2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.binding.data.codec.impl;
10 import java.util.List;
12 import org.opendaylight.yangtools.concepts.Codec;
13 import org.opendaylight.yangtools.yang.binding.Identifiable;
14 import org.opendaylight.yangtools.yang.binding.Identifier;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 class ListNodeCodecContext extends DataObjectCodecContext<ListSchemaNode> {
23 private final YangInstanceIdentifier.PathArgument yangIdentifier;
24 private final Codec<NodeIdentifierWithPredicates, IdentifiableItem<?, ?>> codec;
26 ListNodeCodecContext(final Class<?> cls, final ListSchemaNode nodeSchema, final CodecContextFactory loader) {
27 super(cls, nodeSchema.getQName().getModule(), nodeSchema, loader);
28 this.yangIdentifier = new YangInstanceIdentifier.NodeIdentifier(nodeSchema.getQName());
29 if (Identifiable.class.isAssignableFrom(cls)) {
30 this.codec = loader.getPathArgumentCodec(cls,nodeSchema);
37 public YangInstanceIdentifier.PathArgument getDomPathArgument() {
38 return yangIdentifier;
42 public void addYangPathArgument(final InstanceIdentifier.PathArgument arg, final List<YangInstanceIdentifier.PathArgument> builder) {
45 * DOM Instance Identifier for list is always represent by two
46 * entries one for map and one for children. This is also true for
47 * wildcarded instance identifiers
49 if (builder == null) {
52 super.addYangPathArgument(arg, builder);
53 if (arg instanceof IdentifiableItem<?, ?>) {
54 builder.add(codec.serialize((IdentifiableItem<?, ?>) arg));
57 super.addYangPathArgument(arg, builder);
62 public InstanceIdentifier.PathArgument getBindingPathArgument(
63 final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument domArg) {
64 if(domArg instanceof NodeIdentifierWithPredicates) {
65 return codec.deserialize((NodeIdentifierWithPredicates) domArg);
67 return super.getBindingPathArgument(domArg);
70 @SuppressWarnings({ "rawtypes", "unchecked" })
71 public NodeIdentifierWithPredicates serialize(final Identifier<?> key) {
72 return codec.serialize(new IdentifiableItem(bindingClass, key));