KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > commands > ExtensionParameterValues


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.ui.commands;
13
14 import java.util.Collections JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Hashtable JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.StringTokenizer JavaDoc;
19
20 import org.eclipse.core.commands.IParameterValues;
21 import org.eclipse.core.runtime.IConfigurationElement;
22 import org.eclipse.core.runtime.IExecutableExtension;
23
24 /**
25  * <p>
26  * A generic implementation of <code>IParameterValues</code> that takes advantage
27  * of the <code>IExecutableExtension</code> mechanism. The parameter values and names can be
28  * specified purely in XML. This can be done as follows:
29  * </p>
30  * <p><pre><code>
31  * &lt;command
32  * name="%name"
33  * description="%description"
34  * categoryId="categoryId"
35  * id="commandId"&gt;
36  * &lt;parameter
37  * id="parameterId"
38  * name="%parameterName"&gt;
39  * &lt;values class="org.eclipse.ui.commands.ExtensionParameterValues"&gt;
40  * &lt;parameter name="%parameterName1" value="parameterValue1" /&gt;
41  * &lt;parameter name="%parameterName2" value="parameterValue2" /&gt;
42  * &lt;parameter name="%parameterName3" value="parameterValue3" /&gt;
43  * &lt;/values&gt;
44  * &lt;/parameter&gt;
45  * &lt;/command&gt;
46  * </code></pre></p>
47  *
48  * @since 3.1
49  */

50 public final class ExtensionParameterValues implements IParameterValues,
51         IExecutableExtension {
52
53     /**
54      * The delimiter between elements if the name-value pairs are specified in a
55      * single string.
56      */

57     public static final String JavaDoc DELIMITER = ","; //$NON-NLS-1$
58

59     /**
60      * The parameter values for this instance. This is initialization when the
61      * executable extension is created. For example,
62      */

63     private Map JavaDoc parameterValues = null;
64
65     public Map JavaDoc getParameterValues() {
66         return parameterValues;
67     }
68
69     public final void setInitializationData(final IConfigurationElement config,
70             final String JavaDoc propertyName, final Object JavaDoc data) {
71         if (data == null) {
72             parameterValues = Collections.EMPTY_MAP;
73
74         } else if (data instanceof String JavaDoc) {
75             parameterValues = new HashMap JavaDoc();
76             final StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(
77                     (String JavaDoc) data, DELIMITER);
78             while (tokenizer.hasMoreTokens()) {
79                 final String JavaDoc name = tokenizer.nextToken();
80                 if (tokenizer.hasMoreTokens()) {
81                     final String JavaDoc value = tokenizer.nextToken();
82                     parameterValues.put(name, value);
83                 }
84             }
85             parameterValues = Collections.unmodifiableMap(parameterValues);
86
87         } else if (data instanceof Hashtable JavaDoc) {
88             parameterValues = Collections.unmodifiableMap((Hashtable JavaDoc) data);
89
90         }
91
92     }
93 }
94
Popular Tags