org.eclipse.core.internal.resources
Class PathVariableManager

java.lang.Object
  extended by org.eclipse.core.internal.resources.PathVariableManager
All Implemented Interfaces:
IManager, IPathVariableManager

public class PathVariableManager
extends java.lang.Object
implements IPathVariableManager, IManager

Core's implementation of IPathVariableManager.


Constructor Summary
PathVariableManager()
          Constructor for the class.
 
Method Summary
 void addChangeListener(IPathVariableChangeListener listener)
          Registers the given listener to receive notification of changes to path variables.
 java.lang.String[] getPathVariableNames()
          Returns an array containing all defined path variable names.
 org.eclipse.core.runtime.IPath getValue(java.lang.String varName)
          Note that if a user changes the key in the preferences file to be invalid and then calls #getValue using that key, they will get the value back for that.
 boolean isDefined(java.lang.String varName)
          Returns true if the given variable is defined and false otherwise.
 void removeChangeListener(IPathVariableChangeListener listener)
          Removes the given path variable change listener from the listeners list.
 org.eclipse.core.runtime.IPath resolvePath(org.eclipse.core.runtime.IPath path)
          Resolves a relative IPath object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute path).
 java.net.URI resolveURI(java.net.URI uri)
          Resolves a relative URI object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute URI).
 void setValue(java.lang.String varName, org.eclipse.core.runtime.IPath newValue)
          Sets the path variable with the given name to be the specified value.
 void shutdown(org.eclipse.core.runtime.IProgressMonitor monitor)
           
 void startup(org.eclipse.core.runtime.IProgressMonitor monitor)
           
 org.eclipse.core.runtime.IStatus validateName(java.lang.String name)
          Validates the given name as the name for a path variable.
 org.eclipse.core.runtime.IStatus validateValue(org.eclipse.core.runtime.IPath value)
          Validates the given path as the value for a path variable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathVariableManager

public PathVariableManager()
Constructor for the class.

Method Detail

addChangeListener

public void addChangeListener(IPathVariableChangeListener listener)
Description copied from interface: IPathVariableManager
Registers the given listener to receive notification of changes to path variables. The listener will be notified whenever a variable has been added, removed or had its value changed. Has no effect if an identical path variable change listener is already registered.

Specified by:
addChangeListener in interface IPathVariableManager
Parameters:
listener - the listener
See Also:
IPathVariableManager#addChangeListener(IPathVariableChangeListener)

getPathVariableNames

public java.lang.String[] getPathVariableNames()
Description copied from interface: IPathVariableManager
Returns an array containing all defined path variable names.

Specified by:
getPathVariableNames in interface IPathVariableManager
Returns:
an array containing all defined path variable names
See Also:
IPathVariableManager.getPathVariableNames()

getValue

public org.eclipse.core.runtime.IPath getValue(java.lang.String varName)
Note that if a user changes the key in the preferences file to be invalid and then calls #getValue using that key, they will get the value back for that. But then if they try and call #setValue using the same key it will throw an exception. We may want to revisit this behaviour in the future.

Specified by:
getValue in interface IPathVariableManager
Parameters:
varName - the name of the variable to return the value for
Returns:
the value for the variable, or null if there is no variable defined with the given name
See Also:
IPathVariableManager.getValue(String)

isDefined

public boolean isDefined(java.lang.String varName)
Description copied from interface: IPathVariableManager
Returns true if the given variable is defined and false otherwise. Returns false if the given name is not a valid path variable name.

Specified by:
isDefined in interface IPathVariableManager
Parameters:
varName - the variable's name
Returns:
true if the variable exists, false otherwise
See Also:
IPathVariableManager.isDefined(String)

removeChangeListener

public void removeChangeListener(IPathVariableChangeListener listener)
Description copied from interface: IPathVariableManager
Removes the given path variable change listener from the listeners list. Has no effect if an identical listener is not registered.

Specified by:
removeChangeListener in interface IPathVariableManager
Parameters:
listener - the listener
See Also:
IPathVariableManager#removeChangeListener(IPathVariableChangeListener)

