# com.bea.ide.workspace
IWorkspace Interface

public interface IWorkspace
extends `IPreferencesSupport`, `IPropertySupport`

Represents the content, configuration, and current state of a Workshop application.

The IWorkspace currently open in Workshop may be obtained by using Application.getWorkspace(). An IWorkspace may contain IProjects, shared libraries, and J2EE modules. If the application is a deployable J2EE EAR, then the root directory of the IWorkspace will be the exploded EAR directory deployed to WebLogic Server.

A .work file in the IWorkspace's root directory contains application configuration information, including the set of projects in the app. The .work file is intended to be sharable among application developers, and any paths it contains should be relative to the workspace or project root directories. Use the system Preferences node to read and write information to the .work file. User and machine-specific information may be persisted with the user Preferences node.

All Superinterfaces
  `IPreferencesSupport`, `IPropertySupport`

## Nested Class Summary

`public static interface` | `IWorkspace.IWorkspaceState` Represents an IWorkspace state.

## Field Summary

`public static final `String`` | `PROP_IsDeploying` Set to Boolean.TRUE during deployment
`public static final `String`` | `STATE_IsBuilding` State id set while a build operation is in progress.
`public static final `String`` | `STATE_IsRunning` State id set while a debugging operation is in progress.

## Method Summary

`public boolean` | `addLibrary`(`URI` libraryURI) Adds a file as a library.
`public boolean` | `addLibrary`(`URI` libraryURI, `String` destName, boolean overwrite) Adds a file as a library.
`public boolean` | `addModule`(`URI` moduleURI) Adds a file as a module, deploying it if the server is running.
`public void` | `clearState`(`String` stateName) Call this method after successfully seting the state to signify the state is no longer in effect.
`public boolean` | `close`() Saves the .work and .pref files, removes all listeners that the workspace has registered.
`public `IProject`` | `findProject`(`URI` uri) Find the project that contains the given URI.
`public `IProject`` | `findProject`(`String` name) Find the project with the specified name.
`public boolean` | `getBooleanProperty`(`String` propName) Returns an IWorkspace property as a boolean value.
`public `IFile`` | `getCacheRoot`() Returns a directory where workspace-related files may be cached by Workshop services.
`public `String`` | `getClassName`(`URI` doc) Compute the class name for the given file.
`public `IProject`` | `getCurrentSelectedProject`() Returns the currently selected project.
`public `IFile`` | `getDirectory`() Returns the workspace root directory.
`public `String`` | `getDisplayPath`(`URI` uri) Returns the display path for the uri.
`public `String`` | `getHome`(`String` homeKey) Used to lookup home directory paths.
`public `String`` | `getHttpRoot`() Get the base of the URL for this workspace's server.
`public `IFile`` | `getIFile`() Returns the .work file for this workspace.
`public `URI`[]` | `getLibraries`() Returns an array containing all of the shared libraries in this workspace.
`public `IFile`` | `getLibrariesDirectory`() Returns the J2EE libraries directory.
`public `IModule`[]` | `getModules`() Returns an array of URIs containing all of the modules (EJBs, web-apps, etc.)
`public `IFile`` | `getModulesDirectory`() Returns the J2EE Modules directory.
`public `String`` | `getName`() Returns the name of this workspace.
`public `IProject`` | `getProject`(`String` name) Find the project that has the given name.
`public `String`` | `getProjectPath`(`URI` uri) Returns the relative path of the given file inside this project.
`public `IProject`[]` | `getProjects`() Returns a list of all the projects in this workspace.
`public `IProject`[]` | `getProjects`(`String` attribute) Returns a list of all the projects in this workspace that support a given attribute.
`public `String`` | `getRelativePath`(`URI` uri) Returns a path relative to .work file.
`public `ISecurityConfig`` | `getSecurityConfig`() Gets the current security configuration.
`public `IWorkspace.IWorkspaceState`` | `getState`() Returns the current state of the workspace, or null if it is not in a specific state.
`public `IFile`` | `newFile`(`String` path) Returns a file given a path relative to the workspace directory.
`public `URI`` | `newURI`(`String` path) returns a URI given a path relative to the workspace directory.
`public boolean` | `removeLibrary`(`String` libraryName) Removes a file from the libraries.
`public boolean` | `removeModule`(`String` moduleName) Removes a module from the application.
`public boolean` | `removeProject`(`String` name, boolean delete) Remove the project from the Workspace.
`public boolean` | `renameProject`(`String` oldName, `String` newName) Renames the Project.
`public boolean` | `save`() Saves the .work and user preferences file to disk.
`public void` | `saveSecurityConfig`(`ISecurityConfig` config) Sets this security configuration as the workspace's and stores its settings.
`public void` | `setName`(`String` name) Sets the name of this workspace.
`public void` | `setState`(`String` stateName, `String` userVerb, `IActionProxy` stopAction) Projects can be set in states that exclude all other actions from changing the state until the state is cleared.
`public `Preferences`` | `systemNodeForPackage`(`String` name) Get the preference subtree in the system preferences that corresponds to the given package name.
`public `Preferences`` | `userNodeForPackage`(`String` name) Get the preference subtree in the user preferences that corresponds to the given package name.

