KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > core > EnvironmentVariableResolver


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
12 package org.eclipse.debug.internal.core;
13
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.core.variables.IDynamicVariable;
22 import org.eclipse.core.variables.IDynamicVariableResolver;
23 import org.eclipse.debug.core.DebugPlugin;
24 import org.eclipse.osgi.service.environment.Constants;
25
26 /**
27  * Resolves the value of environment variables.
28  */

29 public class EnvironmentVariableResolver implements IDynamicVariableResolver {
30
31     /* (non-Javadoc)
32      * @see org.eclipse.core.variables.IDynamicVariableResolver#resolveValue(org.eclipse.core.variables.IDynamicVariable, java.lang.String)
33      */

34     public String JavaDoc resolveValue(IDynamicVariable variable, String JavaDoc argument) throws CoreException {
35         if (argument == null) {
36             throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), IStatus.ERROR, DebugCoreMessages.EnvironmentVariableResolver_0, null));
37         }
38         Map JavaDoc map= DebugPlugin.getDefault().getLaunchManager().getNativeEnvironmentCasePreserved();
39         String JavaDoc value= (String JavaDoc) map.get(argument);
40         if (value == null && Platform.getOS().equals(Constants.OS_WIN32)) {
41             // On Win32, env variables are case insensitive, so we search the map
42
// for matches manually.
43
Iterator JavaDoc iter = map.entrySet().iterator();
44             while (iter.hasNext()) {
45                 Map.Entry JavaDoc entry= ((Map.Entry JavaDoc) iter.next());
46                 String JavaDoc key= (String JavaDoc) entry.getKey();
47                 if (key.equalsIgnoreCase(argument)) {
48                     return (String JavaDoc) entry.getValue();
49                 }
50             }
51         }
52         return value;
53     }
54
55 }
56
Popular Tags