001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.ide.registry;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.core.runtime.IConfigurationElement;
015: import org.eclipse.core.runtime.IExtensionRegistry;
016: import org.eclipse.core.runtime.Platform;
017: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
018:
019: /**
020: * This class is used to read marker help context ids and
021: * resolutions from the platform registry.
022: */
023: public class MarkerHelpRegistryReader extends IDERegistryReader {
024: private MarkerHelpRegistry markerHelpRegistry;
025:
026: private ArrayList currentAttributeNames;
027:
028: private ArrayList currentAttributeValues;
029:
030: private static final String TAG_HELP = "markerHelp";//$NON-NLS-1$
031:
032: private static final String TAG_RESOLUTION_GENERATOR = "markerResolutionGenerator";//$NON-NLS-1$
033:
034: private static final String TAG_ATTRIBUTE = "attribute";//$NON-NLS-1$
035:
036: private static final String ATT_TYPE = "markerType";//$NON-NLS-1$
037:
038: private static final String ATT_NAME = "name";//$NON-NLS-1$
039:
040: private static final String ATT_VALUE = "value";//$NON-NLS-1$
041:
042: /**
043: * Get the marker help that is defined in the plugin registry
044: * and add it to the given marker help registry.
045: * <p>
046: * Warning:
047: * The marker help registry must be passed in because this
048: * method is called during the process of setting up the
049: * marker help registry and at this time it has not been
050: * safely setup with the plugin.
051: * </p>
052: */
053: public void addHelp(MarkerHelpRegistry registry) {
054: IExtensionRegistry extensionRegistry = Platform
055: .getExtensionRegistry();
056: markerHelpRegistry = registry;
057: readRegistry(extensionRegistry,
058: IDEWorkbenchPlugin.IDE_WORKBENCH,
059: IDEWorkbenchPlugin.PL_MARKER_HELP);
060: readRegistry(extensionRegistry,
061: IDEWorkbenchPlugin.IDE_WORKBENCH,
062: IDEWorkbenchPlugin.PL_MARKER_RESOLUTION);
063: }
064:
065: /**
066: * Processes one configuration element or child element.
067: */
068: protected boolean readElement(IConfigurationElement element) {
069: if (element.getName().equals(TAG_HELP)) {
070: readHelpElement(element);
071: return true;
072: }
073: if (element.getName().equals(TAG_RESOLUTION_GENERATOR)) {
074: readResolutionElement(element);
075: return true;
076: }
077: if (element.getName().equals(TAG_ATTRIBUTE)) {
078: readAttributeElement(element);
079: return true;
080: }
081: return false;
082: }
083:
084: /**
085: * Processes a help configuration element.
086: */
087: private void readHelpElement(IConfigurationElement element) {
088: // read type
089: String type = element.getAttribute(ATT_TYPE);
090:
091: // read attributes and values
092: currentAttributeNames = new ArrayList();
093: currentAttributeValues = new ArrayList();
094: readElementChildren(element);
095: String[] attributeNames = (String[]) currentAttributeNames
096: .toArray(new String[currentAttributeNames.size()]);
097: String[] attributeValues = (String[]) currentAttributeValues
098: .toArray(new String[currentAttributeValues.size()]);
099:
100: // add query to the registry
101: MarkerQuery query = new MarkerQuery(type, attributeNames);
102: MarkerQueryResult result = new MarkerQueryResult(
103: attributeValues);
104: markerHelpRegistry.addHelpQuery(query, result, element);
105: }
106:
107: /**
108: * Processes a resolution configuration element.
109: */
110: private void readResolutionElement(IConfigurationElement element) {
111: // read type
112: String type = element.getAttribute(ATT_TYPE);
113:
114: // read attributes and values
115: currentAttributeNames = new ArrayList();
116: currentAttributeValues = new ArrayList();
117: readElementChildren(element);
118: String[] attributeNames = (String[]) currentAttributeNames
119: .toArray(new String[currentAttributeNames.size()]);
120: String[] attributeValues = (String[]) currentAttributeValues
121: .toArray(new String[currentAttributeValues.size()]);
122:
123: // add query to the registry
124: MarkerQuery query = new MarkerQuery(type, attributeNames);
125: MarkerQueryResult result = new MarkerQueryResult(
126: attributeValues);
127: markerHelpRegistry.addResolutionQuery(query, result, element);
128: }
129:
130: /**
131: * Processes an attribute sub element.
132: */
133: private void readAttributeElement(IConfigurationElement element) {
134: String name = element.getAttribute(ATT_NAME);
135: String value = element.getAttribute(ATT_VALUE);
136: if (name != null && value != null) {
137: currentAttributeNames.add(name);
138: currentAttributeValues.add(value);
139: }
140: }
141: }
|