Package com.ibm.di.connector
Class ScriptConnector
- java.lang.Object
-
- com.ibm.di.connector.Connector
-
- com.ibm.di.connector.ScriptConnector
-
- All Implemented Interfaces:
ConnectorInterface,VersionInfoInterface
public class ScriptConnector extends Connector implements ConnectorInterface
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
Constructors Constructor Description ScriptConnector()Class constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeleteEntry(Entry entry, SearchCriteria search)Deletes an existing entry.EntryfindEntry(SearchCriteria search)Finds an existing entry.EntrygetNextEntry()Returns the next Entry from the connector.java.lang.StringgetVersion()Return version informationvoidinitialize(java.lang.Object obj)Initialize the connector.voidmodEntry(Entry entry, SearchCriteria search)Modifies an existing entry.voidmodEntry(Entry entry, SearchCriteria search, Entry old)Modifies an existing entry.voidputEntry(Entry entry)Adds a new entry to the data sourceEntryqueryReply(Entry entry)Performs a query/reply operations.java.lang.ObjectquerySchema(java.lang.Object source)This function translates to whatever means a connector has to discover schema for a connection.voidselectEntries()Prepare the Connector for sequential read.voidterminate()Terminate the connector.-
Methods inherited from class com.ibm.di.connector.Connector
addFindEntry, allModes, clearFindEntries, debug, debugMode, extractExceptionInformation, findEntry, getBoolean, getClassInstance, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getLog, getMaxDuplicateEntries, getModes, getModes, getName, getNextClient, getNextFindEntry, getParam, getParser, getProperty, getPushbackEntry, getRawConnectorConfiguration, getRSInterface, getUI, hasConfigValue, hasParser, initParser, isDeltaSupported, isExceptionFatal, isIOException, logError, logmsg, pushback, queryOperations, queryTables, reconnect, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, setCurrent, setDebugMode, setLog, setMaxDuplicateEntries, setModes, setModes, setName, setParam, setParser, setProperty, setRSInterface, terminateServer
-
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
-
-
-
-
Method Detail
-
initialize
public void initialize(java.lang.Object obj) throws java.lang.ExceptionInitialize 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.- Specified by:
initializein interfaceConnectorInterface- Overrides:
initializein classConnector- Parameters:
obj- User provided parameter- Throws:
java.lang.Exception- if the initialization of this connector fails.
-
selectEntries
public void selectEntries() throws java.lang.ExceptionPrepare 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.- Specified by:
selectEntriesin interfaceConnectorInterface- Overrides:
selectEntriesin classConnector- Throws:
java.lang.Exception- if an error occurs.
-
getNextEntry
public Entry getNextEntry() throws java.lang.Exception
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); }- Specified by:
getNextEntryin interfaceConnectorInterface- Overrides:
getNextEntryin classConnector- Returns:
- - the next Entry, or null if no more data
- Throws:
java.lang.Exception- if an error occurs.- See Also:
ConnectorInterface.selectEntries()
-
modEntry
public void modEntry(Entry entry, SearchCriteria search) throws java.lang.Exception
Modifies an existing entry. The new entry data is given by the entry parameter and the search criteria specifies which entry to modify.- Specified by:
modEntryin interfaceConnectorInterface- Overrides:
modEntryin classConnector- Parameters:
entry- The entry datasearch- The search criteria used to locate the entry to be modified- Throws:
java.lang.Exception- if an error occurs.
-
modEntry
public void modEntry(Entry entry, SearchCriteria search, Entry old) throws java.lang.Exception
Modifies an existing entry. The new entry data is given by the entry parameter and the search criteria specifies which entry to modify.- Specified by:
modEntryin interfaceConnectorInterface- Overrides:
modEntryin classConnector- Parameters:
entry- The entry datasearch- The search criteria used to locate the entry to be modifiedold- The old entry found by the search criteria- Throws:
java.lang.Exception- if an error occurs.
-
deleteEntry
public void deleteEntry(Entry entry, SearchCriteria search) throws java.lang.Exception
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.- Specified by:
deleteEntryin interfaceConnectorInterface- Overrides:
deleteEntryin classConnector- Parameters:
entry- The entry datasearch- The search criteria used to locate the entry to be deleted- Throws:
java.lang.Exception- if an error occurs.
-
findEntry
public Entry findEntry(SearchCriteria search) throws java.lang.Exception
Finds an existing entry. The search criteria specifies which entry to locateHere 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!"); } }- Specified by:
findEntryin interfaceConnectorInterface- Overrides:
findEntryin classConnector- Parameters:
search- The search criteria used to locate the entry to be modified- Returns:
- The entry found, or null if no or multiple entries found
- Throws:
java.lang.Exception- if an error occurs.
-
putEntry
public void putEntry(Entry entry) throws java.lang.Exception
Adds a new entry to the data sourceExample:
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); }- Specified by:
putEntryin interfaceConnectorInterface- Overrides:
putEntryin classConnector- Parameters:
entry- The entry data to add- Throws:
java.lang.Exception- if an error occurs.
-
queryReply
public Entry queryReply(Entry entry) throws java.lang.Exception
Performs a query/reply operations.- Specified by:
queryReplyin interfaceConnectorInterface- Overrides:
queryReplyin classConnector- Parameters:
entry- The data used in outgoing call- Returns:
- The entry returned by the peer
- Throws:
java.lang.Exception- if an error occurs.
-
terminate
public void terminate() throws java.lang.ExceptionTerminate 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.- Specified by:
terminatein interfaceConnectorInterface- Overrides:
terminatein classConnector- Throws:
java.lang.Exception- if an error occurs.
-
querySchema
public java.lang.Object querySchema(java.lang.Object source) throws java.lang.ExceptionThis 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:
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 - Specified by:
querySchemain interfaceConnectorInterface- Overrides:
querySchemain classConnector- Parameters:
source- The object on which to discover schema. This may be an Entry or a string value- Returns:
- A Vector of com.ibm.di.entry.Entry objects describing each entity
- Throws:
java.lang.Exception- if an error while retrieving the schema occurs.- See Also:
Entry,Vector
-
getVersion
public java.lang.String getVersion()
Return version information- Specified by:
getVersionin interfaceVersionInfoInterface- Returns:
- version info
-
-