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 org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.IExtension;
16 import org.eclipse.core.runtime.IExtensionPoint;
17 import org.eclipse.core.runtime.IPluginRegistry;
18 import org.eclipse.core.runtime.Platform;
19 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
20 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
23 * General registry reader for external tool variables.
25 public abstract class ExternalToolVariableRegistry {
26 // Format of the variable extension points
27 // <extension point="org.eclipse.ui.externalTools.***Variables>
30 // description={string}
31 // componentClass={string:IVariableComponent}
32 // expanderClass={string:IVariable***Expander}>
38 * Element and attribute tags of a variable extension.
40 /*package*/ static final String TAG_VARIABLE = "variable"; //$NON-NLS-1$
41 /*package*/ static final String TAG_TAG = "tag"; //$NON-NLS-1$
42 /*package*/ static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
43 /*package*/ static final String TAG_COMPONENT_CLASS = "componentClass"; //$NON-NLS-1$
44 /*package*/ static final String TAG_EXPANDER_CLASS = "expanderClass"; //$NON-NLS-1$
48 * Table of variables where the key is the variable tag
49 * and the value is the corresponding variable.
51 private HashMap variables;
54 * The extension point id to read the variables from
56 private String extensionPointId;
61 * Creates a new registry and loads the variables.
63 public ExternalToolVariableRegistry(String extensionPointId) {
65 this.extensionPointId = extensionPointId;
70 * Returns the variables in the registry
72 protected final void copyVariables(Object[] results) {
73 variables.values().toArray(results);
77 * Returns the variable for the specified tag, or
78 * <code>null</code> if none found.
80 protected final ExternalToolVariable findVariable(String tag) {
81 return (ExternalToolVariable) variables.get(tag);
85 * Returns the number of variables in the registry.
87 public final int getVariableCount() {
88 return variables.size();
92 * Load the available variables
94 private void loadVariables() {
95 variables = new HashMap();
96 IPluginRegistry registry = Platform.getPluginRegistry();
97 IExtensionPoint point = registry.getExtensionPoint(IExternalToolConstants.PLUGIN_ID, extensionPointId);
99 IExtension[] extensions = point.getExtensions();
100 for (int i = 0; i < extensions.length; i++) {
101 IConfigurationElement[] elements = extensions[i].getConfigurationElements();
102 for (int j = 0; j < elements.length; j++) {
103 IConfigurationElement element = elements[j];
104 if (element.getName().equals(TAG_VARIABLE)) {
105 String tag = element.getAttribute(TAG_TAG);
106 String description = element.getAttribute(TAG_DESCRIPTION);
107 String className = element.getAttribute(TAG_EXPANDER_CLASS);
109 boolean valid = true;
110 if (tag == null || tag.length() == 0) {
112 ExternalToolsPlugin.getDefault().log("Missing tag attribute value for variable element.", null); //$NON-NLS-1$
114 if (description == null || description.length() == 0) {
116 ExternalToolsPlugin.getDefault().log("Missing description attribute value for variable element.", null); //$NON-NLS-1$
118 if (className == null || className.length() == 0) {
120 ExternalToolsPlugin.getDefault().log("Missing expander class attribute value for variable element.", null); //$NON-NLS-1$
124 variables.put(tag, newVariable(tag, description, element));
132 * Creates a new variable from the specified information.
134 protected abstract ExternalToolVariable newVariable(String tag, String description, IConfigurationElement element);