FELIX-2868 Fix the resolution of the icon path according to the specification:
  - use the metatype XML file's URL as the base URL
  - have the URL constructor resolve the icon Path against that URL
  - increase o.a.f.metatype export version to 1.2 due to extended API

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1187688 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/pom.xml b/metatype/pom.xml
index 495bef2..1210b47 100644
--- a/metatype/pom.xml
+++ b/metatype/pom.xml
@@ -69,7 +69,7 @@
                             http://felix.apache.org/site/apache-felix-metatype-service.html
                         </Bundle-DocURL>
                         <Export-Package>
-                            org.apache.felix.metatype; version=${pom.version},
+                            org.apache.felix.metatype; version=1.2,
                             org.osgi.service.metatype; version=1.1
                         </Export-Package>
                         <Private-Package>
diff --git a/metatype/src/main/java/org/apache/felix/metatype/MetaData.java b/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
index befa4ea..33c9087 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -19,6 +19,7 @@
 package org.apache.felix.metatype;
 
 
+import java.net.URL;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -27,7 +28,7 @@
 /**
  * The <code>MetaData</code> class represents the <code>MetaData</code>
  * element of the meta type descriptor.
- * 
+ *
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class MetaData
@@ -36,7 +37,7 @@
     private String localePrefix;
     private Map objectClassDefinitions;
     private Map designates;
-
+    private URL source;
 
     public String getLocalePrefix()
     {
@@ -66,6 +67,7 @@
             }
 
             objectClassDefinitions.put( objectClassDefinition.getID(), objectClassDefinition );
+            objectClassDefinition.setMetadata( this );
         }
     }
 
@@ -88,4 +90,16 @@
             designates.put( designate.getPid(), designate );
         }
     }
+
+
+    public URL getSource()
+    {
+        return source;
+    }
+
+
+    public void setSource( URL source )
+    {
+        this.source = source;
+    }
 }
diff --git a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
index db0dc8e..a7da322 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
@@ -83,7 +83,12 @@
             this.parser.setProperty( "http://xmlpull.org/v1/doc/properties.html#location", url.toString() );
             this.parser.setFeature(KXmlParser.FEATURE_PROCESS_NAMESPACES, true);
             this.parser.setFeature(KXmlParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES, false);
-            return this.parse( ins );
+            MetaData md = this.parse( ins );
+            if ( md != null )
+            {
+                md.setSource( url );
+            }
+            return md;
         }
         finally
         {
diff --git a/metatype/src/main/java/org/apache/felix/metatype/OCD.java b/metatype/src/main/java/org/apache/felix/metatype/OCD.java
index 993a9e6..b9b21ca 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/OCD.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/OCD.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -38,6 +38,7 @@
     private String description;
     private Map attributes;
     private Map icons;
+    private MetaData metadata;
 
 
     public String getID()
@@ -83,7 +84,7 @@
 
 
     /**
-     * 
+     *
      * @param size
      * @param icon The icon, either an URL or a string designating a resource
      *      which may be a localized string
@@ -120,4 +121,16 @@
             attributes.put( attribute.getID(), attribute );
         }
     }
+
+
+    public MetaData getMetadata()
+    {
+        return metadata;
+    }
+
+
+    public void setMetadata( MetaData metadata )
+    {
+        this.metadata = metadata;
+    }
 }
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/LocalizedObjectClassDefinition.java b/metatype/src/main/java/org/apache/felix/metatype/internal/LocalizedObjectClassDefinition.java
index 6baafae..e511dda 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/LocalizedObjectClassDefinition.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/LocalizedObjectClassDefinition.java
@@ -145,23 +145,18 @@
             iconPath = ( String ) icons.get( selectedSize );
         }
 
-        // fail if no icon could be found
+        // localize the path
+        iconPath = localize( iconPath );
+
+        // fail if no icon could be found (or localization returned null)
         if ( iconPath == null )
         {
             return null;
         }
 
-        // localize the path
-        iconPath = localize( iconPath );
-
-        // try to resolve the path in the bundle
-        URL url = bundle.getEntry( iconPath );
-        if ( url == null )
-        {
-            return null;
-        }
-
-        // open the stream on the URL - this may throw an IOException
+        // just create an URL based on the source of the metadata
+        // see FELIX2868
+        URL url = new URL(this.ocd.getMetadata().getSource(), iconPath);
         return url.openStream();
     }