Programming Guides › Connector Programming Guide › Writing Scripts › How You Pass Data to and from Scripts
How You Pass Data to and from Scripts
You can execute either of the following formats of script (as reflected in the opbindings.xsd XML schema definition):
- You can define one or more global scripts at the head of the opbindings XML file.
As a result, the individual bindings cause the execution of individual functions within these scripts. When this style is used, the exact same arguments passed to the attribute-style processor's method are passed to the corresponding target scripting function. For example, a scripting function targeting an ADD operation are passed an ObjectInfo instance as its first argument, and an Attributes object as its second argument. This is because these are the arguments to com.ca.jcs.processor.OpProcessor.doAdd(ObjectInfo, Attributes). Use this approach for all but the simplest scripts, as it allows reuse of utility functions between multiple scripts.
Note: For more information about the arguments passed to other methods, see the JavaDocs in the CA IdentityMinder bookshelf for the com.ca.jcs.processor.OpProcessor interface. For an example of a script function targeting a MODIFY operation, see com.ca.jcs.processor.OpProcessor.doModify(ObjectInfo, ModificationItem[]) in the CA IAM CS Javadoc in the CA IdentityMinder bookshelf.
- Alternatively, each opbinding can be tied to a complete self-contained script (instead of to a function contained with a script). In this case, each of the arguments to the attribute-style processor's method are bound to script variable names using the exact arguments names and Java structures as defined in the OpProcessor's JavaDoc. For example, a script targeted an ADD operation doAdd(ObjectInfo objInfo, Attributes attrs) are called with two scripting variables defined:
- objInfo is bound to a Java object of type ObjectInfo
- attrs are bound to a Java object of type Attributes.
For both formats, the following additional scripting variables are also bound:
- The zeroth element of special scripting variable statusArray (of type String[]) can be assigned a string value to signify an error condition, which are then passed back to the client. If strictCompletion is true, the LDAP operation to fail. In JavaScript, it is better to throw an exception than to use this variable, as there is better control. For example, an LDAP error code can be assigned to the exception. The SDKSCRIPT connector has a number of examples where LDAP exceptions are thrown, for example, where a LdapServiceUnavailableException is thrown in sdkscript_opbindings.xml.
- The variable connector is bound to the parent connector which owns the attribute-style processor being invoked. Through this variable, the script can access the connector's parent connector type (and hence the metadata settings) and the CA IAM CS framework. For example, a script looking up the value of an attribute stored on the connector to modulate its behavior accordingly.
- For the opbindings targeting the MODIFY operation, the script variable currAttrs can be used to access the current state of the target object (in connector-speak) where required. For example, a script can verify that a single-valued attribute currently has no values before adding a new value for it.
Note: For more information about query-related scripting variables and other notes on queries, see LOOKUP and SEARCH query operations through Script opbindings Considerations.
Only script opbindings that have their executedDirectly Boolean field set to false require a connector to have a script-style processor. As such, opbindings produce connector-specific text (for example, SQL for the JDBC connector) which only the connector knows how to execute. The CA IAM CS framework invokes all other opbindings without any special support being required from the target connector.
Copyright © 2013 CA.
All rights reserved.
|
|