Methods from interface `com.bea.ide.core.`IPreferencesSupport``
``getUserObject`, `setUserObject`, `systemNodeForPackage`, `systemRoot`, `userNodeForPackage`, `userRoot``

Methods from interface `com.bea.ide.core.`IPropertySupport``
``addPropertyChangeListener`, `addPropertyChangeListener`, `getProperty`, `removePropertyChangeListener`, `removePropertyChangeListener`, `setProperty``

## Field Detail

### PROP_IsDeploying

    public static final String PROP_IsDeploying

  Set to Boolean.TRUE during deployment

### STATE_IsBuilding

    public static final String STATE_IsBuilding

  State id set while a build operation is in progress.

### STATE_IsRunning

    public static final String STATE_IsRunning

  State id set while a debugging operation is in progress.

## Method Detail

### addLibrary(URI) Method

    public boolean addLibrary(URI libraryURI)

Adds a file as a library. This copies the file into the APP-INF/lib directory. Library name will be the same as the source URI file name. If the libary exists, the user will be prompted for whether to overwrite.

#### Parameters

libraryURI
  source URI

#### Returns

true if library was successfully added, false if add failed.

### addLibrary(URI, String, boolean) Method

    public boolean addLibrary(URI libraryURI,
                              String destName,
                              boolean overwrite)

Adds a file as a library. This copies a file into the APP-INF/lib directory.

#### Parameters

libraryURI
  source URI

destName
  name to give the library, if null, name will be the same as the source URI name.

overwrite
  whether to overwrite an existing library file of the given name. If false, and the library exists, the user will be prompted for whether to overwrite.

#### Returns

true if library was successfully added, false if add failed.

### addModule(URI) Method

    public boolean addModule(URI moduleURI)

Adds a file as a module, deploying it if the server is running.

### clearState(String) Method

    public void clearState(String stateName)

Call this method after successfully seting the state to signify the state is no longer in effect.

#### Parameters

stateName
  the Property key of the finished state change. The property will be set to Boolean.FALSE

### close() Method

    public boolean close()

Saves the .work and .pref files, removes all listeners that the workspace has registered. There is no way to make the workspace "live" again after calling close.

### findProject(URI) Method

    public IProject findProject(URI uri)

Find the project that contains the given URI. May return null.

#### Parameters

uri
  file in some project in this workspace

### findProject(String) Method

    public IProject findProject(String name)

Find the project with the specified name. May return null.

#### Parameters

name
  name of the project to locate

### getBooleanProperty(String) Method

    public boolean getBooleanProperty(String propName)

Returns an IWorkspace property as a boolean value.

### getCacheRoot() Method

    public IFile getCacheRoot()

Returns a directory where workspace-related files may be cached by Workshop services. The content of this directory will not be deleted when the IWorkspace is closed. It is located beneath the application root directory, so it will be deleted if/when the user deletes the application from the filesystem.

#### Returns

cache location IFile.

### getClassName(URI) Method

    public String getClassName(URI doc)

Compute the class name for the given file. Does this by finding a parent directory in the source path and computing package.

### getCurrentSelectedProject() Method

    public IProject getCurrentSelectedProject()

Returns the currently selected project. Application.PROP_FocusedURIs is used to determine the currently focused URI in Workshop. If the focused URI is within a workspace project, then that project will be returned. Otherwise, the project of the last opened document will be returned. If the last opened document cannot be determined, then the first IProject in the project list will be returned.

### getDirectory() Method

    public IFile getDirectory()

Returns the workspace root directory.

#### Returns

IFile workspace directory.

### getDisplayPath(URI) Method

    public String getDisplayPath(URI uri)

Returns the display path for the uri. This includes the project name and the project relative path only.

### getHome(String) Method

    public String getHome(String homeKey)

Used to lookup home directory paths.

### getHttpRoot() Method

    public String getHttpRoot()

Get the base of the URL for this workspace's server. e.g. http://localhost:7001

### getIFile() Method

    public IFile getIFile()

Returns the .work file for this workspace.

### getLibraries() Method

    public URI[] getLibraries()

Returns an array containing all of the shared libraries in this workspace.

### getLibrariesDirectory() Method

    public IFile getLibrariesDirectory()

Returns the J2EE libraries directory.

### getModules() Method

    public IModule[] getModules()

Returns an array of URIs containing all of the modules (EJBs, web-apps, etc.)

### getModulesDirectory() Method

    public IFile getModulesDirectory()

Returns the J2EE Modules directory.

### getName() Method

    public String getName()

Returns the name of this workspace. The name is independent of the filename or the containing folder, and is stored inside the workspace file.

### getProject(String) Method

    public IProject getProject(String name)

Find the project that has the given name. May return null.

#### Parameters

name
  Name of a project in this workspace

### getProjectPath(URI) Method

    public String getProjectPath(URI uri)