resolvePath

public org.eclipse.core.runtime.IPath resolvePath(org.eclipse.core.runtime.IPath path)
Description copied from interface: IPathVariableManager
Resolves a relative IPath object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute path). If the given path is absolute or has a non- null device then no variable substitution is done and that path is returned as is. If the given path is relative and has a null device, but the first segment does not correspond to a defined variable, then the path is returned as is.

If the given path is null then null will be returned. In all other cases the result will be non-null.

For example, consider the following collection of path variables:

The following paths would be resolved as:

c:/bin => c:/bin

c:TEMP => c:TEMP

/TEMP => /TEMP

TEMP => c:/temp

TEMP/foo => c:/temp/foo

BACKUP => /tmp/backup

BACKUP/bar.txt => /tmp/backup/bar.txt

SOMEPATH/foo => SOMEPATH/foo

Specified by:
resolvePath in interface IPathVariableManager
Parameters:
path - the path to be resolved
Returns:
the resolved path or null
See Also:
IPathVariableManager.resolvePath(IPath)

resolveURI

public java.net.URI resolveURI(java.net.URI uri)
Description copied from interface: IPathVariableManager
Resolves a relative URI object potentially containing a variable reference as its first segment, replacing the variable reference (if any) with the variable's value (which is a concrete absolute URI). If the given URI is absolute or has a non- null device then no variable substitution is done and that URI is returned as is. If the given URI is relative and has a null device, but the first segment does not correspond to a defined variable, then the URI is returned as is.

If the given URI is null then null will be returned. In all other cases the result will be non-null.

Specified by:
resolveURI in interface IPathVariableManager
Parameters:
uri - the URI to be resolved
Returns:
the resolved URI or null

setValue

public void setValue(java.lang.String varName,
                     org.eclipse.core.runtime.IPath newValue)
              throws org.eclipse.core.runtime.CoreException
Description copied from interface: IPathVariableManager
Sets the path variable with the given name to be the specified value. Depending on the value given and if the variable is currently defined or not, there are several possible outcomes for this operation:

If a variable is effectively changed, created or removed by a call to this method, notification will be sent to all registered listeners.

Specified by:
setValue in interface IPathVariableManager
Parameters:
varName - the name of the variable
newValue - the value for the variable (may be null)
Throws:
org.eclipse.core.runtime.CoreException - if this method fails. Reasons include:
  • The variable name is not valid
  • The variable value is relative
See Also:
IPathVariableManager.setValue(String, IPath)

shutdown

public void shutdown(org.eclipse.core.runtime.IProgressMonitor monitor)
Specified by:
shutdown in interface IManager
See Also:
IManager.shutdown(IProgressMonitor)

startup

public void startup(org.eclipse.core.runtime.IProgressMonitor monitor)
Specified by:
startup in interface IManager
See Also:
IManager.startup(IProgressMonitor)

validateName

public org.eclipse.core.runtime.IStatus validateName(java.lang.String name)
Description copied from interface: IPathVariableManager
Validates the given name as the name for a path variable. A valid path variable name is made exclusively of letters, digits and the underscore character, and does not start with a digit.

Specified by:
validateName in interface IPathVariableManager
Parameters:
name - a possibly valid path variable name
Returns:
a status object with code IStatus.OK if the given name is a valid path variable name, otherwise a status object indicating what is wrong with the string
See Also:
IPathVariableManager.validateName(String)

validateValue

public org.eclipse.core.runtime.IStatus validateValue(org.eclipse.core.runtime.IPath value)
Description copied from interface: IPathVariableManager
Validates the given path as the value for a path variable. A path variable value must be a valid path that is absolute.

Specified by:
validateValue in interface IPathVariableManager
Parameters:
value - a possibly valid path variable value
Returns:
a status object with code IStatus.OK if the given path is a valid path variable value, otherwise a status object indicating what is wrong with the value
See Also:
IPathVariableManager.validateValue(IPath)