|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.di.connector.Connector com.ibm.di.connector.ScriptConnector
public class ScriptConnector
The Script Connector enables you to write your own Connector in JavaScript. A Script Connector must implement a few functions to operate. If you plan to use it for iteration purposes only (for example, reading, not searching or updating), you can operate with two functions only. If you plan to use it as a fully qualified Connector, you must implement all functions. The functions do not use parameters. Passing data between the hosting Connector and the script is enabled by using predefined objects. One of these predefined objects is the result object, which is used to communicate status information. Upon entry in either function, the status field is set to normal, which causes the hosting Connector to continue calls. Signaling end-of-input or error is done by setting the status and message fields in this object. Two other script objects are defined upon function entry, the entry object and the search object.
Field Summary |
---|
Fields inherited from class com.ibm.di.connector.Connector |
---|
ALL_MODES, myLog, PROPERTY_MESSAGE, PROPERTY_READER, PROPERTY_WRITER |
Constructor Summary | |
---|---|
ScriptConnector()
Class constructor |
Method Summary | |||||||||
---|---|---|---|---|---|---|---|---|---|
void |
deleteEntry(Entry entry,
SearchCriteria search)
Deletes an existing entry. The search criteria specifies which entry to modify. Some connectors may silently ignore the search criteria. For example, the LDAP connector will use the distinguished name ($dn) from the entry parameter (if it exists) rather than expanding the search criteria and search for the entry. Each connector's inner semantics governs whether the search parameter is used or not. |
||||||||
Entry |
findEntry(SearchCriteria search)
Finds an existing entry. The search criteria specifies which entry to locate Here is an example of how to find all people with names starting with 'J' which are from IBM organization in US. Example: var ctor = input.getConnector(); var crit = new com.ibm.di.SearchCriteria("$dn", com.ibm.di.SearchCriteria.SUBSTRING, "c=US,o=IBM"); crit.addCriteria("name", com.ibm.di.SearchCriteria.INITIAL_STRING, "J"); crit.addCriteria("objectclass", com.ibm.di.SearchCriteria.SUBSTRING, "person"); var res = ctor.findEntry(crit); if (res != null) { main.logmsg("Found entry:"); main.dumpEntry(res); } else { if( getFindEntryCount()> 1 ){ main.logmsg("Found these entries:"); while ( (entry = ctor.getNextFindEntry()) != null ) { main.dumpEntry(entry); } } else { main.logmsg("Entry not found!"); } } |
||||||||
Entry |
getNextEntry()
Returns the next Entry from the connector. The entry is populated with attributes and values from the next entry in the input set. Example: var ctor = input.getConnector(); var entry = ctor.getNextEntry(); for (; entry != null; entry = ctor.getNextEntry()) { main.logmsg("Read entry..."); main.dumpEntry(entry); } |
||||||||
java.lang.String |
getVersion()
Return version information |
||||||||
void |
initialize(java.lang.Object obj)
Initialize the connector. The connector may be passed a parameter of any kind by the user. It is up to the connector to determine whether this object can be used or not. The parameter is typically provided by a user script. When an AssemblyLine initializes it's Connectors, they are passed a ConnectorMode object. |
||||||||
void |
modEntry(Entry entry,
SearchCriteria search)
Modifies an existing entry. The new entry data is given by the entry parameter and the search criteria specifies which entry to modify. |
||||||||
void |
modEntry(Entry entry,
SearchCriteria search,
Entry old)
Modifies an existing entry. The new entry data is given by the entry parameter and the search criteria specifies which entry to modify. |
||||||||
void |
putEntry(Entry entry)
Adds a new entry to the data source Example: var ctor = write.getConnector(); for (i = 0; i < 10; i++) { var entry = system.newEntry(); entry.setAttribute("linenumber", i); entry.setAttribute("line", i + " line of text..."); main.logmsg("Writes entry to output..."); main.dumpEntry(entry); ctor.putEntry(entry); } |
||||||||
Entry |
queryReply(Entry entry)
Performs a query/reply operations. |
||||||||
java.lang.Object |
querySchema(java.lang.Object source)
This function translates to whatever means a connector has to discover schema for a connection. The connector may implement this, in which case a Vector of Entry objects is returned for each column/attribute it discovered. For a database connector this would typically be column names and their attributes. Each Entry in the Vector returned should contain the following attributes:
|
||||||||
void |
selectEntries()
Prepare the Connector for sequential read. If necessary, create a result set to be used for getNextEntry(). When the Connector is used as an Iterator in an AssemblyLine, this method will be called. Default is an empty method. |
||||||||
void |
terminate()
Terminate the connector. This function closes all connection and releases all resources used by the connector. This function also calls the parser's closeParser() method if a parser is active. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.ibm.di.connector.ConnectorInterface |
---|
getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getMaxDuplicateEntries, getName, getNextClient, getNextFindEntry, getParam, getPushbackEntry, getRawConnectorConfiguration, isDeltaSupported, isExceptionFatal, isIOException, pushback, queryOperations, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, setCurrent, setLog, setMaxDuplicateEntries, setName, setParam, setRSInterface, terminateServer |
Constructor Detail |
---|
public ScriptConnector()
Method Detail |
---|
public void initialize(java.lang.Object obj) throws java.lang.Exception
initialize
in interface ConnectorInterface
initialize
in class Connector
obj
- User provided parameter
java.lang.Exception
- if the initialization of this connector fails.public void selectEntries() throws java.lang.Exception
selectEntries
in interface ConnectorInterface
selectEntries
in class Connector
java.lang.Exception
- if an error occurs.public Entry getNextEntry() throws java.lang.Exception
Example:
var ctor = input.getConnector(); var entry = ctor.getNextEntry(); for (; entry != null; entry = ctor.getNextEntry()) { main.logmsg("Read entry..."); main.dumpEntry(entry); }
getNextEntry
in interface ConnectorInterface
getNextEntry
in class Connector
java.lang.Exception
- if an error occurs.ConnectorInterface.selectEntries()
public void modEntry(Entry entry, SearchCriteria search) throws java.lang.Exception
modEntry
in interface ConnectorInterface
modEntry
in class Connector
entry
- The entry datasearch
- The search criteria used to locate the entry to be modified
java.lang.Exception
- if an error occurs.public void modEntry(Entry entry, SearchCriteria search, Entry old) throws java.lang.Exception
modEntry
in interface ConnectorInterface
modEntry
in class Connector
entry
- The entry datasearch
- The search criteria used to locate the entry to be modifiedold
- The old entry found by the search criteria
java.lang.Exception
- if an error occurs.public void deleteEntry(Entry entry, SearchCriteria search) throws java.lang.Exception
deleteEntry
in interface ConnectorInterface
deleteEntry
in class Connector
entry
- The entry datasearch
- The search criteria used to locate the entry to be deleted
java.lang.Exception
- if an error occurs.public Entry findEntry(SearchCriteria search) throws java.lang.Exception
Here is an example of how to find all people with names starting with 'J' which are from IBM organization in US.
Example:
var ctor = input.getConnector(); var crit = new com.ibm.di.SearchCriteria("$dn", com.ibm.di.SearchCriteria.SUBSTRING, "c=US,o=IBM"); crit.addCriteria("name", com.ibm.di.SearchCriteria.INITIAL_STRING, "J"); crit.addCriteria("objectclass", com.ibm.di.SearchCriteria.SUBSTRING, "person"); var res = ctor.findEntry(crit); if (res != null) { main.logmsg("Found entry:"); main.dumpEntry(res); } else { if( getFindEntryCount()> 1 ){ main.logmsg("Found these entries:"); while ( (entry = ctor.getNextFindEntry()) != null ) { main.dumpEntry(entry); } } else { main.logmsg("Entry not found!"); } }
findEntry
in interface ConnectorInterface
findEntry
in class Connector
search
- The search criteria used to locate the entry to be modified
java.lang.Exception
- if an error occurs.public void putEntry(Entry entry) throws java.lang.Exception
Example:
var ctor = write.getConnector(); for (i = 0; i < 10; i++) { var entry = system.newEntry(); entry.setAttribute("linenumber", i); entry.setAttribute("line", i + " line of text..."); main.logmsg("Writes entry to output..."); main.dumpEntry(entry); ctor.putEntry(entry); }
putEntry
in interface ConnectorInterface
putEntry
in class Connector
entry
- The entry data to add
java.lang.Exception
- if an error occurs.public Entry queryReply(Entry entry) throws java.lang.Exception
queryReply
in interface ConnectorInterface
queryReply
in class Connector
entry
- The data used in outgoing call
java.lang.Exception
- if an error occurs.public void terminate() throws java.lang.Exception
terminate
in interface ConnectorInterface
terminate
in class Connector
java.lang.Exception
- if an error occurs.public java.lang.Object querySchema(java.lang.Object source) throws java.lang.Exception
Each Entry in the Vector returned should contain the following attributes:
Name | Value |
---|---|
name | The name of the column/attribute/field .... |
syntax | The syntax or expected value type |
size | If specified this will give the user a hint as to how long the field may be |
querySchema
in interface ConnectorInterface
querySchema
in class Connector
source
- The object on which to discover schema. This may be an Entry
or a string value
java.lang.Exception
- if an error while retrieving the schema occurs.Entry
,
Vector
public java.lang.String getVersion()
getVersion
in interface VersionInfoInterface
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |