d370eb2deb5fc8ae6a9042e20f778454954e6314
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / NormalizedNodePrinter.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.cluster.datastore.node.utils;
12
13 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16
17 public class NormalizedNodePrinter implements NormalizedNodeVisitor {
18
19     private String spaces(int n){
20         StringBuilder builder = new StringBuilder();
21         for(int i=0;i<n;i++){
22             builder.append(' ');
23         }
24         return builder.toString();
25     }
26
27     @Override
28     public void visitNode(int level, String parentPath, NormalizedNode normalizedNode) {
29         System.out.println(spaces((level) * 4) + normalizedNode.getClass().toString() + ":" + normalizedNode.getIdentifier());
30         if(normalizedNode instanceof LeafNode || normalizedNode instanceof LeafSetEntryNode){
31             System.out.println(spaces((level) * 4) + " parentPath = " + parentPath);
32             System.out.println(spaces((level) * 4) + " key = " + normalizedNode.getClass().toString() + ":" + normalizedNode.getIdentifier());
33             System.out.println(spaces((level) * 4) + " value = " + normalizedNode.getValue());
34         }
35     }
36 }