Package org.eclipse.birt.report.model.api

# Class SessionHandle

java.lang.Object
org.eclipse.birt.report.model.api.SessionHandle

public class SessionHandle extends Object
Represents the design state -- a session for a user. In the Eclipse environment, this represents the set of open designs. In the web environment, this represents open designs and locale for the session. A session has a set of default values for style properties and a default unit. The session also has methods to create and open designs.

A session can also provides the mechanism for specified file searching algorithm. After get an new instance of SessionHandle, an algorithm of how to search a file should be set by calling ``setResourceLocator(IResourceLocator)`` if the default resource locator is not the expected one.

The default resource locator will search in the folder where the design file is located.

See Also:
  - `ResourceLocatorImpl`
  - `DesignSession`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected org.eclipse.birt.report.model.core.DesignSession`
`session`
The implementation of the design session.

## Constructor Summary

Constructors
Constructor
Description
`SessionHandle(com.ibm.icu.util.ULocale locale)`
Constructs a handle for the session with the given locale.
`SessionHandle(Locale locale)`
Deprecated.
to use ICU4J, this method is replaced by: SessionHandle(ULocale locale)

## Method Summary

Modifier and Type
Method
Description
`void`
`activate()`
Activates this session within a thread.
`void`
`addResourceChangeListener(IResourceChangeListener listener)`
Adds one resource change listener.
`void`
`closeAll(boolean save)`
Closes all open designs and libraires.
`ReportDesignHandle`
`createDesign()`
Creates a new empty design.
`ReportDesignHandle`
`createDesign(String fileName)`
Creates a new design based on a file name.
`ReportDesignHandle`
`createDesign(String fileName, ModuleOption options)`
Creates a new design based on the file name and the module options.
`ReportDesignHandle`
`createDesignFromTemplate(String templateDesignName)`
Creates a new design based on a template file.
`ReportDesignHandle`
`createDesignFromTemplate(String templateDesignName, InputStream is)`
Creates a new design based a given template file name and input stream.
`LibraryHandle`
`createLibrary()`
Creates a new empty library.
`LibraryHandle`
`createLibraryFromTemplate(String templateLibraryName)`
Creates a new library based on a template file.
`void`
`fireResourceChange(ResourceChangeEvent ev)`
Informs this session some resources is changed.
`String`
`getApplicationUnits()`
Returns the current session (application) units.
`static String`
`getBirtResourcePath()`
Gets resource path.
`int`
`getColorFormat()`
Returns the current application rgb color display preference.
`StyleHandle`
`getDefaultTOCStyle(String name)`
Gets default TOC Style.Heading 1 -> Heading 10.
`Object`
`getDefaultValue(String propName)`
Gets the default value of the specified style property.
`Locale`
`getLocale()`
Deprecated.
to use ICU4J, replaced by: public ULocale getLocale()
`IAbsoluteFontSizeValueProvider`
`getPredefinedFontSizeProvider()`
Returns the provider instance which provides the absolute dimension value of predefined font size choice.
`String`
`getResourceFolder()`
Gets the resource folder set in this session.
`IResourceLocator`
`getResourceLocator()`
Returns the installed resource locator.
`com.ibm.icu.util.ULocale`
`getULocale()`
Returns the locale of the current session.
`ReportDesignHandle`
`openDesign(String fileName)`
Opens a design with the given the file name.
`ReportDesignHandle`
`openDesign(String fileName, InputStream is)`
Opens a design given a stream to the design and the the file name of the design.
`ReportDesignHandle`
`openDesign(String fileName, InputStream is, ModuleOption options)`
Opens a design given a stream to the design and the the file name of the design.
`ReportDesignHandle`
`openDesign(String fileName, ModuleOption options)`
Opens a design with the given the file name.
`ReportDesignHandle`
`openDesign(URL systemId, InputStream is)`
Opens a design given a stream to the design and the the file name of the design.
`ReportDesignHandle`
`openDesign(URL systemId, InputStream is, ModuleOption options)`
Opens a design given a stream to the design and the the file name of the design.
`LibraryHandle`
`openLibrary(String fileName)`
Opens a library with the given the file name.
`LibraryHandle`
`openLibrary(String fileName, InputStream is)`
Opens a library given a stream to the design and the the file name of the design.
`LibraryHandle`
`openLibrary(String fileName, InputStream is, ModuleOption options)`
Opens a library given a stream to the design and the the file name of the design.
`LibraryHandle`
`openLibrary(String fileName, ModuleOption options)`
Opens a library with the given the file name.
`LibraryHandle`
`openLibrary(URL systemId, InputStream is)`
Opens a library with the given the file name.
`LibraryHandle`
`openLibrary(URL systemId, InputStream is, ModuleOption options)`
Opens a library with the given the file name.
`ModuleHandle`
`openModule(String fileName)`
Opens a module regardless of the module type(library or report design).
`ModuleHandle`
`openModule(String fileName, InputStream is)`
Opens a module regardless of the module type(library or report design).
`ModuleHandle`
`openModule(String fileName, InputStream is, ModuleOption options)`
Opens a module regardless of the module type(library or report design).
`ModuleHandle`
`openModule(String fileName, ModuleOption options)`
Opens a module regardless of the module type(library or report design).
`boolean`
`removeResourceChangeListener(IResourceChangeListener listener)`
Removes one resource change listener.
`void`
`saveAll()`
Saves all designs and librariesthat need a save.
`void`
`setApplicationUnits(String units)`
Sets the units to be used by the application.
`static void`
`setBirtResourcePath(String resourcePath)`
Sets resource path.
`void`
`setColorFormat(int rgbFormat)`
Sets the rgb color display preference to be used by the application.
`void`
`setDefaultValue(String propName, Object value)`
Sets the specified default value of style property.
`void`
`setResourceFolder(String resourceFolder)`
Sets the resource folder for this session.
`void`
`setResourceLocator(IResourceLocator locator)`
Sets the resource locator for the specified file searching algorithm.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### session

protected org.eclipse.birt.report.model.core.DesignSession session
The implementation of the design session.

## Constructor Details

### SessionHandle

@Deprecated public SessionHandle(Locale locale)
Deprecated.
to use ICU4J, this method is replaced by: SessionHandle(ULocale locale)
Constructs a handle for the session with the given locale.

Parameters:
  `locale` - the user's locale. If null, then the system locale is assumed.

### SessionHandle

public SessionHandle(com.ibm.icu.util.ULocale locale)
Constructs a handle for the session with the given locale.

Parameters:
  `locale` - the user's locale which is `ULocale`. If null, then the system locale is assumed.

## Method Details

### setBirtResourcePath

public static void setBirtResourcePath(String resourcePath)
Sets resource path.

Parameters:
  `resourcePath` - the resource path to set. It must be an absolute path based on file system and must present a dictory.

### getBirtResourcePath

public static String getBirtResourcePath()
Gets resource path. `setBirtResourcePath(String)`

Returns:
  the resource path set in the session

### activate

public void activate()
Activates this session within a thread. Used in the web environment to associate this session with a message thread or that the client user startup a new thread. Required to allow the thread to access localized messages.

### openModule

public ModuleHandle openModule(String fileName, InputStream is) throws DesignFileException
Opens a module regardless of the module type(library or report design). design.

Parameters:
  `fileName` - name of the file to open.
  `is` - stream to read the design
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openModule

public ModuleHandle openModule(String fileName, InputStream is, ModuleOption options) throws DesignFileException
Opens a module regardless of the module type(library or report design). design.

Parameters:
  `fileName` - name of the file to open.
  `is` - stream to read the design
  `options` - the options set for this module
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openModule

public ModuleHandle openModule(String fileName) throws DesignFileException
Opens a module regardless of the module type(library or report design). design.

Parameters:
  `fileName` - name of the file to open.
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openModule

public ModuleHandle openModule(String fileName, ModuleOption options) throws DesignFileException
Opens a module regardless of the module type(library or report design). design.

Parameters:
  `fileName` - name of the file to open.
  `options` - the options set for this module
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openDesign

public ReportDesignHandle openDesign(String fileName) throws DesignFileException
Opens a design with the given the file name.

Parameters:
  `fileName` - name of the file to open. It may contain the relative/absolute path information. This name must include the file name with the filename extension.
Returns:
  handle to the report design
Throws:
  `DesignFileException` - if the file is not found, or the file contains fatal errors.

### openDesign

public ReportDesignHandle openDesign(String fileName, ModuleOption options) throws DesignFileException
Opens a design with the given the file name.

Parameters:
  `fileName` - name of the file to open. It may contain the relative/absolute path information. This name must include the file name with the filename extension.
  `options` - the options set for this module
Returns:
  handle to the report design
Throws:
  `DesignFileException` - if the file is not found, or the file contains fatal errors.

### openDesign

public ReportDesignHandle openDesign(String fileName, InputStream is) throws DesignFileException
Opens a design given a stream to the design and the the file name of the design.

Parameters:
  `fileName` - name of the file to open. If `null`, the design will be treated as a new design, and will be saved to a different file. If not `null`, it may contain the relative/absolute path information. This name must include the file name with the filename extension.
  `is` - stream to read the design
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openDesign

public ReportDesignHandle openDesign(String fileName, InputStream is, ModuleOption options) throws DesignFileException
Opens a design given a stream to the design and the the file name of the design.

Parameters:
  `fileName` - name of the file to open. If `null`, the design will be treated as a new design, and will be saved to a different file. If not `null`, it may contain the relative/absolute path information. This name must include the file name with the filename extension.
  `is` - stream to read the design
  `options` - options set for this module
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openDesign

public ReportDesignHandle openDesign(URL systemId, InputStream is) throws DesignFileException
Opens a design given a stream to the design and the the file name of the design. *

Parameters:
  `systemId` - the uri where to find the relative sources for the report. This url is treated as an absolute directory.
  `is` - the input stream to read the design
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openDesign

public ReportDesignHandle openDesign(URL systemId, InputStream is, ModuleOption options) throws DesignFileException
Opens a design given a stream to the design and the the file name of the design. *

Parameters:
  `systemId` - the uri where to find the relative sources for the report. This url is treated as an absolute directory.
  `is` - the input stream to read the design
  `options` - the options set for this module
Returns:
  handle to the report design
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openLibrary

public LibraryHandle openLibrary(String fileName) throws DesignFileException
Opens a library with the given the file name.

Parameters:
  `fileName` - name of the file to open. This name must include the file name with the filename extension.
Returns:
  handle to the library
Throws:
  `DesignFileException` - if the file is not found, or the file contains fatal errors.

### openLibrary

public LibraryHandle openLibrary(String fileName, ModuleOption options) throws DesignFileException
Opens a library with the given the file name.

Parameters:
  `fileName` - name of the file to open. This name must include the file name with the filename extension.
  `options` - the options set for this module
Returns:
  handle to the library
Throws:
  `DesignFileException` - if the file is not found, or the file contains fatal errors.

### openLibrary

public LibraryHandle openLibrary(String fileName, InputStream is) throws DesignFileException
Opens a library given a stream to the design and the the file name of the design.

Parameters:
  `fileName` - name of the file to open. If `null`, the library will be treated as a new library, and will be saved to a different file. If not `null`, it may contain the relative/absolute path information. This name must include the file name with the filename extension.
  `is` - the stream to read the library
Returns:
  the library instance
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openLibrary

public LibraryHandle openLibrary(String fileName, InputStream is, ModuleOption options) throws DesignFileException
Opens a library given a stream to the design and the the file name of the design.

Parameters:
  `fileName` - name of the file to open. If `null`, the library will be treated as a new library, and will be saved to a different file. If not `null`, it may contain the relative/absolute path information. This name must include the file name with the filename extension.
  `is` - the stream to read the library
  `options` - the options set for this module
Returns:
  the library instance
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### openLibrary

public LibraryHandle openLibrary(URL systemId, InputStream is) throws DesignFileException
Opens a library with the given the file name.

Parameters:
  `systemId` - the uri where to find the relative sources for the library. This url is treated as an absolute directory.
  `is` - the input stream
Returns:
  handle to the library
Throws:
  `DesignFileException` - if the file is not found, or the file contains fatal errors.

### openLibrary

public LibraryHandle openLibrary(URL systemId, InputStream is, ModuleOption options) throws DesignFileException
Opens a library with the given the file name.

Parameters:
  `systemId` - the uri where to find the relative sources for the library. This url is treated as an absolute directory.
  `is` - the input stream
  `options` - the options set for this module
Returns:
  handle to the library
Throws:
  `DesignFileException` - if the file is not found, or the file contains fatal errors.

### createDesign

public ReportDesignHandle createDesign(String fileName)
Creates a new design based on a file name.

Parameters:
  `fileName` - file name.
Returns:
  A handle to the report design.

### createDesign

public ReportDesignHandle createDesign(String fileName, ModuleOption options)
Creates a new design based on the file name and the module options.

Parameters:
  `fileName` -
  `options` -
Returns:
  new report design handle.

### createDesignFromTemplate

public ReportDesignHandle createDesignFromTemplate(String templateDesignName) throws DesignFileException
Creates a new design based on a template file.

Parameters:
  `templateDesignName` - The name of the template for the design.
Returns:
  A handle to the report design.
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### createDesignFromTemplate

public ReportDesignHandle createDesignFromTemplate(String templateDesignName, InputStream is) throws DesignFileException
Creates a new design based a given template file name and input stream.

Parameters:
  `templateDesignName` - The name of the template for the design.
Returns:
  A handle to the report design.
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### createLibraryFromTemplate

public LibraryHandle createLibraryFromTemplate(String templateLibraryName) throws DesignFileException
Creates a new library based on a template file.

Parameters:
  `templateLibraryName` - The name of the template for the library.
Returns:
  A handle to the report library.
Throws:
  `DesignFileException` - If the file is not found, or the file contains fatal errors.

### createDesign

public ReportDesignHandle createDesign()
Creates a new empty design. This new design is not based on a template.

Returns:
  the handle of the new report design.

### createLibrary

public LibraryHandle createLibrary()
Creates a new empty library.

Returns:
  the handle of the new library.

### saveAll

public void saveAll() throws IOException
Saves all designs and librariesthat need a save.

Throws:
  `IOException` - if a save error occurs

### closeAll

public void closeAll(boolean save) throws IOException
Closes all open designs and libraires.

Parameters:
  `save` - `true` if designs are to be saved before closing
Throws:
  `IOException` - if a save error occurs

### setApplicationUnits

public void setApplicationUnits(String units) throws PropertyValueException
Sets the units to be used by the application. These units are independent of those set for the design. The application and design can use the same units, or different units. The application units are those used when getting and setting dimension properties using double (float) values. The possible values are defined in `DesignChoiceConstants` and can be one of:

- `UNITS_IN`
- `UNITS_CM`
- `UNITS_MM`
- `UNITS_PT`
- `UNITS_PC`

Parameters:
  `units` - the units to set for the session -- application
Throws:
  `PropertyValueException` - if `units` is not one of the above
See Also:
  - `DimensionValue`

### getApplicationUnits

public String getApplicationUnits()
Returns the current session (application) units. The return values are defined in `DesignChoiceConstants` and is one of:

- `UNITS_IN`
- `UNITS_CM`
- `UNITS_MM`
- `UNITS_PT`
- `UNITS_PC`

Returns:
  the application units
See Also:
  - `setApplicationUnits(java.lang.String)`

### setColorFormat

public void setColorFormat(int rgbFormat) throws PropertyValueException
Sets the rgb color display preference to be used by the application. If the preference is not set the application will use default CSS_ABSOLUTE_FORMAT like "RGB(255,0,0)" for a rgb color display value. The rgbFormat argument is an integer value that may be the following constants defined in `ColorUtil`:

- `INT_FORMAT`
- `HTML_FORMAT`
- `JAVA_FORMAT`
- `CSS_ABSOLUTE_FORMAT`
- `CSS_RELATIVE_FORMAT`

Parameters:
  `rgbFormat` - the rgb color display preference to set.
Throws:
  `PropertyValueException` - if `rgbFormat` is not one of the above.
See Also:
  - `ColorPropertyType`

### getColorFormat

public int getColorFormat()
Returns the current application rgb color display preference. The return is one of the following constants defined in `ColorUtil`:

- `INT_FORMAT`
- `HTML_FORMAT`
- `JAVA_FORMAT`
- `CSS_ABSOLUTE_FORMAT`
- `CSS_RELATIVE_FORMAT`

Returns:
  application rgb color display preference
See Also:
  - `setColorFormat(int)`

### setDefaultValue

public void setDefaultValue(String propName, Object value) throws PropertyValueException
Sets the specified default value of style property.

Parameters:
  `propName` - style property name
  `value` - default value to set
Throws:
  `PropertyValueException` - if value is invalid.

### getDefaultValue

public Object getDefaultValue(String propName)
Gets the default value of the specified style property.

Parameters:
  `propName` - style property name
Returns:
  The default value of this style property. If the default value is not set, return `null`.

### setResourceLocator

public void setResourceLocator(IResourceLocator locator)
Sets the resource locator for the specified file searching algorithm.

Parameters:
  `locator` - the resource locator to be set.

### getResourceLocator

public IResourceLocator getResourceLocator()
Returns the installed resource locator.

Returns:
  the resource locator.

### getLocale

@Deprecated public Locale getLocale()
Deprecated.
to use ICU4J, replaced by: public ULocale getLocale()
Returns the locale of the current session.

Returns:
  the locale of the current session

### getULocale

public com.ibm.icu.util.ULocale getULocale()
Returns the locale of the current session.

Returns:
  the locale of the current session, the return value is of `ULocale`.

### fireResourceChange

public void fireResourceChange(ResourceChangeEvent ev)
Informs this session some resources is changed. Session will check all opened mudules, all interfered modules will be informed of the changes.

Current, only changes of library is supported.

Parameters:
  `ev` - the resource change event to fire

### addResourceChangeListener

public void addResourceChangeListener(IResourceChangeListener listener)
Adds one resource change listener. The duplicate listener will not be added.

Parameters:
  `listener` - the resource change listener to add

### removeResourceChangeListener

public boolean removeResourceChangeListener(IResourceChangeListener listener)
Removes one resource change listener. If the listener not registered, then the request is silently ignored.

Parameters:
  `listener` - the resource change listener to remove
Returns:
  `true` if `listener` is successfully removed. Otherwise `false`.

### setResourceFolder

public void setResourceFolder(String resourceFolder)
Sets the resource folder for this session.

Parameters:
  `resourceFolder` - the folder to set

### getResourceFolder

public String getResourceFolder()
Gets the resource folder set in this session.

Returns:
  the resource folder set in this session

### getDefaultTOCStyle

public StyleHandle getDefaultTOCStyle(String name)
Gets default TOC Style.Heading 1 -> Heading 10.

Parameters:
  `name` - style name
Returns:
  style handle which is read only.

### getPredefinedFontSizeProvider

public IAbsoluteFontSizeValueProvider getPredefinedFontSizeProvider()
Returns the provider instance which provides the absolute dimension value of predefined font size choice.

- `FONT_SIZE_XX_SMALL`
- `FONT_SIZE_X_SMALL`
- `FONT_SIZE_SMALL`
- `FONT_SIZE_MEDIUM`
- `FONT_SIZE_LARGE`
- `FONT_SIZE_X_LARGE`
- `FONT_SIZE_XX_LARGE`

Returns:
  the instance of `IAbsoluteFontSizeValueProvider`