To compile the sample adapter, the following steps must be executed:
1. Create a work folder, let's say c:\work and inside create the following structure:
c:\work\com\oracle\events\
2. Create a java file in c:\work\com\oracle\events\ named tcGenerateRandomPassword.java
3. Copy the source code provided in this document to the java file.
4. In c:\work create a file named compile.bat with the following contents:
set OIM_LIBS=c:\oim91\xellerate\lib set CLASSPATH=%OIM_LIBS%\xlLogger.jar;%OIM_LIBS%\xlDataObjects.jar;%OIM_LIBS%\xlVO.jar;%OIM_LIBS%\xlUtils.jar javac -classpath %CLASSPATH% com\oracle\events\tcGenerateRandomPassword.java jar cf randomPwdGen.jar *
Modify OIM_LIBS to point to the correct lib folder on the machine.
5. Run compile.bat and check for any compilation errors.
6. At this point a JAR file named randomPwdGen.jar will be created in c:\work folder.
To add the new created event handler to OIM server, perform the following steps:
1. Copy the file randomPwdGen.jar from c:\work to OIM_HOME\xellerate\EventHandlers
2. Open Design Console and navigate to:
Development Tools -> Business Rule Definition -> Event Handler Manager
3. Create a new Event Handler and specify:
Event Handler Name: tcGenerateRandomPassword
Package: com.oracle.events
Pre-Insert: Checked
4. Save the event handler
5. Navigate to Development Tools -> Business Rule Definition -> Data Object Manager
6. Search for "Users" and add the event handler to the Pre-Insert list.7. Save.
package com.oracle.events;
import java.util.Random;
import com.thortech.xl.dataobj.tcDataSet;
import com.thortech.xl.util.logging.LoggerMessages; import com.thortech.xl.util.logging.LoggerModules;
import com.thortech.util.logging.Logger;
public class tcGenerateRandomPassword extends com.thortech.xl.client.events.tcBaseEvent
{
private static Logger logger = Logger.getLogger(LoggerModules.XL_JAVA_CLIENT);
public tcGenerateRandomPassword()
{
setEventName("Generating a random password for a User.");
}
protected void implementation() throws Exception
{
if (getDataObject().isDeleting())
{
return;
}
if (getDataObject().isUpdating())
{
return;
}
String randomPassword = getRandomPassword();
getDataObject().setString("usr_password",randomPassword);
return;
}
private String getRandomPassword()
{
StringBuffer buffer = new StringBuffer();
Random random = new Random();
for ( int i = 0; i < 10; i++ ) {
buffer.append(((char)
('a'+random.nextInt(20))));
}
return buffer.toString();
}
}