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.model.IExternalToolConstants;
 
  15 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
 
  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$
 
  43         /* package */static final String TAG_TAG = "tag"; //$NON-NLS-1$
 
  45         /* package */static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
 
  47         /* package */static final String TAG_COMPONENT_CLASS = "componentClass"; //$NON-NLS-1$
 
  49         /* package */static final String TAG_EXPANDER_CLASS = "expanderClass"; //$NON-NLS-1$
 
  52          * Table of variables where the key is the variable tag and the value is the
 
  53          * corresponding variable.
 
  55         private HashMap variables;
 
  58          * The extension point id to read the variables from
 
  60         private String extensionPointId;
 
  63          * The /** Creates a new registry and loads the variables.
 
  65         public ExternalToolVariableRegistry(String extensionPointId) {
 
  67                 this.extensionPointId = extensionPointId;
 
  72          * Returns the variables in the registry
 
  74         protected final void copyVariables(Object[] results) {
 
  75                 variables.values().toArray(results);
 
  79          * Returns the variable for the specified tag, or <code>null</code> if
 
  82         protected final ExternalToolVariable findVariable(String tag) {
 
  83                 return (ExternalToolVariable) variables.get(tag);
 
  87          * Returns the number of variables in the registry.
 
  89         public final int getVariableCount() {
 
  90                 return variables.size();
 
  94          * Load the available variables
 
  96         private void loadVariables() {
 
  97                 variables = new HashMap();
 
  98                 IExtensionRegistry registry = Platform.getExtensionRegistry();
 
  99                 // IPluginRegistry registry = Platform.getPluginRegistry();
 
 100                 IExtensionPoint point = registry.getExtensionPoint(
 
 101                                 IExternalToolConstants.PLUGIN_ID, extensionPointId);
 
 103                         IExtension[] extensions = point.getExtensions();
 
 104                         for (int i = 0; i < extensions.length; i++) {
 
 105                                 IConfigurationElement[] elements = extensions[i]
 
 106                                                 .getConfigurationElements();
 
 107                                 for (int j = 0; j < elements.length; j++) {
 
 108                                         IConfigurationElement element = elements[j];
 
 109                                         if (element.getName().equals(TAG_VARIABLE)) {
 
 110                                                 String tag = element.getAttribute(TAG_TAG);
 
 111                                                 String description = element
 
 112                                                                 .getAttribute(TAG_DESCRIPTION);
 
 113                                                 String className = element
 
 114                                                                 .getAttribute(TAG_EXPANDER_CLASS);
 
 116                                                 boolean valid = true;
 
 117                                                 if (tag == null || tag.length() == 0) {
 
 122                                                                                         "Missing tag attribute value for variable element.", null); //$NON-NLS-1$
 
 124                                                 if (description == null || description.length() == 0) {
 
 129                                                                                         "Missing description attribute value for variable element.", null); //$NON-NLS-1$
 
 131                                                 if (className == null || className.length() == 0) {
 
 136                                                                                         "Missing expander class attribute value for variable element.", null); //$NON-NLS-1$
 
 140                                                         variables.put(tag, newVariable(tag, description,
 
 149          * Creates a new variable from the specified information.
 
 151         protected abstract ExternalToolVariable newVariable(String tag,
 
 152                         String description, IConfigurationElement element);