com.supermap.data

Class Workspace

  • java.lang.Object
    • com.supermap.data.Workspace


  • public class Workspace
    extends java.lang.Object
    The Workspace.

    A workspace is where users work with their data. It is primarily used to manage and organize data, including opening, closing, creating, and saving workspaces (SXW,SMW,SXWU,SMWU,DEFAULT). Workspace is an important concept in SuperMap, and it stores all the datasources and the map organic relationships of a project (The same business process). Workspace manages the datasources, maps via the Datasources (Maps), Maps object (Maps).

    The Datasources collection (Datasources) of the workspace only stores the connection information and locations of the datasources, and the data of datasources are stored in a relational database or UDB file. The Maps object (Datasources}) in a Workspace object stores some configuration information, such as the number of the layers in a map, the name of the dataset referenced by the layer, the bounds of the map, the style of the background.

    In the current version, multiple workspaces are allowed in an application and each workspace manages a set of datasources and maps etc. Note that interoperable operations are not allowed for different workspaces.

    Note:If the instances of two classes, Workspaceand MapControl, have built the connection, when closing the objects, you should follow the following orders.

    1. Close Map object;
      1. Close MapControl object;
      2. Close the Workspace object.
    Example:
    The following example demonstrates how to open a workspace, get the datasource and the dataset, get description of the dataset and how to save the workspace.
     public void workspaceTest(){
            // Opens the workspace and gets the dataset named "World", and then query its description information
            Workspace workspace = new Workspace();
            WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
            workspaceConnectionInfo.setType(WorkspaceType.SMWU);
            String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
            String file = rootPath + "/SampleData/World/World.smwu";
            workspaceConnectionInfo.setServer(file);
            workspace.open(workspaceConnectionInfo);
            Datasource datasource = workspace.getDatasources().get(0);
            DatasetVector dataset = (DatasetVector) datasource.getDatasets().get( "World");
            System.out.println("The description information of dataset is: " + dataset.getDescription());
    
            // Saves the workspace
            try {
                            workspace.save();
                    } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    }
    
            // Releases resources
            dataset.close();
            workspaceConnectionInfo.dispose();
            workspace.close();
            workspace.dispose();
        }
     
    • Constructor Summary

      Constructors 
      Constructor and Description
      Workspace()
      Constructs a new Workspace object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void close()
      Closes the workspace.
      void dispose()
      Disposes the resources occupied by the object.
      java.lang.String getCaption()
      Sets the display name of workspace, so that the user can identify this Workspace,and the caption of a Workspace can be modified.
      WorkspaceConnectionInfo getConnectionInfo()
      Returns the connection information of the workspace.
      Datasources getDatasources()
      Returns the Datasources object.
      java.lang.String getDescription()
      Returns the description about this Workspace object that added by the user.
      Maps getMaps()
      Returns the Maps object of this Workspace object.
      Resources getResources()
      Returns the Resources object in the workspace.
      Scenes getScenes()
      Gets the Scene collection in the workspace.
      boolean isModified()
      Whether the contents returned to the workspace are changed.
      boolean open(WorkspaceConnectionInfo connectionInfo)
      Opens a existing workspace files.
      boolean save()
      Save workspace.
      void setCaption(java.lang.String caption)
      Sets the display name of workspace, so that the user can identify this Workspace,and the caption of a Workspace can be modified.
      void setDescription(java.lang.String description)
      Sets the description about this Workspace object that added by the user.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Workspace

        public Workspace()
        Constructs a new Workspace object.
    • Method Detail

      • close

        public void close()
        Closes the workspace. The maps in this workspace are all closed or disconnected before closing the workspace.
      • dispose

        public void dispose()
        Disposes the resources occupied by the object. After calling this method, this object will not be usable.

        Calls the dispose() method after operate the dataset, or the changes can't be saves.

      • getConnectionInfo

        public WorkspaceConnectionInfo getConnectionInfo()
        Returns the connection information of the workspace.
        Returns:
        The connection information of the workspace.
        See Also:
        WorkspaceConnectionInfo
        Default:
        The default value is {Name="",Type=Default,Version=UGC60,Server="",Database="",Driver="",User="",Password=""}.
      • getCaption

        public java.lang.String getCaption()
        Sets the display name of workspace, so that the user can identify this Workspace,and the caption of a Workspace can be modified.
        Returns:
        The display name of workspace.
        Default:
        The default value is "UntitledWorkspace".
      • setCaption

        public void setCaption(java.lang.String caption)
        Sets the display name of workspace, so that the user can identify this Workspace,and the caption of a Workspace can be modified.
        Parameters:
        caption - The display name of workspace.
      • getDatasources

        public Datasources getDatasources()
        Returns the Datasources object.

        The Datasources object stores the logic information of the datasources in this Workspace, such as the connection information of datasource data, storage location of datasources, but it does not store the real data of datasources. The data of datasources are stored in relational databases or UDB files. The Datasources object in a Workspace is mainly used to manage the datasource in this Workspace, including opening, creating, closing operation etc.

        Returns:
        The Datasources object.
        Default:
        The default value is a initialized {} object.
      • getMaps

        public Maps getMaps()
        Returns the Maps object of this Workspace object. Actually, the Maps object stores all the maps in this Workspace, but you can only access the names of the maps via this object. If you want to open a map in this workspace, you should get the name of this object of the Map class in SuperMap.Data.Mapping namespace via the object, and then perform the opening operation. Note that the {} Map should first connect the workspace, and then the map can be opened.
        Returns:
        The Maps object of this Workspace object.
        Example:
        Please see the sample of Map.
        Default:
        The default value is a initialized {} object.
      • isModified

        public boolean isModified()
        Whether the contents returned to the workspace are changed. If changed, return true, otherwise, false. The Workspace object is responsible for managing datasources, maps, layouts, scenes and resources, if any of these is modified, this property will return True. When closing a application, you can use this property to determine whether this workspace has been modified, and if it returns true, you can save the modified.
        Returns:
        If changed, return true; otherwise, false.
        Default:
        The default value is false, that is, the cotents didn't change.
      • getDescription

        public java.lang.String getDescription()
        Returns the description about this Workspace object that added by the user.
        Returns:
        The description about this Workspace object that added by the user.
        Default:
        The default is a null string.
      • setDescription

        public void setDescription(java.lang.String description)
        Sets the description about this Workspace object that added by the user.
        Parameters:
        description - The description about this Workspace object that added by the user.
      • open

        public boolean open(WorkspaceConnectionInfo connectionInfo)
        Opens a existing workspace files. If successful, returns True.

        If a Datasource object is set to be auto connected, the data of this Datasource object will be connected, but if you want to access data in a dataset in this datasource, you need to open the dataset after the datasource is connected; otherwise, you can not know what and how many datasets this datasource contains and the data is not available.

        If some of the datasources in the workspace are not opened successfully when opening the workspace, this method will still return True. In this situation, you can get the information of which datasources are opened and which are not by viewing the log.

        Parameters:
        connectionInfo - is used to open the workspace connection information.
        Returns:
        A value indicates whether this Workspace is opened. If it is opened successfully, returns True; otherwise returns false.
      • save

        public boolean save()
                     throws java.lang.Exception
        Save workspace. By setting the connection information of the workspace, it can save the new workpace, or save as workspace to save the current workspace The interface is needed to capture the exceptions.
        Returns:
        True if the Workspace is saved successfully; otherwise False.
        Throws:
        java.lang.Exception -

        It will occur exceptions for the following conditions: 1. The current workspace object has been released; 2. The workspace is a new one, and the saving directory is not specified; 3. The saving directory doesn't exist, it will be created automatically, but failed; 4. The saving directory is specified, but the workspace file extension is invalid, and the workspace type is not specified;

        Example:
        The following codes demenstrate how to save a workspace
         public void testSaveWorkSpace{
                MapControl mapControl = new MapControl(context);
                Map map = mapControl.getMap();
                Workspace workspace = new Workspace();
                map.setWorkspace(workspace);    
                        
                ......
                          
               WorkspaceConnectionInfo info = workspace.getConnectionInfo();
               info.setType(WorkspaceType.SMWU);
               String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
               info.setServer(rootPath + "/SuperMap/data/MyWorld.smwu");
               try {
                                workspace.save();
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
            }
         
      • getResources

        public Resources getResources()
        Returns the Resources object in the workspace. The Resources object is used to manage the resources such as the line style library, the fill style library and the symbol library.
        Returns:
        The resource library objects of the workspace.
        Default:
        The default value is an empty Resources object.
      • getScenes

        public Scenes getScenes()
        Gets the Scene collection in the workspace.
        Returns:
        The scene set object in the workspace, the default is Scenes object.