/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.karaf.features.command;

import java.net.URI;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;

public class FeatureFinder implements ManagedService {
    Map<String, String> nameToArtifactMap = new HashMap<String, String>();
    public String[] getNames() {
        return nameToArtifactMap.keySet().toArray(new String[] {});
    }

    public URI getUriFor(String name, String version) {
        String coords = nameToArtifactMap.get(name);
        if (coords == null) {
            return null;
        }
        Artifact artifact = new Artifact(coords);
        return artifact.getPaxUrlForArtifact(version);
    }

    @SuppressWarnings("rawtypes")
    public void updated(Dictionary properties) throws ConfigurationException {
        nameToArtifactMap.clear();
        Enumeration keys = properties.keys();
        while (keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            if (!"felix.fileinstall.filename".equals(key) && !"service.pid".equals(key)) {
                nameToArtifactMap.put(key, (String)properties.get(key));
            }
        }
    }

}

@@ -1119,16 +1119,17 @@
 rvice %7B%0A
+%0A
     Map%3C
@@ -1191,24 +1191,25 @@
  String%3E();%0A
+%0A
     public S
@@ -1703,16 +1703,54 @@
 ption %7B%0A
+        if (properties != null) %7B%0A    
         
@@ -1784,16 +1784,20 @@
         
+    
 Enumerat
@@ -1834,16 +1834,20 @@
         
+    
 while (k
@@ -1879,24 +1879,28 @@
             
+  
+  
 String key =
@@ -1924,24 +1924,28 @@
 tElement();%0A
+    
             
@@ -2031,32 +2031,36 @@
                 
+   
+ 
 nameToArtifactMa
@@ -2100,16 +2100,34 @@
 (key));%0A
+                %7D%0A
         

Fix NPE on the FeatureFinder when Properties are not yet there