BUG 1330 - list key counts|values diff in payload and URI
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / impl / ControllerContext.java
index 86ed13a2802bc98b4ddd9a259aa5ac1c329118e2..28e6a3c2472ee3b8723c82dc5d1050215c209bee 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.collect.BiMap;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.HashBiMap;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
@@ -40,8 +39,6 @@ import org.opendaylight.controller.sal.core.api.mount.MountInstance;
 import org.opendaylight.controller.sal.core.api.mount.MountService;
 import org.opendaylight.controller.sal.rest.api.Draft02;
 import org.opendaylight.controller.sal.rest.impl.RestUtil;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
-import org.opendaylight.controller.sal.restconf.impl.RestCodec;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.yangtools.concepts.Codec;
@@ -51,6 +48,7 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdent
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -84,6 +82,10 @@ public class ControllerContext implements SchemaContextListener {
 
     private final static String URI_ENCODING_CHAR_SET = "ISO-8859-1";
 
+    private static final Splitter SLASH_SPLITTER = Splitter.on('/');
+
+    private static final Splitter COLON_SPLITTER = Splitter.on(':');
+
     private final BiMap<URI, String> uriToModuleName = HashBiMap.<URI, String> create();
 
     private final Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
@@ -127,13 +129,11 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private InstanceIdWithSchemaNode toIdentifier( final String restconfInstance,
-                                                   final boolean toMountPointIdentifier ) {
+            final boolean toMountPointIdentifier ) {
         this.checkPreconditions();
 
-        Iterable<String> split = Splitter.on( "/" ).split( restconfInstance );
-        final ArrayList<String> encodedPathArgs = Lists.<String> newArrayList( split );
-        final List<String> pathArgs = this.urlPathArgsDecode( encodedPathArgs );
-        this.omitFirstAndLastEmptyString( pathArgs );
+        final List<String> pathArgs = urlPathArgsDecode( SLASH_SPLITTER.split( restconfInstance ) );
+        omitFirstAndLastEmptyString( pathArgs );
         if( pathArgs.isEmpty() ) {
             return null;
         }
@@ -149,7 +149,7 @@ public class ControllerContext implements SchemaContextListener {
         InstanceIdentifierBuilder builder = InstanceIdentifier.builder();
         Module latestModule = this.getLatestModule( globalSchema, startModule );
         InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments( builder, pathArgs,
-                                                           latestModule, null, toMountPointIdentifier );
+                latestModule, null, toMountPointIdentifier );
 
         if( iiWithSchemaNode == null ) {
             throw new RestconfDocumentedException(
@@ -159,7 +159,7 @@ public class ControllerContext implements SchemaContextListener {
         return iiWithSchemaNode;
     }
 
-    private List<String> omitFirstAndLastEmptyString( final List<String> list ) {
+    private static List<String> omitFirstAndLastEmptyString( final List<String> list ) {
         if( list.isEmpty() ) {
             return list;
         }
@@ -187,7 +187,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Predicate<Module> filter = new Predicate<Module>() {
             @Override
-            public boolean apply( Module m ) {
+            public boolean apply( final Module m ) {
                 return Objects.equal( m.getName(), moduleName );
             }
         };
@@ -232,14 +232,14 @@ public class ControllerContext implements SchemaContextListener {
 
         final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
         Set<Module> moduleSchemas = mountPointSchema == null ? null :
-                                                mountPointSchema.findModuleByNamespace( namespace );
+            mountPointSchema.findModuleByNamespace( namespace );
         return moduleSchemas == null ? null : this.filterLatestModule( moduleSchemas );
     }
 
     public Module findModuleByNameAndRevision( final QName module ) {
         this.checkPreconditions();
         Preconditions.checkArgument( module != null && module.getLocalName() != null &&
-                                     module.getRevision() != null );
+                module.getRevision() != null );
 
         return globalSchema.findModuleByName( module.getLocalName(), module.getRevision() );
     }
@@ -247,17 +247,17 @@ public class ControllerContext implements SchemaContextListener {
     public Module findModuleByNameAndRevision( final MountInstance mountPoint, final QName module ) {
         this.checkPreconditions();
         Preconditions.checkArgument( module != null && module.getLocalName() != null &&
-                                     module.getRevision() != null && mountPoint != null );
+                module.getRevision() != null && mountPoint != null );
 
         SchemaContext schemaContext = mountPoint.getSchemaContext();
         return schemaContext == null ? null :
-                       schemaContext.findModuleByName( module.getLocalName(), module.getRevision() );
+            schemaContext.findModuleByName( module.getLocalName(), module.getRevision() );
     }
 
     public DataNodeContainer getDataNodeContainerFor( final InstanceIdentifier path ) {
         this.checkPreconditions();
 
-        final List<PathArgument> elements = path.getPath();
+        final Iterable<PathArgument> elements = path.getPathArguments();
         PathArgument head = elements.iterator().next();
         final QName startQName = head.getNodeType();
         final Module initialModule = globalSchema.findModuleByNamespaceAndRevision(
@@ -278,7 +278,7 @@ public class ControllerContext implements SchemaContextListener {
     public String toFullRestconfIdentifier( final InstanceIdentifier path ) {
         this.checkPreconditions();
 
-        final List<PathArgument> elements = path.getPath();
+        final Iterable<PathArgument> elements = path.getPathArguments();
         final StringBuilder builder = new StringBuilder();
         PathArgument head = elements.iterator().next();
         final QName startQName = head.getNodeType();
@@ -354,7 +354,7 @@ public class ControllerContext implements SchemaContextListener {
         String module = this.uriToModuleName.get( qname.getNamespace() );
         if( module == null ) {
             final Module moduleSchema = globalSchema.findModuleByNamespaceAndRevision(
-                                                       qname.getNamespace(), qname.getRevision() );
+                    qname.getNamespace(), qname.getRevision() );
             if( moduleSchema == null ) {
                 return null;
             }
@@ -378,7 +378,7 @@ public class ControllerContext implements SchemaContextListener {
         SchemaContext schemaContext = mountPoint.getSchemaContext();
 
         final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision(
-                                                       qname.getNamespace(), qname.getRevision() );
+                qname.getNamespace(), qname.getRevision() );
         if( moduleSchema == null ) {
             return null;
         }
@@ -406,7 +406,7 @@ public class ControllerContext implements SchemaContextListener {
             @Override
             public boolean apply(final GroupingDefinition g) {
                 return Objects.equal(g.getQName().getLocalName(),
-                                     Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE);
+                        Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE);
             }
         };
 
@@ -416,12 +416,12 @@ public class ControllerContext implements SchemaContextListener {
 
         List<DataSchemaNode> instanceDataChildrenByName =
                 this.findInstanceDataChildrenByName(restconfGrouping,
-                                                    Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE);
+                        Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE);
         return Iterables.getFirst(instanceDataChildrenByName, null);
     }
 
-    public DataSchemaNode getRestconfModuleRestConfSchemaNode( Module inRestconfModule,
-                                                               String schemaNodeName ) {
+    public DataSchemaNode getRestconfModuleRestConfSchemaNode( final Module inRestconfModule,
+            final String schemaNodeName ) {
         Module restconfModule = inRestconfModule;
         if( restconfModule == null ) {
             restconfModule = getRestconfModule();
@@ -437,7 +437,7 @@ public class ControllerContext implements SchemaContextListener {
             @Override
             public boolean apply(final GroupingDefinition g) {
                 return Objects.equal(g.getQName().getLocalName(),
-                                     Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE);
+                        Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE);
             }
         };
 
@@ -447,49 +447,49 @@ public class ControllerContext implements SchemaContextListener {
 
         List<DataSchemaNode> instanceDataChildrenByName =
                 this.findInstanceDataChildrenByName(restconfGrouping,
-                                                            Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE);
+                        Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE);
         final DataSchemaNode restconfContainer = Iterables.getFirst(instanceDataChildrenByName, null);
 
         if (Objects.equal(schemaNodeName, Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                    Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                   Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                   Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             final DataSchemaNode modules = Iterables.getFirst(instances, null);
             instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules),
-                                                               Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
+                    Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                         Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                         Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
             final DataSchemaNode modules = Iterables.getFirst(instances, null);
             instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules),
-                                                                 Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
+                    Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                   Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
 
@@ -545,7 +545,7 @@ public class ControllerContext implements SchemaContextListener {
 
     private String toUriString( final Object object ) throws UnsupportedEncodingException {
         return object == null ? "" :
-                       URLEncoder.encode( object.toString(), ControllerContext.URI_ENCODING_CHAR_SET );
+            URLEncoder.encode( object.toString(), ControllerContext.URI_ENCODING_CHAR_SET );
     }
 
     private InstanceIdWithSchemaNode collectPathArguments( final InstanceIdentifierBuilder builder,
@@ -559,17 +559,17 @@ public class ControllerContext implements SchemaContextListener {
 
         if( strings.isEmpty() ) {
             return new InstanceIdWithSchemaNode( builder.toInstance(),
-                                                 ((DataSchemaNode) parentNode), mountPoint );
+                    ((DataSchemaNode) parentNode), mountPoint );
         }
 
         String head = strings.iterator().next();
-        final String nodeName = this.toNodeName( head );
+        final String nodeName = toNodeName( head );
         final String moduleName = ControllerContext.toModuleName( head );
 
         DataSchemaNode targetNode = null;
         if( !Strings.isNullOrEmpty( moduleName ) ) {
             if( Objects.equal( moduleName, ControllerContext.MOUNT_MODULE ) &&
-                Objects.equal( nodeName, ControllerContext.MOUNT_NODE ) ) {
+                    Objects.equal( nodeName, ControllerContext.MOUNT_NODE ) ) {
                 if( mountPoint != null ) {
                     throw new RestconfDocumentedException(
                             "Restconf supports just one mount point in URI.",
@@ -587,7 +587,7 @@ public class ControllerContext implements SchemaContextListener {
                 if( mount == null ) {
                     LOG.debug( "Instance identifier to missing mount point: {}", partialPath );
                     throw new RestconfDocumentedException(
-                         "Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT );
+                            "Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT );
                 }
 
                 final SchemaContext mountPointSchema = mount.getSchemaContext();
@@ -610,12 +610,12 @@ public class ControllerContext implements SchemaContextListener {
                 final String moduleNameBehindMountPoint = toModuleName(  strings.get( 1 ) );
                 if( moduleNameBehindMountPoint == null ) {
                     throw new RestconfDocumentedException(
-                        "First node after mount point in URI has to be in format \"moduleName:nodeName\"",
-                        ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                            "First node after mount point in URI has to be in format \"moduleName:nodeName\"",
+                            ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
                 }
 
                 final Module moduleBehindMountPoint = this.getLatestModule( mountPointSchema,
-                                                                            moduleNameBehindMountPoint );
+                        moduleNameBehindMountPoint );
                 if( moduleBehindMountPoint == null ) {
                     throw new RestconfDocumentedException(
                             "\"" +moduleName + "\" module does not exist in mount point.",
@@ -624,7 +624,7 @@ public class ControllerContext implements SchemaContextListener {
 
                 List<String> subList = strings.subList( 1, strings.size() );
                 return this.collectPathArguments( InstanceIdentifier.builder(), subList, moduleBehindMountPoint,
-                                                  mount, returnJustMountPoint );
+                        mount, returnJustMountPoint );
             }
 
             Module module = null;
@@ -639,7 +639,7 @@ public class ControllerContext implements SchemaContextListener {
             else {
                 SchemaContext schemaContext = mountPoint.getSchemaContext();
                 module = schemaContext == null ? null :
-                                          this.getLatestModule( schemaContext, moduleName );
+                    this.getLatestModule( schemaContext, moduleName );
                 if( module == null ) {
                     throw new RestconfDocumentedException(
                             "\"" + moduleName + "\" module does not exist in mount point.",
@@ -648,23 +648,23 @@ public class ControllerContext implements SchemaContextListener {
             }
 
             targetNode = this.findInstanceDataChildByNameAndNamespace(
-                                          parentNode, nodeName, module.getNamespace() );;
+                    parentNode, nodeName, module.getNamespace() );
             if( targetNode == null ) {
                 throw new RestconfDocumentedException(
                         "URI has bad format. Possible reasons:\n" +
-                        " 1. \"" + head + "\" was not found in parent data node.\n" +
-                        " 2. \"" + head + "\" is behind mount point. Then it should be in format \"/" +
-                        MOUNT + "/" + head + "\".", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                                " 1. \"" + head + "\" was not found in parent data node.\n" +
+                                " 2. \"" + head + "\" is behind mount point. Then it should be in format \"/" +
+                                MOUNT + "/" + head + "\".", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
             }
         } else {
             final List<DataSchemaNode> potentialSchemaNodes =
-                                          this.findInstanceDataChildrenByName( parentNode, nodeName );
+                    this.findInstanceDataChildrenByName( parentNode, nodeName );
             if( potentialSchemaNodes.size() > 1 ) {
                 final StringBuilder strBuilder = new StringBuilder();
                 for( final DataSchemaNode potentialNodeSchema : potentialSchemaNodes ) {
                     strBuilder.append( "   " )
-                              .append( potentialNodeSchema.getQName().getNamespace() )
-                              .append( "\n" );
+                    .append( potentialNodeSchema.getQName().getNamespace() )
+                    .append( "\n" );
                 }
 
                 throw new RestconfDocumentedException(
@@ -696,8 +696,8 @@ public class ControllerContext implements SchemaContextListener {
             final int keysSize = listNode.getKeyDefinition().size();
             if( (strings.size() - consumed) < keysSize ) {
                 throw new RestconfDocumentedException(
-                        "Missing key for list \"" + listNode.getQName().getLocalName() + "\".",
-                        ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                        "Missing key value for list element '" + listNode.getQName().getLocalName() + "' in the URI.",
+                        ErrorType.PROTOCOL, ErrorTag.DATA_MISSING );
             }
 
             final List<String> uriKeyValues = strings.subList( consumed, consumed + keysSize );
@@ -714,7 +714,7 @@ public class ControllerContext implements SchemaContextListener {
                     }
 
                     this.addKeyValue( keyValues, listNode.getDataChildByName( key ),
-                                      uriKeyValue, mountPoint );
+                            uriKeyValue, mountPoint );
                     i++;
                 }
             }
@@ -729,7 +729,7 @@ public class ControllerContext implements SchemaContextListener {
         if( (targetNode instanceof DataNodeContainer) ) {
             final List<String> remaining = strings.subList( consumed, strings.size() );
             return this.collectPathArguments( builder, remaining,
-                              ((DataNodeContainer) targetNode), mountPoint, returnJustMountPoint );
+                    ((DataNodeContainer) targetNode), mountPoint, returnJustMountPoint );
         }
 
         return new InstanceIdWithSchemaNode( builder.toInstance(), targetNode, mountPoint );
@@ -743,7 +743,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
             @Override
-            public boolean apply( DataSchemaNode node ) {
+            public boolean apply( final DataSchemaNode node ) {
                 return Objects.equal( node.getQName().getNamespace(), namespace );
             }
         };
@@ -753,7 +753,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     public List<DataSchemaNode> findInstanceDataChildrenByName( final DataNodeContainer container,
-                                                                final String name ) {
+            final String name ) {
         Preconditions.<DataNodeContainer> checkNotNull( container );
         Preconditions.<String> checkNotNull( name );
 
@@ -769,7 +769,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
             @Override
-            public boolean apply( DataSchemaNode node ) {
+            public boolean apply( final DataSchemaNode node ) {
                 return Objects.equal( node.getQName().getLocalName(), name );
             }
         };
@@ -785,7 +785,7 @@ public class ControllerContext implements SchemaContextListener {
         }
 
         Iterable<ChoiceNode> choiceNodes = Iterables.<ChoiceNode> filter( container.getChildNodes(),
-                                                                          ChoiceNode.class );
+                ChoiceNode.class );
 
         final Function<ChoiceNode, Set<ChoiceCaseNode>> choiceFunction =
                 new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
@@ -796,7 +796,7 @@ public class ControllerContext implements SchemaContextListener {
         };
 
         Iterable<Set<ChoiceCaseNode>> map = Iterables.<ChoiceNode, Set<ChoiceCaseNode>> transform(
-                                                                           choiceNodes, choiceFunction );
+                choiceNodes, choiceFunction );
 
         final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat( map );
         for( final ChoiceCaseNode caze : allCases ) {
@@ -806,11 +806,12 @@ public class ControllerContext implements SchemaContextListener {
 
     public boolean isInstantiatedDataSchema( final DataSchemaNode node ) {
         return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode ||
-               node instanceof ContainerSchemaNode || node instanceof ListSchemaNode;
+                node instanceof ContainerSchemaNode || node instanceof ListSchemaNode ||
+                node instanceof AnyXmlSchemaNode;
     }
 
     private void addKeyValue( final HashMap<QName, Object> map, final DataSchemaNode node,
-                              final String uriValue, final MountInstance mountPoint ) {
+            final String uriValue, final MountInstance mountPoint ) {
         Preconditions.<String> checkNotNull( uriValue );
         Preconditions.checkArgument( (node instanceof LeafSchemaNode) );
 
@@ -830,8 +831,8 @@ public class ControllerContext implements SchemaContextListener {
 
         if( decoded == null ) {
             throw new RestconfDocumentedException(
-                            uriValue + " from URI can't be resolved. " + additionalInfo,
-                            ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                    uriValue + " from URI can't be resolved. " + additionalInfo,
+                    ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
         }
 
         map.put( node.getQName(), decoded );
@@ -839,20 +840,20 @@ public class ControllerContext implements SchemaContextListener {
 
     private static String toModuleName( final String str ) {
         Preconditions.<String> checkNotNull( str );
-        if( str.contains( ":" ) ) {
-            final String[] args = str.split( ":" );
-            if( args.length == 2 ) {
-                return args[0];
+        if( str.indexOf( ':' ) != -1 ) {
+            final Iterable<String> args = COLON_SPLITTER.split( str );
+            if( Iterables.size( args ) == 2 ) {
+                return args.iterator().next();
             }
         }
         return null;
     }
 
-    private String toNodeName( final String str ) {
-        if( str.contains( ":" ) ) {
-            final String[] args = str.split( ":" );
-            if( args.length == 2 ) {
-                return args[1];
+    private static String toNodeName( final String str ) {
+        if( str.indexOf( ':' ) != -1 ) {
+            final Iterable<String> args = COLON_SPLITTER.split( str );
+            if( Iterables.size( args ) == 2 ) {
+                return Iterables.get( args, 1 );
             }
         }
         return str;
@@ -860,7 +861,7 @@ public class ControllerContext implements SchemaContextListener {
 
     private QName toQName( final String name ) {
         final String module = toModuleName( name );
-        final String node = this.toNodeName( name );
+        final String node = toNodeName( name );
         Set<Module> modules = globalSchema.getModules();
 
         final Comparator<Module> comparator = new Comparator<Module>() {
@@ -888,8 +889,8 @@ public class ControllerContext implements SchemaContextListener {
         };
 
         Optional<QName> namespace = FluentIterable.from( sorted )
-                                                  .transform( transform )
-                                                  .firstMatch( findFirst );
+                .transform( transform )
+                .firstMatch( findFirst );
         return namespace.isPresent() ? QName.create( namespace.get(), node ) : null;
     }
 
@@ -916,7 +917,7 @@ public class ControllerContext implements SchemaContextListener {
         }
     }
 
-    public List<String> urlPathArgsDecode( final List<String> strings ) {
+    public static List<String> urlPathArgsDecode( final Iterable<String> strings ) {
         try {
             List<String> decodedPathArgs = new ArrayList<String>();
             for( final String pathArg : strings ) {
@@ -948,7 +949,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private CharSequence convertToRestconfIdentifier( final PathArgument argument,
-                                                      final DataNodeContainer node ) {
+            final DataNodeContainer node ) {
         if( argument instanceof NodeIdentifier && node instanceof ContainerSchemaNode ) {
             return convertToRestconfIdentifier( (NodeIdentifier) argument, (ContainerSchemaNode) node );
         }
@@ -957,7 +958,7 @@ public class ControllerContext implements SchemaContextListener {
         }
         else if( argument != null && node != null ) {
             throw new IllegalArgumentException(
-                                     "Conversion of generic path argument is not supported" );
+                    "Conversion of generic path argument is not supported" );
         }
         else {
             throw new IllegalArgumentException( "Unhandled parameter types: "
@@ -966,7 +967,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private CharSequence convertToRestconfIdentifier( final NodeIdentifier argument,
-                                                      final ContainerSchemaNode node ) {
+            final ContainerSchemaNode node ) {
         StringBuilder builder = new StringBuilder();
         builder.append( "/" );
         QName nodeType = argument.getNodeType();
@@ -975,7 +976,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private CharSequence convertToRestconfIdentifier( final NodeIdentifierWithPredicates argument,
-                                                      final ListSchemaNode node ) {
+            final ListSchemaNode node ) {
         QName nodeType = argument.getNodeType();
         final CharSequence nodeIdentifier = this.toRestconfIdentifier( nodeType );
         final Map<QName, Object> keyValues = argument.getKeyValues();
@@ -998,7 +999,7 @@ public class ControllerContext implements SchemaContextListener {
             try {
                 builder.append( this.toUriString( keyValues.get( key ) ) );
             } catch( UnsupportedEncodingException e ) {
-                LOG.error( "Error parsing URI: " + keyValues.get( key ), e );
+                LOG.error( "Error parsing URI: {}", keyValues.get( key ), e );
                 return null;
             }
         }