--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2016 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * THTH ry - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.debug.browser.content;\r
+\r
+import java.util.Arrays;\r
+import java.util.Comparator;\r
+\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.util.tracker.ServiceTracker;\r
+import org.simantics.debug.browser.internal.Activator;\r
+\r
+public class ResourceBrowserRewriterRepository {\r
+ private static ServiceTracker<ResourceBrowserRewriter, ResourceBrowserRewriter> TRACKER;\r
+\r
+ private static final Comparator<ResourceBrowserRewriter> REWRITER_COMPARATOR =\r
+ new Comparator<ResourceBrowserRewriter>() {\r
+ @Override\r
+ public int compare(ResourceBrowserRewriter o1,\r
+ ResourceBrowserRewriter o2) {\r
+ return Double.compare(o1.getPriority(), o2.getPriority());\r
+ }\r
+ };\r
+\r
+ public static ResourceBrowserRewriter[] getRewriters() {\r
+ if(TRACKER == null) {\r
+ BundleContext context = Activator.getContext();\r
+ TRACKER = new ServiceTracker<ResourceBrowserRewriter, ResourceBrowserRewriter>(\r
+ context, ResourceBrowserRewriter.class, null);\r
+ TRACKER.open();\r
+ }\r
+ ResourceBrowserRewriter[] rewriters =\r
+ TRACKER.getServices(new ResourceBrowserRewriter[TRACKER.getTrackingCount()]);\r
+ Arrays.sort(rewriters, REWRITER_COMPARATOR);\r
+ return rewriters;\r
+ }\r
+}\r