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.IExtensionRegistry;
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 IExtensionRegistry registry= Platform.getExtensionRegistry();
98 // IPluginRegistry registry = Platform.getPluginRegistry();
99 IExtensionPoint point = registry.getExtensionPoint(IExternalToolConstants.PLUGIN_ID, extensionPointId);
101 IExtension[] extensions = point.getExtensions();
102 for (int i = 0; i < extensions.length; i++) {
103 IConfigurationElement[] elements = extensions[i].getConfigurationElements();
104 for (int j = 0; j < elements.length; j++) {
105 IConfigurationElement element = elements[j];
106 if (element.getName().equals(TAG_VARIABLE)) {
107 String tag = element.getAttribute(TAG_TAG);
108 String description = element.getAttribute(TAG_DESCRIPTION);
109 String className = element.getAttribute(TAG_EXPANDER_CLASS);
111 boolean valid = true;
112 if (tag == null || tag.length() == 0) {
114 ExternalToolsPlugin.getDefault().log("Missing tag attribute value for variable element.", null); //$NON-NLS-1$
116 if (description == null || description.length() == 0) {
118 ExternalToolsPlugin.getDefault().log("Missing description attribute value for variable element.", null); //$NON-NLS-1$
120 if (className == null || className.length() == 0) {
122 ExternalToolsPlugin.getDefault().log("Missing expander class attribute value for variable element.", null); //$NON-NLS-1$
126 variables.put(tag, newVariable(tag, description, element));
134 * Creates a new variable from the specified information.
136 protected abstract ExternalToolVariable newVariable(String tag, String description, IConfigurationElement element);