]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/internal/ProjectFeatureRegistry.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / internal / ProjectFeatureRegistry.java
index ea126d9d31ec4715b721b3d54d328dc954f0b9b1..e861bc09dc47e81f3b1857889c835db091837048 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 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
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.project.internal;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.runtime.IConfigurationElement;\r
-import org.eclipse.core.runtime.IExtension;\r
-import org.eclipse.core.runtime.IExtensionPoint;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;\r
-import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;\r
-import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;\r
-import org.eclipse.core.runtime.dynamichelpers.IFilter;\r
-import org.simantics.project.features.registry.GroupReference;\r
-import org.simantics.project.features.registry.IProjectFeatureExtension;\r
-import org.simantics.project.features.registry.IProjectFeatureRegistry;\r
-import org.simantics.project.features.registry.InjectedDependency;\r
-import org.simantics.project.features.registry.ProjectFeatureReference;\r
-import org.simantics.utils.strings.StringUtils;\r
-\r
-/**\r
- * This registry implementation is not properly dynamic-enabled.\r
- * injectDependency is not handled well enough to work dynamically.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class ProjectFeatureRegistry implements IProjectFeatureRegistry, IExtensionChangeHandler {\r
-\r
-    private final static String        NAMESPACE         = "org.simantics.project";\r
-\r
-    private final static String        EP_NAME           = "feature";\r
-\r
-    private final static String        FEATURE           = "feature";\r
-\r
-    private final static String        INJECT_DEPENDENCY = "injectDependency";\r
-\r
-    private final ExtensionTracker     tracker;\r
-\r
-    private IProjectFeatureExtension[] extensions        = new IProjectFeatureExtension[0];\r
-\r
-    public ProjectFeatureRegistry() {\r
-        tracker = new ExtensionTracker();\r
-\r
-        // Cache defined actions\r
-        IExtensionPoint expt = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACE, EP_NAME);\r
-        loadExtensions(expt.getConfigurationElements());\r
-\r
-        // Start tracking for new and removed extensions\r
-        IFilter filter = ExtensionTracker.createExtensionPointFilter(expt);\r
-        tracker.registerHandler(this, filter);\r
-    }\r
-\r
-    private void loadExtensions(IConfigurationElement[] configurationElements) {\r
-        Set<IProjectFeatureExtension> newExtensions = new HashSet<IProjectFeatureExtension>(Arrays.asList(extensions));\r
-\r
-        // These are all "feature" elements with required attributes\r
-        //  - id\r
-        //  - feature\r
-        for (IConfigurationElement el : configurationElements) {\r
-            if (FEATURE.equals(el.getName())) {\r
-                String id = StringUtils.safeString(el.getAttribute("id"));\r
-                if (ProjectPolicy.TRACE_PROJECT_FEATURE_LOAD)\r
-                    System.out.println(this + " Trying to load project feature extension id '" + id + "' contributed by " + el.getContributor().getName());\r
-                if (id.isEmpty()) {\r
-                    // Ignore extension without an ID\r
-                    // TODO: log warning\r
-                    if (ProjectPolicy.TRACE_PROJECT_FEATURE_LOAD)\r
-                        System.out.println(this + " skipping feature with empty ID contributed by " + el.getContributor().getName());\r
-                    continue;\r
-                }\r
-                if (StringUtils.safeString(el.getAttribute("class")).isEmpty()) {\r
-                    // Ignore extension without a feature class\r
-                    // TODO: log warning\r
-                    if (ProjectPolicy.TRACE_PROJECT_FEATURE_LOAD)\r
-                        System.out.println(this + " skipping feature missing 'class' attribute contributed by " + el.getContributor().getName());\r
-                    continue;\r
-                }\r
-                // Load optional attributes\r
-                String label = StringUtils.safeString(el.getAttribute("label"));\r
-                String description = StringUtils.safeString(el.getAttribute("description"));\r
-                boolean published = "true".equalsIgnoreCase(el.getAttribute("published"));\r
-                Collection<ProjectFeatureReference> requires = readProjectFeatureReferenceCollection(el, "requires");\r
-                Collection<InjectedDependency> injections = readInjectedDependencies(el);\r
-                Collection<GroupReference> installGroups = readGroupReferenceCollection(el, "installGroup");\r
-\r
-                ProjectFeatureExtension ext = new ProjectFeatureExtension(el, id, label, description, published, requires, injections, installGroups);\r
-\r
-                // Start tracking the new extension object, its removal will be notified of\r
-                // with removeExtension(extension, Object[]).\r
-                tracker.registerObject(el.getDeclaringExtension(), ext, IExtensionTracker.REF_STRONG);\r
-\r
-                newExtensions.add(ext);\r
-            }\r
-        }\r
-\r
-        // Atomic assignment\r
-        this.extensions = newExtensions.toArray(new IProjectFeatureExtension[newExtensions.size()]);\r
-    }\r
-\r
-    private Collection<InjectedDependency> readInjectedDependencies(IConfigurationElement element) {\r
-        Collection<InjectedDependency> result = new ArrayList<InjectedDependency>();\r
-\r
-        for (IConfigurationElement child : element.getChildren(INJECT_DEPENDENCY)) {\r
-            String id = StringUtils.safeString(child.getAttribute("id"));\r
-            if (id.isEmpty())\r
-                // Invalid extension\r
-                return null;\r
-\r
-            String targetId = StringUtils.safeString(child.getAttribute("targetId"));\r
-            if (targetId.isEmpty())\r
-                // Invalid extension\r
-                return null;\r
-        }\r
-\r
-        return result;\r
-    }\r
-\r
-    private Collection<ProjectFeatureReference> readProjectFeatureReferenceCollection(IConfigurationElement element, String childName) {\r
-        Collection<ProjectFeatureReference> result = new ArrayList<ProjectFeatureReference>();\r
-\r
-        for (IConfigurationElement child : element.getChildren(childName)) {\r
-            String id = StringUtils.safeString(child.getAttribute("id"));\r
-            if (id.isEmpty()) {\r
-                // Invalid extension\r
-                continue;\r
-            }\r
-            boolean optional = "true".equalsIgnoreCase( child.getAttribute("optional") );\r
-            result.add(new ProjectFeatureReference(id, optional));\r
-        }\r
-\r
-        return result;\r
-    }\r
-\r
-    private Collection<GroupReference> readGroupReferenceCollection(IConfigurationElement element, String childName) {\r
-        Collection<GroupReference> result = new ArrayList<GroupReference>();\r
-\r
-        for (IConfigurationElement child : element.getChildren(childName)) {\r
-            String id = StringUtils.safeString(child.getAttribute("id"));\r
-            if (id.isEmpty()) {\r
-                // Invalid extension\r
-                // TODO: log warning\r
-                continue;\r
-            }\r
-            String version = StringUtils.safeString(child.getAttribute("version"));\r
-            if (version.isEmpty())\r
-                // Empty version implies no version, mark that with null.\r
-                version = null;\r
-            result.add(new GroupReference(id, version));\r
-        }\r
-\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public void addExtension(IExtensionTracker tracker, IExtension extension) {\r
-        loadExtensions(extension.getConfigurationElements());\r
-    }\r
-\r
-    @Override\r
-    public void removeExtension(IExtension extension, Object[] objects) {\r
-        Set<IProjectFeatureExtension> newExtensions = new HashSet<IProjectFeatureExtension>(Arrays.asList(extensions));\r
-\r
-        for (Object o : objects) {\r
-            tracker.unregisterObject(extension, o);\r
-            newExtensions.remove(o);\r
-        }\r
-\r
-        // Atomic assignment\r
-        this.extensions = newExtensions.toArray(new IProjectFeatureExtension[newExtensions.size()]);\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * @see org.simantics.project.IProjectFeatureRegistry#getExtensions()\r
-     */\r
-    @Override\r
-    public IProjectFeatureExtension[] getExtensions() {\r
-        return extensions;\r
-    }\r
-\r
-    @Override\r
-    public IProjectFeatureExtension getExtensionById(String id) {\r
-        if (id == null)\r
-            throw new IllegalArgumentException("null id");\r
-\r
-        for (IProjectFeatureExtension ext : extensions) {\r
-            if (id.equals(ext.getId()))\r
-                return ext;\r
-        }\r
-        return null;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.project.internal;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
+import org.eclipse.core.runtime.dynamichelpers.IFilter;
+import org.simantics.project.features.registry.GroupReference;
+import org.simantics.project.features.registry.IProjectFeatureExtension;
+import org.simantics.project.features.registry.IProjectFeatureRegistry;
+import org.simantics.project.features.registry.InjectedDependency;
+import org.simantics.project.features.registry.ProjectFeatureReference;
+import org.simantics.utils.strings.StringUtils;
+
+/**
+ * This registry implementation is not properly dynamic-enabled.
+ * injectDependency is not handled well enough to work dynamically.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class ProjectFeatureRegistry implements IProjectFeatureRegistry, IExtensionChangeHandler {
+
+    private final static String        NAMESPACE         = "org.simantics.project";
+
+    private final static String        EP_NAME           = "feature";
+
+    private final static String        FEATURE           = "feature";
+
+    private final static String        INJECT_DEPENDENCY = "injectDependency";
+
+    private final ExtensionTracker     tracker;
+
+    private IProjectFeatureExtension[] extensions        = new IProjectFeatureExtension[0];
+
+    public ProjectFeatureRegistry() {
+        tracker = new ExtensionTracker();
+
+        // Cache defined actions
+        IExtensionPoint expt = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACE, EP_NAME);
+        loadExtensions(expt.getConfigurationElements());
+
+        // Start tracking for new and removed extensions
+        IFilter filter = ExtensionTracker.createExtensionPointFilter(expt);
+        tracker.registerHandler(this, filter);
+    }
+
+    private void loadExtensions(IConfigurationElement[] configurationElements) {
+        Set<IProjectFeatureExtension> newExtensions = new HashSet<IProjectFeatureExtension>(Arrays.asList(extensions));
+
+        // These are all "feature" elements with required attributes
+        //  - id
+        //  - feature
+        for (IConfigurationElement el : configurationElements) {
+            if (FEATURE.equals(el.getName())) {
+                String id = StringUtils.safeString(el.getAttribute("id"));
+                if (ProjectPolicy.TRACE_PROJECT_FEATURE_LOAD)
+                    System.out.println(this + " Trying to load project feature extension id '" + id + "' contributed by " + el.getContributor().getName());
+                if (id.isEmpty()) {
+                    // Ignore extension without an ID
+                    // TODO: log warning
+                    if (ProjectPolicy.TRACE_PROJECT_FEATURE_LOAD)
+                        System.out.println(this + " skipping feature with empty ID contributed by " + el.getContributor().getName());
+                    continue;
+                }
+                if (StringUtils.safeString(el.getAttribute("class")).isEmpty()) {
+                    // Ignore extension without a feature class
+                    // TODO: log warning
+                    if (ProjectPolicy.TRACE_PROJECT_FEATURE_LOAD)
+                        System.out.println(this + " skipping feature missing 'class' attribute contributed by " + el.getContributor().getName());
+                    continue;
+                }
+                // Load optional attributes
+                String label = StringUtils.safeString(el.getAttribute("label"));
+                String description = StringUtils.safeString(el.getAttribute("description"));
+                boolean published = "true".equalsIgnoreCase(el.getAttribute("published"));
+                Collection<ProjectFeatureReference> requires = readProjectFeatureReferenceCollection(el, "requires");
+                Collection<InjectedDependency> injections = readInjectedDependencies(el);
+                Collection<GroupReference> installGroups = readGroupReferenceCollection(el, "installGroup");
+
+                ProjectFeatureExtension ext = new ProjectFeatureExtension(el, id, label, description, published, requires, injections, installGroups);
+
+                // Start tracking the new extension object, its removal will be notified of
+                // with removeExtension(extension, Object[]).
+                tracker.registerObject(el.getDeclaringExtension(), ext, IExtensionTracker.REF_STRONG);
+
+                newExtensions.add(ext);
+            }
+        }
+
+        // Atomic assignment
+        this.extensions = newExtensions.toArray(new IProjectFeatureExtension[newExtensions.size()]);
+    }
+
+    private Collection<InjectedDependency> readInjectedDependencies(IConfigurationElement element) {
+        Collection<InjectedDependency> result = new ArrayList<InjectedDependency>();
+
+        for (IConfigurationElement child : element.getChildren(INJECT_DEPENDENCY)) {
+            String id = StringUtils.safeString(child.getAttribute("id"));
+            if (id.isEmpty())
+                // Invalid extension
+                return null;
+
+            String targetId = StringUtils.safeString(child.getAttribute("targetId"));
+            if (targetId.isEmpty())
+                // Invalid extension
+                return null;
+        }
+
+        return result;
+    }
+
+    private Collection<ProjectFeatureReference> readProjectFeatureReferenceCollection(IConfigurationElement element, String childName) {
+        Collection<ProjectFeatureReference> result = new ArrayList<ProjectFeatureReference>();
+
+        for (IConfigurationElement child : element.getChildren(childName)) {
+            String id = StringUtils.safeString(child.getAttribute("id"));
+            if (id.isEmpty()) {
+                // Invalid extension
+                continue;
+            }
+            boolean optional = "true".equalsIgnoreCase( child.getAttribute("optional") );
+            result.add(new ProjectFeatureReference(id, optional));
+        }
+
+        return result;
+    }
+
+    private Collection<GroupReference> readGroupReferenceCollection(IConfigurationElement element, String childName) {
+        Collection<GroupReference> result = new ArrayList<GroupReference>();
+
+        for (IConfigurationElement child : element.getChildren(childName)) {
+            String id = StringUtils.safeString(child.getAttribute("id"));
+            if (id.isEmpty()) {
+                // Invalid extension
+                // TODO: log warning
+                continue;
+            }
+            String version = StringUtils.safeString(child.getAttribute("version"));
+            if (version.isEmpty())
+                // Empty version implies no version, mark that with null.
+                version = null;
+            result.add(new GroupReference(id, version));
+        }
+
+        return result;
+    }
+
+    @Override
+    public void addExtension(IExtensionTracker tracker, IExtension extension) {
+        loadExtensions(extension.getConfigurationElements());
+    }
+
+    @Override
+    public void removeExtension(IExtension extension, Object[] objects) {
+        Set<IProjectFeatureExtension> newExtensions = new HashSet<IProjectFeatureExtension>(Arrays.asList(extensions));
+
+        for (Object o : objects) {
+            tracker.unregisterObject(extension, o);
+            newExtensions.remove(o);
+        }
+
+        // Atomic assignment
+        this.extensions = newExtensions.toArray(new IProjectFeatureExtension[newExtensions.size()]);
+    }
+
+    /* (non-Javadoc)
+     * @see org.simantics.project.IProjectFeatureRegistry#getExtensions()
+     */
+    @Override
+    public IProjectFeatureExtension[] getExtensions() {
+        return extensions;
+    }
+
+    @Override
+    public IProjectFeatureExtension getExtensionById(String id) {
+        if (id == null)
+            throw new IllegalArgumentException("null id");
+
+        for (IProjectFeatureExtension ext : extensions) {
+            if (id.equals(ext.getId()))
+                return ext;
+        }
+        return null;
+    }
+
+}