[Title] Added PluginUtil#loadClassAttribute
authorchanghyun1.lee <changhyun1.lee@samsung.com>
Tue, 11 Dec 2012 14:28:28 +0000 (23:28 +0900)
committerchanghyun1.lee <changhyun1.lee@samsung.com>
Tue, 11 Dec 2012 15:12:27 +0000 (00:12 +0900)
[Desc.]
[Issue] Redmine-7495

Change-Id: I5de65f47357f448856c219c05976893fc5fee2b7

org.tizen.common/src/org/tizen/common/util/PluginUtil.java
org.tizen.common/test/src/org/tizen/common/util/PluginUtilTest.java

index a451c48..b1bd640 100644 (file)
@@ -78,7 +78,7 @@ public class PluginUtil {
     }
     
     /**
-     * Return class of specific class id which extends specific extension point id.  
+     * Return class of specific class id which extends specific extension point id.
      * @param extPointId  - extension point id.
      * @param classId  - class id.
      * @return object class of specific class id which extends specific extension point id.
@@ -102,4 +102,30 @@ public class PluginUtil {
         }
         return null;
     }
+
+    /**
+     * Return object of specific attribute which extends specific extension point id.
+     * @param extPointId  - extension point id.
+     * @param attribute  - attribute.
+     * @return object of specific attribute which extends specific extension point id.
+     */
+    public static Object[] getExtensionAttribute(String extPointId, String attribute) throws CoreException {
+        IExtensionRegistry registry = platformSurrogate.getAdapter();
+        IExtensionPoint ep = registry.getExtensionPoint(extPointId );
+        IExtension[] exts = ep.getExtensions();
+        List<String> values = new ArrayList<String>();
+
+        for ( IExtension ext : exts ) {
+            IConfigurationElement[] configs = ext.getConfigurationElements();
+            for ( final IConfigurationElement config : configs ) {
+                String value = config.getAttribute(attribute);
+                if (value != null && !value.isEmpty()) {
+                    values.add(value);
+                }
+            }
+        }
+
+        return values.toArray();
+    }
+
 }
index 5fccdcf..7760c43 100644 (file)
@@ -121,4 +121,17 @@ public class PluginUtilTest {
         Mockito.verify(config).createExecutableExtension("class");
     }
 
+    /**
+     * Test {@link PluginUtil#getExtensionAttribute(String, String)}
+     * 
+     * @throws Exception in case of failure in test
+     * 
+     * @see PluginUtil#getExtensionAttribute(String, String)
+     */
+    @Test
+    public void testGetExtensionAttribute() throws Exception {
+        when(config.getAttribute("extension")).thenReturn("css");
+        PluginUtil.getExtensionAttribute(TEST_EXT_ID, "extension");
+        Mockito.verify(config).getAttribute("extension");
+    }
 }