+ @SuppressWarnings("unchecked")
+ private <T extends Node<?>> T pruneDataAtDepth( T node, Integer depth ) {
+ if( depth == null ) {
+ return node;
+ }
+
+ if( node instanceof CompositeNode ) {
+ ImmutableList.Builder<Node<?>> newChildNodes = ImmutableList.<Node<?>> builder();
+ if( depth > 1 ) {
+ for( Node<?> childNode: ((CompositeNode)node).getValue() ) {
+ newChildNodes.add( pruneDataAtDepth( childNode, depth - 1 ) );
+ }
+ }
+
+ return (T) ImmutableCompositeNode.create( node.getNodeType(), newChildNodes.build() );
+ }
+ else { // SimpleNode
+ return node;
+ }
+ }
+
+ private Integer parseDepthParameter( UriInfo info ) {
+ String param = info.getQueryParameters( false ).getFirst( "depth" );
+ if( Strings.isNullOrEmpty( param ) || "unbounded".equals( param ) ) {
+ return null;
+ }
+
+ try {
+ Integer depth = Integer.valueOf( param );
+ if( depth < 1 ) {
+ throw new RestconfDocumentedException( new RestconfError(
+ ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, "Invalid depth parameter: " + depth,
+ null, "The depth parameter must be an integer > 1 or \"unbounded\"" ) );
+ }
+
+ return depth;
+ }
+ catch( NumberFormatException e ) {
+ throw new RestconfDocumentedException( new RestconfError(
+ ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
+ "Invalid depth parameter: " + e.getMessage(),
+ null, "The depth parameter must be an integer > 1 or \"unbounded\"" ) );
+ }
+ }
+