The Java API. Pitney Bowes 9.0 API Guide
Below you will find brief information for Spectrum Technology Platform 9.0 API Guide. This guide contains comprehensive information about using the Spectrum Technology Platform API. The API enables you to interact with the Spectrum Technology Platform services by creating a connection to the Server, constructing messages that contain your input data, and processing the responses received from the Server.
Advertisement
Advertisement
The Java API
In this section:
•
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
•
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134
•
Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139
•
Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140
•
DataTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146
•
DataRow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151
5
Introduction
Introduction
A Java class is a blueprint or prototype that defines the variables and methods common to all objects of a certain type. A Java class also defines the implementation of a particular kind of object. It is with these classes that you can create Java applications. In general, Java objects are created from Java classes.
A Java object is a collection of related variables and methods written in the Java language utilizing the
Java Virtual Machine (JVM). The data associated with a class or object is stored in variables. The behavior associated with a class or object is implemented with methods. Methods are similar to the functions or procedures in procedural languages such as C.
Java software objects interact and communicate with each other using messages. Additional information that the receiving object may need to perform its task is passed by parameters.
For more information on Java technology, go to
www.oracle.com/java
.
Constants
The Java API uses two sets of constants. The first set is for the Server component, described in the table below.
Table 33: Constants for the Server Component
Constant Name
Server.HOST
Server.PORT
Server.ACCOUNT_ID
Server.ACCOUNT_PASSWORD
Server.CONNECTION_TIMEOUT
Server.CONNECTION_TYPE
Server.PROXY_HOST
Server.PROXY_PORT
Server.PROXY_USER
Server.PROXY_PASSWORD
Description Example
String for server host name. Default is
"localhost".
65.89.200.89
String for server port. Default is "8080".
10119
String for server account ID. Default is null.
user1
String for server account password.
Default is null.
user1
String for server connection timeout, in millisecond. Default is "10000".
50000
HTTP String for server connection type.
Currently only support HTTP, HTTPS, or SOCKET. Default is "HTTP".
String for proxy server host name.
Default is null.
192.168.1.77
8080 String for proxy server port. Default is null.
String for proxy server account ID.
Default is null.
String for proxy server account password. Default is null.
user1 user1
The second set of constants is for the Message component.
132 Spectrum
™
Technology Platform 9.0
Chapter 5: The Java API
Table 34: Constants for the Message Component
Constant Name Description/Default Example
Message.CONTEXT_ACCOUNT_ID
Message.CONTEXT_ACCOUNT_PASSWORD
Message.CONTEXT_SERVICE_NAME
String for message context account ID.
String for message context account password.
String for message context service name.
user1 user1 echoservice
Error Messages
The Java API uses the following error messages:
• Error Messages for Connection
• "Connection type not supported."
• "Client timeout"
• Error Messages for creating DataTable:
• "Blank column name"
• "Duplicated column name"
• "Index is out of bounds"
• Error Messages for Message Packaging Exception
• "Cannot pack null Message"
• "Input Message is null"
• "Unable to connect to Server:"
• "Failed to get Service"
• "Unknown serialization type:"
• "Unknown encoding type:"
• "Gateway is not connected" (for SOCKET)
Example Application
The sample code shown below illustrates how to use the Java API.
try
{
// Create Server
Server server = new Server();
// Set server connection properties server.setConnectionProperty(Server.HOST, "localhost"); server.setConnectionProperty(Server.PORT, "10119"); server.setConnectionProperty(Server.CONNECTION_TYPE, "SOCKET"); server.setConnectionProperty(Server.ACCOUNT_ID, "guest"); server.setConnectionProperty(Server.ACCOUNT_PASSWORD, "");
// Connect to server server.connect();
// Get Service From Server
Service service = server.getService("ValidateAddress");
// Create Input Message
API Guide 133
Server
Message request = new Message();
// Fill DataTable in the input message
DataTable dataTable = request.getDataTable();
DataRow row1 = dataTable.newRow(); row1.set("AddressLine1", "4200 Parliament Place"); row1.set("City", "Lanham"); row1.set("StateProvince", "Maryland"); dataTable.addRow(row1);
DataRow row2 = dataTable.newRow(); row2.set("AddressLine1", "100 Congress"); row2.set("City", "Austin"); row2.set("StateProvince", "Texas"); dataTable.addRow(row2);
// Set"option" Properties to the Input
Message request.putOption("OutputCasing", "M"); request.putOption("OutputRecordType", "A");
// Process Input Message, return output Message
Message reply = service.process(request);
// Disconnect from server server.disconnect();
// Get the result from the response message
DataTable returnDataTable = reply.getDataTable();
String[] columnNames = returnDataTable.getColumnNames();
Iterator iter = returnDataTable.iterator(); while (iter.hasNext())
{
DataRow row = (DataRow) iter.next(); for (int col = 0; col & lt; returnDataTable.getColumnCount(); col++)
{
String value = row.get(columnNames[col]);
System.out.println(value);
}
}
} catch (Exception e)
{
System.out.println("Error Occurred, " + e.getMessage());
}
Server
The Server class is used to connect to the server, disconnect from the server, and get the service from the server. The following table summarizes the functions each method performs in the Server class.
Table 35: Server Methods Summary
134
Method
connect disconnect setConnectionProperty getService
Function
Connects to the server.
Disconnects from the server.
Sets the configuration items for the connection to the server.
Gets the service from the server.
Spectrum
™
Technology Platform 9.0
Chapter 5: The Java API
Note:
See the Component Reference section of this guide for a list of services that may be available to you.
Connect
Reads the properties to determine which gateway connection to be used and makes a connection to the server. You can connect via HTTP, HTTPS, or SOCKET. However, HTTP and HTTPS do not actually connect to the server until a GetService or Process method is invoked. With a SOCKET connection type, the Connect method is fully functional.
Syntax
public void connect()
Parameters
None.
Results
Throws:
• ConfigurationException: When invalid configuration causes the inability to connect to the server. For example, an unknown protocol would cause a ConfigurationException. There is no value in attempting to retry connect() when this error occurs.
• ConnectionException: When unable to connect to the server. It might be possible to reconnect, depending on the underlying cause of the exception.
• MessageProcessingException: When an error occurs on the server that is not due to Configuration or
Connection issues.
Example
Server server = new Server(); server.setConnectionProperty(Server.HOST, "localhost"); server.setConnectionProperty(Server.PORT, "10119"); server.setConnectionProperty(Server.CONNECTION_TYPE, "SOCKET"); server.setConnectionProperty(Server.ACCOUNT_ID, "guest"); server.setConnectionProperty(Server.ACCOUNT_PASSWORD, ""); try
{
//Connect to server server.connect();
} catch (ConfgurationException e)
{
// indicate an error with configuration
} catch (ConnectionException e)
{
// handle connection issue (retry, report error, etc.)
} catch (MessageProcessingException e)
{
}
// report error
API Guide 135
Server
Connection Pooling
Connection pooling for the SOCKET connection type is available to the Java client. This section describes how to enable and disable connection pooling. By default connection pooling is disabled.
To enable connection pooling:
Server server = new Server();
Server.setConnectionProperty(Connection.SOCKET_POOL, "true");
To disable connection pooling:
Server server = new Server();
Server.setConnectionProperty(Connection.SOCKET_POOL, "false");
When connection pooling is enabled, the connect() method borrows a connection from the pool, and the disconnect() method returns the connection back to the pool. When pooling, the client must call disconnect() each time to return the connection to the pool.
Each thread should contain its own server, as shown in the following example:
{
...
Server server = new Server(); server.setConnectionProperty(Server.HOST, "localhost"); server.setConnectionProperty(Server.PORT, "10119"); server.setConnectionProperty(Server.CONNECTION_TYPE, "SOCKET"); server.setConnectionProperty(Server.ACCOUNT_ID, "yourID"); server.setConnectionProperty(Server.ACCOUNT_PASSWORD, "pwd"); server.setConnectionProperty(Connection.SOCKET_POOL, "true"); server.setConnectionProperty(Connection.SOCKET_POOL_MAX_ACTIVE, "20"); server.setConnectionProperty(Connection.SOCKET_POOL_MIN_IDLE, "10"); server.setConnectionProperty(Connection.SOCKET_POOL_MAX_TOTAL, "25");
} server.connect();
...
service = server.getService(serviceName); reply = service.process(requestMessage); server.disconnect();
...
The following table lists the constants you can use for connection pooling.
Table 36: Constants for Connection Pooling
Constant Name
SOCKET_POOL
136
SOCKET_POOL_MAX_ACTIVE*
SOCKET_POOL_MAX_IDLE*
SOCKET_POOL_MAX_TOTAL*
Description
Whether or not to use connection pooling if using the SOCKET connection type.
Valid values are true or false. Default is false.
Maximum number of active socket connections that may be borrowed from the pool. Default is -1, which indicates no maximum.
Maximum number of idle socket connections remaining in the pool.
Default is -1, which indicates no maximum.
Maximum total number of pooled socket connections (both active and idle).
Spectrum
™
Technology Platform 9.0
Chapter 5: The Java API
Constant Name Description
SOCKET_POOL_MAX_WAIT*
SOCKET_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS*
SOCKET_POOL_MIN_IDLE*
SOCKET_POOL_NUM_TESTS_PER_EVICTION_RUN*
Default is -1, which indicates no maximum.
Maximum amount of time (in milliseconds) to wait before throwing an exception when the pool is exhausted and the "when exhausted" action is
WHEN_EXHAUSTED_BLOCK. Default is -1, which indicates no maximum.
Minimum amount of time a connection may sit idle in the pool before it is eligible for eviction. Default is 1800000 (30 minutes).
Minimum number of connections allowed in the pool before the evictor thread (if active) creates new connections. Default is 0.
Sets the number of idle connections to examine during each run of the evictor thread (if active). Default is -1, which indicates all idle connections are examined.
SOCKET_POOL_TEST_ON_BORROW*
SOCKET_POOL_TEST_ON_RETURN*
SOCKET_POOL_TEST_WHILE_IDLE* Whether connections will be validated by the idle connection eviction thread.
Default is false.
SOCKET_POOL_TIME_BETWEEN_EVICTION_RUNS_MILLIS* Sets the number of milliseconds to sleep between runs of the idle connection evictor thread. When set to zero or a negative number, no idle connection evictor thread will be run. Default is
300000 (5 minutes).
SOCKET_POOL_WHEN_EXHAUSTED_ACTION*
Whether connections will be validated before being borrowed from the pool.
Default is true.
Whether connections will be validated before being returned to the pool. Default is false.
SOCKET_POOL_WHEN_EXHAUSTED_BLOCK*
Sets the "when exhausted action" to take when attempting to borrow a connection and none are available. Default is
SOCKET_POOL_WHEN_EXHA
USTED_BLOCK.
A "when exhausted action" type indicating that when attempting to borrow a connection and none are available, the caller should block until a new object is available, or the maximum wait time has elapsed.
API Guide 137
Server
Constant Name
SOCKET_POOL_WHEN_EXHAUSTED_FAIL*
SOCKET_POOL_WHEN_EXHAUSTED_GROW*
Description
A "when exhausted action" type indicating that when attempting to borrow a connection and none are available, the caller should fail, throwing a
ConnectionException.
A "when exhausted action" type indicating that when attempting to borrow a connection and none are available, a new connection will be made anyway.
* Applicable only if using the SOCKET connection type and connection pooling is enabled.
Disconnect
Disconnects from the server.
Syntax
public void disconnect()
Parameters
None.
Results
Client is disconnected from the server.
Example
...
//Disconnect from server server.disconnect();
SetConnectionProperty
Establishes the server connection configuration properties, such as host name and length of timeout.
Syntax
public void setConnectionProperty(String name, String value)
Parameters
• Name — the name of the connection property, such as HOST
• Value — the value for the name of the connection property, such as "www.myhost.com"
Results
None.
138 Spectrum
™
Technology Platform 9.0
Exceptions
• ERROR-INVALID-COLUMN_NAME — an empty of null column name.
• ERROR_INVALID_VALUE — A null value.
Example
Server server = new Server(); server.setConnectionProperty(Server.HOST, "localhost"); server.setConnectionProperty(Server.PORT, "8080");
//Connect to server server.connect();
Chapter 5: The Java API
GetService
Gets the service from the server.
Note:
See the Component Reference section of this guide for a list of services that may be available to you.
Syntax
public Service getService(String serviceName)
Parameters
• Name - the name of the service
Results
Returns the specific service.
Exceptions
throws ServiceNotFoundException, ServiceCreationException
Example
Service service = server.getService("ValidateAddress");
Service
The Service class is used to process the message (i.e., send the message to the server and receive a response from the server).
This class has just one method: Process. The Process method is detailed below.
Process
Process the input message and returns the response message.
API Guide 139
Message
Syntax
public Message process (Message message)
Parameters
• Input message
Results
Returns the response message.
Exceptions
• TimeoutException: When invalid configuration causes the inability to connect to the server. For example, an unknown protocol would cause a ConfigurationException. There is no value in attempting to retry connect() when this error occurs.
• ConnectionException: When unable to connect to the server. It might be possible to reconnect, depending on the underlying cause of the exception.
• MessageProcessingException: When an error occurs on the server that is not due to Configuration or
Connection issues.
Example
try
{
}
//Process Input Message, return output Message
Message response = service.process(message); catch (ConnectionException e)
{
// handle connection issue (retry, report error, etc.)
} catch (TimeoutException e)
{
// handle timeout issue (retry, report error, etc.)
} catch (MessageProcessingException e)
{
}
// report error
Message
The Message class sends your input data and receives your output data from the service. The properties for Message include context properties, such as account ID, account password, service name, and service method; and option properties, which are the service-specific runtime options.
The following table summarizes the functions each method performs in the Message class.
Table 37: Message Methods Summary
Method
getContext
Function
Gets the value of the context entity identified by name in the context section of the message.
140 Spectrum
™
Technology Platform 9.0
Method
getContext putContext putContext setContext getOption getOptions putOption putOptions setOptions getError getDataTable
Chapter 5: The Java API
Function
Gets the map that contains all of the context entries.
Sets the value of the context entity identified by name in the context session of the message. If there is an existing value present for the entity identified by the name, it is replaced.
Add the new context properties to the current context properties.
Overwrites the current context properties with the new context properties.
Gets the value of the option entity identified by name in the option section of the message.
Gets the map that contains all of the option entries.
Sets the value of the option entity identified by name in the option section of the message. If there is an existing value present for the entity identified by the name, it is replaced.
Add the new option properties to the current option properties.
Overwrites the current option properties with the new option properties.
Gets the error from the error message.
Gets the specified data table from the message.
GetContext
Gets the value by the name in the "context" properties. Context properties include the following constants: account ID, account password, service name, service key, and request ID.
Syntax
public String getContext(String name)
Parameters
• Name - the name whose associated value is to be returned
Results
Returns the value associated with the name in the context properties. If the name does not exist, the method returns NULL.
Example
String value = message.getContext(Message.CONTEXT_ACCOUNT_ID);
API Guide 141
Message
GetContext
Gets the map that contains all of the context entries.
Syntax
public Map getContext()
Parameters
• None
Results
Returns the map that contains all of the context entries.
Example
Map context = message.getContext();
PutContext
Sets the value for the given name in the context properties. If there is an existing value present for the entity identified by the name, it is replaced. Context properties include the following constants: accountID, account password, service name, service key, and request ID.
Syntax
public void putContext(String name, String value)
Parameters
• Name - the name with which the specified value is to be associated
• Value - the value to be associated with the specified name
Results
None.
Example
message.putContext(Message.CONTEXT_ACCOUNT_ID, "user1");
PutContext
Adds the new context properties to the current context properties.
Syntax
public void putContext(Map map)
142 Spectrum
™
Technology Platform 9.0
Parameters
• The new context hashtable to be added to the current context hashtable
Results
None.
Example
Map context = new HashMap();
...
message.putContext(context);
Chapter 5: The Java API
SetContext
Overwrites the current context properties with the new context properties.
Syntax
public void setContext(Map map)
Parameters
• The new context map that will replace the current context map.
Results
None.
Example
Map context = new Map ();
...
message.setContext(context);
GetOption
Gets the value by the name in the option properties. Option properties are the service-specific run-time options.
Syntax
public String getOption(String name)
Parameters
• Name - the name whose associated value is to be returned.
Results
Returns the value for the name in the option properties in the message OR NULL if the name does not exist.
API Guide 143
Message
Example
String value = message.getOption("OutputCasing");
GetOptions
Gets the map that contains all of the option entries.
Syntax
public Map getOptions();
Parameters
• None
Results
Returns the map that contains all of the option entries.
Example
Map options = message.getOptions();
PutOption
Sets the value for given name in the option properties. If there is an existing value present for the entity identified by the name, it is replaced. Option properties are the service specific run-time options.
Syntax
public void setOption(String name, String value)
Parameters
• Name - name with which the specified value is to be associated
• Value - value to be associated with the specified name
Results
None.
Example
message.setOption("OutputCasing", "M");
PutOptions
Adds the new option properties to the current option properties.
Syntax
public void putOptions(Map map)
144 Spectrum
™
Technology Platform 9.0
Parameters
• The new option map to be added to the current option properties
Example
Map options = new HashMap();
...
message.putOptions(options);
SetOptions
Overwrites the current option properties with the new option properties.
Syntax
public void setOptions(Map map)
Parameters
• The new option map to replace the current option map
Results
None.
Example
Map options = new HashMap();
...
message.setOptions(options);
GetError
Gets the error message from the message.
Syntax
public String getError()
Parameters
• None
Results
Returns the error message in the message.
Example
String error = message.getError();
Chapter 5: The Java API
API Guide 145
DataTable
GetDataTable
Gets the data table in this message.
Syntax
public DataTable getDataTable()
Parameters
None.
Results
None.
Example
DataTable dataTable = message.getDataTable();
DataTable
DataTable contains the records for your input and output data. Using the methods associated with this class, you define the column names for your output and add records to the DataTable.
The following table summarizes the functions each method performs in the DataTable class.
Table 38: DataTable Methods Summary
Method
addColumn getColumnNames getColumnIndex getColumnCount clear iterator addRow newRow getRowCount merge
Function
Adds a new column to the DataTable.
Gets all the column names.
Gets the corresponding column index.
Gets the number of columns.
Clears all the data in the DataTable.
An iterator that contains all the rows in the
DataTable.
Adds a DataRow to the DataTable.
Creates a new DataRow in the DataTable.
Gets the number of DataRows in the DataTable.
Merge the given DataTable and the current
DataTable.
These methods are discussed in more detail in the following sections.
146 Spectrum
™
Technology Platform 9.0
AddColumn
Adds the new column to the DataTable.
Syntax
public int addColumn(String columnName)
Parameters
• columnName
Results
Returns the index of the column
Example
DataTable dataTable = message.getDataTable(); int columnIndex = dataTable.addColumn("AddressLine1"); columnIndex = dataTable.addColumn("City")
GetColumnNames
Gets all the column names.
Syntax
public String[] getColumnNames()
Parameters
• None
Results
Returns the string array of column names.
Example
String[] columnNames = dataTable.getColumnNames();
GetColumnIndex
Gets the corresponding column index.
Syntax
public int getColumnIndex(String columnName)
Parameters
• Column name
API Guide
Chapter 5: The Java API
147
DataTable
Results
Returns the corresponding column index.
Example
int columnIndex = dataTable.getColumnIndex("City");
GetColumnCount
Gets the number of columns in the DataTable.
Syntax
public int getColumnCount()
Parameters
• None
Results
Returns the number of columns.
Example
int columnCount = dataTable.getColumnCount();
Clear
Clears the data in the DataTable.
Syntax
public void clear()
Parameters
• None
Results
None.
Example
dataTable.clear();
Iterator
An iterator that contains all DataRows in the DataTable.
148 Spectrum
™
Technology Platform 9.0
Syntax
public Iterator iterator()
Parameters
• None
Results
Returns an iterator that contains all DataRows in the DataTable.
Example
Iterator iter = dataTable.iterator(); while (iter.hasNext())
{
DataRow row = (DataRow)iter.next();
}
AddRow
Adds a row to the DataTable.
Syntax
public void addRow(DataRow row)
Parameters
• Row - DataRow to be added to the DataTable
Results
None.
Example
DataTable dataTable = message.getDataTable();
DataRow row = dataTable.newRow(); row.set("AddressLine1","4203 Greenridge"); dataTable.addRow(row);
NewRow
Creates a new DataRow to the DataTable.
Syntax
public DataRow newRow()
Parameters
• None
API Guide
Chapter 5: The Java API
149
DataTable
Results
Returns the newly created DataRow
Example
DataRow row = dataTable.newRow(); row.set("AddressLine1", "4203 Greenridge"); dataTable.addRow(row);
GetRowCount
Gets the number of DataRows in the DataTable.
Syntax
public int getRowCount()
Parameters
• None
Results
Returns the number of DataRows in the DataTable.
Example
int rowCount = dataTable.getRowCount();
Merge
Merges the given DataTable and the current DataTable.
Syntax
public void merge(DataTable other)
Parameters
• The other DataTable to be merged with the current DataTable
Results
None.
Example
DataTable otherDataTable = new DataTable(); dataTable.merge(otherDataTable);
150 Spectrum
™
Technology Platform 9.0
Chapter 5: The Java API
DataRow
DataRow contains the individual records for your input and output data. Using the methods associated with this class, you define the column names for your output and add records to the DataTable.
The following table summarizes the functions each method performs in the DataRow class.
Table 39: DataRow Methods Summary
Method
getColumnNames getColumnIndex get get merge set set addChild getChildren listChildNames setChildren
Function
Gets all the column names.
Gets the corresponding column index.
Gets the value from the field array by the column index in this DataRow.
Gets the value from the field array by the column name in this dataTow.
Merges the given DataRow and the current
DataRow.
Sets the value for the corresponding column name for the DataRow. If the value for the name exists, the old value is replaced.
Sets the value for the corresponding column index for the DataRow. If the value for the name exists, the old value is replaced.
Adds a new DataRow to the named parent/child relationship. If the named relationship exists, the supplied DataRow will be appended to the existing
DataRow Collection, otherwise a new Collection will be created with the supplied DataRow as its only element.
Retrieves the child rows from a named relationship.
Retrieves all of the names of the named parent/child relationships
Sets the rows of a supplied, named parent/child relationship. If rows previously existed under this name, they will be returned to the caller.
These methods are discussed in more detail in the following sections.
GetColumnNames
Gets all the column names.
API Guide 151
DataRow
Syntax
public String[] getColumnNames()
Parameters
• None
Results
Returns the string array of column names.
Example
String[] columnNames = dataRow.getColumnNames();
GetColumnIndex
Gets the corresponding column index.
Syntax
public int getColumnIndex(String columnName)
Parameters
• Name - column name
Results
Returns the corresponding column index.
Example
int columnIndex = dataRow.getColumnIndex("City");
Get
Gets the value from the field array by the column index in this DataRow.
Syntax
public String get(int index)
Parameters
• Index with which the specified value is to be associated
Results
Returns the value for the column index in this DataRow.
152 Spectrum
™
Technology Platform 9.0
Chapter 5: The Java API
Example
String value = dataRow.get(1);
Get
Gets the value from the field array by the column name in this DataRow.
Syntax
public String get(String columnName)
Parameters
• Name - name with which the specified value is to be associated
Results
Returns the value for the column name in this DataRow; returns empty string if the column name does not exist.
Example
String value = dataRow.get("City");
Merge
Merges the given DataRow and the current DataRow.
Syntax
public void merge(DataRow other)
Parameters
• The other DataRow to be merged with the current DataRow
Results
None.
Example
DataRow otherDataRow = new DataRow(); dataRow.merge(otherDataRow);
Set
Sets the value for the corresponding column for the DataRow. If the value for the name exists, the old value is replaced.
API Guide 153
DataRow
Syntax
public void set(int Index, String value)
Parameters
• The column index with which the specified value is to be associated
• Value to be associated with the specified name
Results
None.
Exceptions
• IndexOutOfBounds — the column index is invalid
Example
DataRow row = dataTable.newRow(); row.set(0,"4203 Greenridge"); row.set(1,"Austin"); row.set(2,"Texas") dataTable.addRow(row);
AddChild
Adds a new DataRow to the named parent/child relationship. If the named relationship exists, the supplied
DataRow will be appended to the existing DataRow collection. Otherwise, a new collection will be created with the supplied DataRow as its only element.
Syntax
public void addChild(String childName, DataRow childDataRow)
Parameters
• Name - the name of the parent/child relationship (e.g., "Flood Plain Data," "References, " "Used By," etc.)
• Value - the DataRow to be added to the relationship.
Results
None.
Example
DataRow childDataRow = new DataRow(); childDataRow.set("Address", "100 Congress");
...
DataRow dataRow = new DataRow();
...
dataRow.addChild("child1", childDataRow);
154 Spectrum
™
Technology Platform 9.0
Chapter 5: The Java API
GetChildren
Retrieves the child rows from a named relationship.
Syntax
public List getChildren(String childName)
Parameters
• The name of the parent/child relationship, e.g. "Flood Plain Data", "References", "Used By", etc.
Results
Returns the child rows from the named relationship.
Example
List childRows = row.getChildren("child1");
ListChildNames
Retrieves all of the names of the named parent/child relationships.
Syntax
public Set listChildNames()
Parameters
None.
Results
Returns the set of the names of the named parent/child relationships.
Example
Set childNames = row.listChildNames();
SetChildren
Sets the rows of a supplied, named parent/child relationship. If rows previously existed under this name, they will be returned to the caller.
Syntax
public List setChildren(String childName, List DataRows)
Parameters
None.
API Guide 155
DataRow
Results
Returns the set of the names of the named parent/child relationships.
Example
List rows = dataRow.getChildren("child1"); parentRow.setChildren("child2", rows);
Set
Sets the value for the corresponding column for the DataRow. If the value for the name exists, the old value is replaced.
Syntax
public void set(int Index, String value)
Parameters
• The column index with which the specified value is to be associated
• Value to be associated with the specified name
Results
None.
Exceptions
• IndexOutOfBounds — the column index is invalid
Example
DataRow row = dataTable.newRow(); row.set(0,"4203 Greenridge"); row.set(1,"Austin"); row.set(2,"Texas") dataTable.addRow(row);
156 Spectrum
™
Technology Platform 9.0
Download
Advertisement
Key features
Provides access to Spectrum Technology Platform services
Supports various programming languages
Allows customization of service options
Offers comprehensive documentation and examples
Enables seamless integration with existing applications
Frequently asked questions
The Spectrum Technology Platform API supports C, C++, COM, Java, and .NET.
To connect to the Spectrum Technology Platform server, you need to create a Server instance, set connection properties, and then call the Connect method.
To send a request, you need to create a Message object, specify the service and method, set the input data, and then call the Process method of the Service object.
The API provides error information through the GetError method of the Message object. You can use this information to diagnose and handle errors in your application.