KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > registry > MarkerHelpRegistryReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide.registry;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IExtensionRegistry;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
19
20 /**
21  * This class is used to read marker help context ids and
22  * resolutions from the platform registry.
23  */

24 public class MarkerHelpRegistryReader extends IDERegistryReader {
25     private MarkerHelpRegistry markerHelpRegistry;
26
27     private ArrayList JavaDoc currentAttributeNames;
28
29     private ArrayList JavaDoc currentAttributeValues;
30
31     private static final String JavaDoc TAG_HELP = "markerHelp";//$NON-NLS-1$
32

33     private static final String JavaDoc TAG_RESOLUTION_GENERATOR = "markerResolutionGenerator";//$NON-NLS-1$
34

35     private static final String JavaDoc TAG_ATTRIBUTE = "attribute";//$NON-NLS-1$
36

37     private static final String JavaDoc ATT_TYPE = "markerType";//$NON-NLS-1$
38

39     private static final String JavaDoc ATT_NAME = "name";//$NON-NLS-1$
40

41     private static final String JavaDoc ATT_VALUE = "value";//$NON-NLS-1$
42

43     /**
44      * Get the marker help that is defined in the plugin registry
45      * and add it to the given marker help registry.
46      * <p>
47      * Warning:
48      * The marker help registry must be passed in because this
49      * method is called during the process of setting up the
50      * marker help registry and at this time it has not been
51      * safely setup with the plugin.
52      * </p>
53      */

54     public void addHelp(MarkerHelpRegistry registry) {
55         IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
56         markerHelpRegistry = registry;
57         readRegistry(extensionRegistry, IDEWorkbenchPlugin.IDE_WORKBENCH,
58                 IDEWorkbenchPlugin.PL_MARKER_HELP);
59         readRegistry(extensionRegistry, IDEWorkbenchPlugin.IDE_WORKBENCH,
60                 IDEWorkbenchPlugin.PL_MARKER_RESOLUTION);
61     }
62
63     /**
64      * Processes one configuration element or child element.
65      */

66     protected boolean readElement(IConfigurationElement element) {
67         if (element.getName().equals(TAG_HELP)) {
68             readHelpElement(element);
69             return true;
70         }
71         if (element.getName().equals(TAG_RESOLUTION_GENERATOR)) {
72             readResolutionElement(element);
73             return true;
74         }
75         if (element.getName().equals(TAG_ATTRIBUTE)) {
76             readAttributeElement(element);
77             return true;
78         }
79         return false;
80     }
81
82     /**
83      * Processes a help configuration element.
84      */

85     private void readHelpElement(IConfigurationElement element) {
86         // read type
87
String JavaDoc type = element.getAttribute(ATT_TYPE);
88
89         // read attributes and values
90
currentAttributeNames = new ArrayList JavaDoc();
91         currentAttributeValues = new ArrayList JavaDoc();
92         readElementChildren(element);
93         String JavaDoc[] attributeNames = (String JavaDoc[]) currentAttributeNames
94                 .toArray(new String JavaDoc[currentAttributeNames.size()]);
95         String JavaDoc[] attributeValues = (String JavaDoc[]) currentAttributeValues
96                 .toArray(new String JavaDoc[currentAttributeValues.size()]);
97
98         // add query to the registry
99
MarkerQuery query = new MarkerQuery(type, attributeNames);
100         MarkerQueryResult result = new MarkerQueryResult(attributeValues);
101         markerHelpRegistry.addHelpQuery(query, result, element);
102     }
103
104     /**
105      * Processes a resolution configuration element.
106      */

107     private void readResolutionElement(IConfigurationElement element) {
108         // read type
109
String JavaDoc type = element.getAttribute(ATT_TYPE);
110
111         // read attributes and values
112
currentAttributeNames = new ArrayList JavaDoc();
113         currentAttributeValues = new ArrayList JavaDoc();
114         readElementChildren(element);
115         String JavaDoc[] attributeNames = (String JavaDoc[]) currentAttributeNames
116                 .toArray(new String JavaDoc[currentAttributeNames.size()]);
117         String JavaDoc[] attributeValues = (String JavaDoc[]) currentAttributeValues
118                 .toArray(new String JavaDoc[currentAttributeValues.size()]);
119
120         // add query to the registry
121
MarkerQuery query = new MarkerQuery(type, attributeNames);
122         MarkerQueryResult result = new MarkerQueryResult(attributeValues);
123         markerHelpRegistry.addResolutionQuery(query, result, element);
124     }
125
126     /**
127      * Processes an attribute sub element.
128      */

129     private void readAttributeElement(IConfigurationElement element) {
130         String JavaDoc name = element.getAttribute(ATT_NAME);
131         String JavaDoc value = element.getAttribute(ATT_VALUE);
132         if (name != null && value != null) {
133             currentAttributeNames.add(name);
134             currentAttributeValues.add(value);
135         }
136     }
137 }
138
139
Popular Tags