Returns the relative path of the given file inside this project.

### getProjects() Method

    public IProject[] getProjects()

Returns a list of all the projects in this workspace.

### getProjects(String) Method

    public IProject[] getProjects(String attribute)

Returns a list of all the projects in this workspace that support a given attribute.

### getRelativePath(URI) Method

    public String getRelativePath(URI uri)

Returns a path relative to .work file. If the uri does not refer to a resource within the directory containing the .work file, this method returns null.

### getSecurityConfig() Method

    public ISecurityConfig getSecurityConfig()

Gets the current security configuration. The SecurityConfiguration represents a snapshot of the present security settings, such as the current security roles and test users. It is mutable, and is not stored permanently until saveSecurityConfig() is called.

#### Returns

The security configuration

Related Topics

``ISecurityConfig``

### getState() Method

    public IWorkspace.IWorkspaceState getState()

Returns the current state of the workspace, or null if it is not in a specific state. The name and verb of the current state is available through IWorkspaceState.

#### Returns

IWorkspaceState

### newFile(String) Method

    public IFile newFile(String path)

Returns a file given a path relative to the workspace directory. Can safely be called with absolute paths.

#### Parameters

path
  relative or absolute path

#### Returns

IFile for path.

### newURI(String) Method

    public URI newURI(String path)

returns a URI given a path relative to the workspace directory. Can safely be called with absolute paths.

#### Parameters

path
  relative or absolute path

#### Returns

URI for path.

### removeLibrary(String) Method

    public boolean removeLibrary(String libraryName)

Removes a file from the libraries. This deletes the given file from the APP-INF/lib directory.

#### Parameters

libraryName
  The name of the library file to remove. This should be the filename, but not a complete path to the file.

### removeModule(String) Method

    public boolean removeModule(String moduleName)

Removes a module from the application. This will also undeploy it.

#### Parameters

moduleName
  The name of the module to remove (e.g. myEJB.jar). This should be the filename, but not a complete path to the file.

### removeProject(String, boolean) Method

    public boolean removeProject(String name,
                                 boolean delete)

Remove the project from the Workspace. Optionally deletes the project on disk.

#### Parameters

name
  the name of the project to remove from this workspace

delete
  if true, delete the project from disk

#### Returns

true if the remove succeeded, false if the user cancelled the remove operation

### renameProject(String, String) Method

    public boolean renameProject(String oldName,
                                 String newName)

Renames the Project. Does not change the directory name, just the user-visible name.

#### Parameters

oldName
  Name of the project to be renamed.

newName
  Name the project should be given.

#### Returns

true if rename was successful, false if not.

### save() Method

    public boolean save()

Saves the .work and user preferences file to disk.

### saveSecurityConfig(ISecurityConfig) Method

    public void saveSecurityConfig(ISecurityConfig config)

Sets this security configuration as the workspace's and stores its settings.

#### Parameters

config
  The security configuration to save

Related Topics

``ISecurityConfig``

### setName(String) Method

    public void setName(String name)

Sets the name of this workspace.

### setState(String, String, IActionProxy) Method

    public void setState(String stateName,
                         String userVerb,
                         IActionProxy stopAction)
         throws IllegalStateException

Projects can be set in states that exclude all other actions from changing the state until the state is cleared. A good example is build; when the project is being built, the project's state is set with this call. Other actions that need to set the state, such as debugging, will not be able to change the state unless the user agrees to stop the current active state (like build) in order to perform the new action(debugging).

If the user chooses not to cancel the current state, an IllegalStateException is thrown and the caller must cancel their operation.

The only predefined state is the closed state, where a project has been removed from the workspace or the workspace itself has been closed. Ideally, closed projects should be discarded, but race conditions exist between when the project is closed and when the notifications of said closing are processed.

SetState helps resolve this problem for those operations that require the project to be in a non-closed state for their duration. The user must authorize the canceling of pending state-changing operations for the close to go forward.

Callers of this method must bound their operation between setState and clearState. The caller must pass in a user-readable operation verb (for instance, "building") as well as an IActionProxy that can be used to stop the operation. All states must pass in a stopAction. This stopAction must be synchronous, and thus should not return from actionPerformed until the action it stops is completely stopped.

#### Parameters

stateName
  Identifier for the state.

userVerb
  Human-readable verb to describe the operation. For example, "building"

stopAction
  An action that can be used to stop the operation.

#### Exceptions

``IllegalStateException``
  Thrown when the state cannot be set. Cancel the operation.

### systemNodeForPackage(String) Method

    public Preferences systemNodeForPackage(String name)

Get the preference subtree in the system preferences that corresponds to the given package name.

#### Parameters

name
  String package name.

#### Returns

Preference node associated with the given package name. If no such node exists, an empty one is created and returned.

### userNodeForPackage(String) Method

    public Preferences userNodeForPackage(String name)

Get the preference subtree in the user preferences that corresponds to the given package name.

#### Parameters

name
  String package name.

#### Returns

Preference node associated with the given package name. If no such node exists, an empty one is created and returned.