How to initialize a GeoDataServer object


Summary
A GeoDataServer is an object that references a geodatabase. It is a coarse-grained object through which you can browse, query, extract data, and use geodatabase replication. GeoDataServer objects can be initialized locally or accessed remotely from an ArcGIS Server connection. Because it can be used in so many environments, application developers are advised to investigate meeting their requirements using this object.

This article shows the different ways of initializing a GeoDataServer object.

In this topic


Initializing a GeoDataServer object for a local geodatabase

[Java]
// For example, path = "C:\arcgis\ArcTutor\DatabaseServers\buildings.mdb"
// Or, path = "C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb"
static IGeoDataServer initGeoDataServerFromFile(String path)throws Exception{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer = new GeoDataServer();
    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
    // Initialize the GeoDataServer and return it.
    geoDataServerInit.initFromFile(path);
    return geoDataServer;
}

Initializing a GeoDataServer object for an ArcSDE geodatabase

[Java]
// For example, connectionString = "SERVER=bobmk;INSTANCE=5151;VERSION=sde.DEFAULT;USER=gdb;PASSWORD=gdb"
static IGeoDataServer initGeoDataServerFromConnectionString(String connectionString)
    throws Exception{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer = new GeoDataServer();
    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
    // Initialize the GeoDataServer and return it.
    geoDataServerInit.initFromConnectionString(connectionString);
    return geoDataServer;
}

Initializing a GeoDataServer object for an IWorkspace

[Java]
static IGeoDataServer initGeoDataServerFromWorkspace(IWorkspace workspace)throws
    Exception{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer = new GeoDataServer();
    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
    // Initialize the GeoDataServer and return it.
    geoDataServerInit.initWithWorkspace(workspace);
    return geoDataServer;
}

Initializing a GeoDataServer object for an ArcGIS Server GeoData Service

[Java]
// For example, url = @"http://jerome/arcgis/services"
// serviceName = "FileGDB_GDS"
static IGeoDataServer initGeoDataServerFromInternetServer(String url, String
    serviceName)throws Exception{
    // Create a property set for connection properties.
    IPropertySet propertySet = new PropertySet();
    propertySet.setProperty("URL", url);
    // Connect to the server and get an enumerator for its objects.
    IAGSServerConnectionFactory agsServerConnectionFactory = new
        AGSServerConnectionFactory();
    IAGSServerConnection agsServerConnection = agsServerConnectionFactory.open
        (propertySet, 0);
    IAGSEnumServerObjectName enumServerObjectName =
        agsServerConnection.getServerObjectNames();
    enumServerObjectName.reset();
    // Iterate through the objects to locate the geodata service.
    IAGSServerObjectName serverObjectName = null;
    IGeoDataServer geoDataServer = null;
    while ((serverObjectName = enumServerObjectName.next()) != null){
        if (serverObjectName.getName().equals(serviceName)){
            IName name = (IName)serverObjectName;
            geoDataServer = (IGeoDataServer)name.open();
            break;
        }
    }
    return geoDataServer;
}
[Java]
// For example, machineName = "jerome"
// serviceName = "FileGDB_GDS"
static IGeoDataServer initGeoDataServerFromNetworkServer(String machineName, String
    serviceName)throws Exception{
    // Create a property set for connection properties.
    IPropertySet propertySet = new PropertySet();
    propertySet.setProperty("Machine", machineName);
    // Connect to the server and get an enumerator for its objects.
    IAGSServerConnectionFactory agsServerConnectionFactory = new
        AGSServerConnectionFactory();
    IAGSServerConnection agsServerConnection = agsServerConnectionFactory.open
        (propertySet, 0);
    IAGSEnumServerObjectName enumServerObjectName =
        agsServerConnection.getServerObjectNames();
    enumServerObjectName.reset();
    // Iterate through the objects to locate the geodata service.
    IAGSServerObjectName serverObjectName = null;
    IGeoDataServer geoDataServer = null;
    while ((serverObjectName = enumServerObjectName.next()) != null){
        if (serverObjectName.getName().equals(serviceName)){
            IName name = (IName)serverObjectName;
            geoDataServer = (IGeoDataServer)name.open();
            break;
        }
    }
    return geoDataServer;
}






Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced