!!! Overview A [How To] [DirXML Examples] on calling Java from a [DirXML] [Policy] %%information This was done on IDM 3.5 and eDirectory 8.8.1 so somethings may vary for your implementation. %% This is just a simple application to show how to call a java application from Novell's IdM product. Be sure the [DirXML Script namespace definitions|DirXML Script namespace definitions|target='_blank'] are set within the policy where using the Java call. You will also need to place the [Java jar files in the correct location.|IDM Location of jar files|target='_blank'] The idea is to supply a [UUID] as defined in [RFC 4122|http://www.faqs.org/rfcs/rfc4122.html]. The [UUID] will be a string and look similar to: {{{ cd2c0ce6-5d5d-11dc-a188-f53b0a4780f0 }}} !!!The Policy The [Example] policy is [Source code] attached to the bottom of page. The file [uuidGenPolicy.xml|IDM Call Java Example/uuidGenPolicy.xml] contains the policy and the output from dstrace. Shows a [DirXML Example] and [XPATH Example] for working with [{$pagename}]. %%prettify {{{ <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE policy PUBLIC "policy-builder-dtd" "C:\novell\Designer\eclipse\plugins\com.novell.designer.idm.policybuilder_2.0.0.200703152140\DTD\dirxmlscript.dtd"> <policy xmlns:uuid="http://www.novell.com/nxsl/java/com.willeke.uuid.UUIDGen"> <rule> <description>GUID Generate</description> <conditions> <and/> </conditions> <actions> <do-set-local-variable name="mac" scope="policy"> <arg-string> <token-text xml:space="preserve">f5:3b:0a:47:80:f0</token-text> </arg-string> </do-set-local-variable> <do-set-local-variable name="myguid" scope="policy"> <arg-string> <token-xpath expression="uuid:genUUID($mac)"/> </arg-string> </do-set-local-variable> <do-trace-message> <arg-string> <token-text xml:space="preserve">### </token-text> <token-local-variable name="myguid"/> <token-text xml:space="preserve"> ###</token-text> </arg-string> </do-trace-message> </actions> </rule> </policy> }}} /% !!! Java Code As our objective is to set a value within [eDirectory] using [DirXML], we want the application to return a string. Although there are a couple of methods in the java code, we are only interested in the "genUUID" method which returns a string. In the example, we supply a MAC Address as a local variable which could be from a GCV. The value should be a "real" MAC Address of the machine the generator runs on to comply with the RFC. Here is the [Java] [source code] of the application: %%prettify {{{ /** * A wrapper around the Java Uuid Generator (JUG) * See: http://jug.safehaus.org/Home */ package com.willeke.uuid; /** * @author jim@willeke.com */ public class UUIDGen { /** * Just here for fun */ public UUIDGen(String macaddress) { System.out.println(genUUID(macaddress)); } /** * @param mac - * Mac address of Machine * @return - String of UUID */ public static String genUUID(String mac) { return org.safehaus.uuid.UUIDGenerator.getInstance().generateTimeBasedUUID(new org.safehaus.uuid.EthernetAddress(mac)).toString(); } /** * Prints to the system console * * @param macaddress */ public static void printUUID(String macaddress) { System.out.println(genUUID(macaddress)); } /* * Just to test with */ public static void main(String[] args) { printUUID(args[0]); } } }}} /% !! More Information There might be more information for this subject on one of the following: [{ReferringPagesPlugin before='*' after='\n' }] !!!How to make it happen We generated a [single jar file|Novell IDM Call Java Example/UUIDGeneratorForIDM.jar|DirXML Calling Java Example] with both the com.willeke.uuid class and the files from the jug-lgpl-2.0.0.jar file. For those who want to know, we used Eclipse to write the Java code and the [Fat Jar Plugin|http://fjep.sourceforge.net/]. Copy the jar file to the [correct location for Jars for IDM|IDM Location of jar files]. You will have to stop and start the IdM engine for the jar file to be read. Install the policy and watch it work. !!!The Output {{{ 12:17:16 964A5BA0 Drvrs: Generic Null ST:Applying policy: Temp. 12:17:16 964A5BA0 Drvrs: Generic Null ST: Applying to modify #1. 12:17:16 964A5BA0 Drvrs: Generic Null ST: Evaluating selection criteria for rule 'GUID Generate'. 12:17:16 964A5BA0 Drvrs: Generic Null ST: Rule selected. 12:17:16 964A5BA0 Drvrs: Generic Null ST: Applying rule 'GUID Generate'. 12:17:16 964A5BA0 Drvrs: Generic Null ST: Action: do-set-local-variable("mac",scope="policy","f5:3b:0a:47:80:f0"). 12:17:16 964A5BA0 Drvrs: Generic Null ST: arg-string("f5:3b:0a:47:80:f0") 12:17:16 964A5BA0 Drvrs: Generic Null ST: token-text("f5:3b:0a:47:80:f0") 12:17:16 964A5BA0 Drvrs: Generic Null ST: Arg Value: "f5:3b:0a:47:80:f0". 12:17:16 964A5BA0 Drvrs: Generic Null ST: Action: do-set-local-variable("myguid",scope="policy",token-xpath("uuid:genUUID($mac)")). 12:17:16 964A5BA0 Drvrs: Generic Null ST: arg-string(token-xpath("uuid:genUUID($mac)")) 12:17:16 964A5BA0 Drvrs: Generic Null ST: token-xpath("uuid:genUUID($mac)") 12:17:16 964A5BA0 Drvrs: Generic Null ST: Token Value: "cd2c0ce6-5d5d-11dc-a188-f53b0a4780f0". 12:17:16 964A5BA0 Drvrs: Generic Null ST: Arg Value: "cd2c0ce6-5d5d-11dc-a188-f53b0a4780f0". 12:17:16 964A5BA0 Drvrs: Generic Null ST: Action: do-trace-message("### "+token-local-variable("myguid")+" ###"). 12:17:16 964A5BA0 Drvrs: Generic Null ST: arg-string("### "+token-local-variable("myguid")+" ###") 12:17:16 964A5BA0 Drvrs: Generic Null ST: token-text("### ") 12:17:16 964A5BA0 Drvrs: Generic Null ST: token-local-variable("myguid") 12:17:16 964A5BA0 Drvrs: Generic Null ST: Token Value: "cd2c0ce6-5d5d-11dc-a188-f53b0a4780f0". 12:17:16 964A5BA0 Drvrs: Generic Null ST: token-text(" ###") 12:17:16 964A5BA0 Drvrs: Generic Null ST: Arg Value: "### cd2c0ce6-5d5d-11dc-a188-f53b0a4780f0 ###". 12:17:16 964A5BA0 Drvrs: Generic Null ST:### cd2c0ce6-5d5d-11dc-a188-f53b0a4780f0 ### }}} !! More Information There might be more information for this subject on one of the following: [{ReferringPagesPlugin before='*' after='\n' }]