1 package net.sourceforge.phpdt.externaltools.internal.registry;
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
10 **********************************************************************/
12 import java.util.HashMap;
14 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
15 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExtension;
19 import org.eclipse.core.runtime.IExtensionPoint;
20 import org.eclipse.core.runtime.IPluginRegistry;
21 import org.eclipse.core.runtime.Platform;
24 * General registry reader for external tool variables.
26 public abstract class ExternalToolVariableRegistry {
27 // Format of the variable extension points
28 // <extension point="org.eclipse.ui.externalTools.***Variables>
31 // description={string}
32 // componentClass={string:IVariableComponent}
33 // expanderClass={string:IVariable***Expander}>
39 * Element and attribute tags of a variable extension.
41 /*package*/ static final String TAG_VARIABLE = "variable"; //$NON-NLS-1$
42 /*package*/ static final String TAG_TAG = "tag"; //$NON-NLS-1$
43 /*package*/ static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
44 /*package*/ static final String TAG_COMPONENT_CLASS = "componentClass"; //$NON-NLS-1$
45 /*package*/ static final String TAG_EXPANDER_CLASS = "expanderClass"; //$NON-NLS-1$
49 * Table of variables where the key is the variable tag
50 * and the value is the corresponding variable.
52 private HashMap variables;
55 * The extension point id to read the variables from
57 private String extensionPointId;
62 * Creates a new registry and loads the variables.
64 public ExternalToolVariableRegistry(String extensionPointId) {
66 this.extensionPointId = extensionPointId;
71 * Returns the variables in the registry
73 protected final void copyVariables(Object[] results) {
74 variables.values().toArray(results);
78 * Returns the variable for the specified tag, or
79 * <code>null</code> if none found.
81 protected final ExternalToolVariable findVariable(String tag) {
82 return (ExternalToolVariable) variables.get(tag);
86 * Returns the number of variables in the registry.
88 public final int getVariableCount() {
89 return variables.size();
93 * Load the available variables
95 private void loadVariables() {
96 variables = new HashMap();
97 IPluginRegistry registry = Platform.getPluginRegistry();
98 IExtensionPoint point = registry.getExtensionPoint(IExternalToolConstants.PLUGIN_ID, extensionPointId);
100 IExtension[] extensions = point.getExtensions();
101 for (int i = 0; i < extensions.length; i++) {
102 IConfigurationElement[] elements = extensions[i].getConfigurationElements();
103 for (int j = 0; j < elements.length; j++) {
104 IConfigurationElement element = elements[j];
105 if (element.getName().equals(TAG_VARIABLE)) {
106 String tag = element.getAttribute(TAG_TAG);
107 String description = element.getAttribute(TAG_DESCRIPTION);
108 String className = element.getAttribute(TAG_EXPANDER_CLASS);
110 boolean valid = true;
111 if (tag == null || tag.length() == 0) {
113 ExternalToolsPlugin.getDefault().log("Missing tag attribute value for variable element.", null); //$NON-NLS-1$
115 if (description == null || description.length() == 0) {
117 ExternalToolsPlugin.getDefault().log("Missing description attribute value for variable element.", null); //$NON-NLS-1$
119 if (className == null || className.length() == 0) {
121 ExternalToolsPlugin.getDefault().log("Missing expander class attribute value for variable element.", null); //$NON-NLS-1$
125 variables.put(tag, newVariable(tag, description, element));
133 * Creates a new variable from the specified information.
135 protected abstract ExternalToolVariable newVariable(String tag, String description, IConfigurationElement element);