IBM FileNet P8, Version 5.2.1            

Updating a CodeModule Object

If you modify an action handler that is contained within a CodeModule object, you must first update the CodeModule object with the new version of the action handler. Then, you must update any Action subclassed objects that reference the updated code module.

The following Java™ and C# examples illustrate the update process for an event handler that has been previously archived in a JAR file,EventHandlers.jar, which is contained in the content element of a CodeModule object. After the handler is modified and rearchived in EventHandlers.jar, the CodeModule object is ready to be updated with the new version of EventHandlers.jar.

First, the content of the new JAR file is retrieved as a ContentTransfer object and stored in a ContentElementList object. Next, the current version of the CodeModule object is checked out, a reservation object is retrieved, and the ContentElements property on the reservation object is set to the ContentElementList object. The reservation object is checked in, becoming the new version of the CodeModule object.

The CodeModule object that is updated is referenced by an EventAction object, and it must be updated to reference the current version of the CodeModule object. As shown in the second part of the examples, the EventAction object's CodeModule property is set to the current version of the CodeModule object.

Java Example

...
// Create a File object for the JAR containing the updated event handler.
File newHandlerVersion = new File("C:\\EclipseWorkspace\\EventHandlers\\EventHandlers.jar");
// non-Windows: File newHandlerVersion = new File("/EclipseWorkspace/EventHandlers/EventHandlers.jar");
           
// Create ContentTransfer object from updated JAR content.
ContentElementList contentList = Factory.ContentTransfer.createList();
ContentTransfer ctNew;
FileInputStream fileIS;
ctNew = Factory.ContentTransfer.createInstance();
fileIS = new FileInputStream(newHandlerVersion.getAbsolutePath());
ctNew.setCaptureSource(fileIS);
ctNew.set_ContentType("application/java-archive");
contentList.add(ctNew);

// Check out current version of CodeModule object.
CodeModule cm = Factory.CodeModule.getInstance(os, "/CodeModules/EventHandlers.jar");
cm.checkout(com.filenet.api.constants.ReservationType.EXCLUSIVE, null, null, null);
cm.save(RefreshMode.REFRESH);

// Get reservation object from the checked-out code module.
// This will become the new version of the code module.
CodeModule cmUpdate = (CodeModule) cm.get_Reservation();


// Set the new content on the reservation object.
cmUpdate.set_ContentElements(contentList);

// Check in the new version of the code module.
cmUpdate.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
cmUpdate.save(RefreshMode.REFRESH);
 
/////////////////////////////////////////////
// Get event action to update its CodeModule property.
PropertyFilter pf = new PropertyFilter();
pf.addIncludeType(1, null, null, FilteredPropertyType.SINGLETON_OBJECT, new Integer(1) );
pf.addIncludeProperty(0, null, Boolean.TRUE, PropertyNames.CODE_MODULE, new Integer(1) );
EventAction eventAction = Factory.EventAction.fetchInstance(os, new Id("{94AF1BB3-A4A7-4851-9067-D6F88005C470}"), pf); 

// Set CodeModule property.
eventAction.set_CodeModule(cmUpdate);

eventAction.save(RefreshMode.REFRESH); 
}

C# Example

...
// Create a Stream object for the JAR containing the updated event handler.
Stream fileStream = File.OpenRead(@"C:\\EclipseWorkspace\\EventHandlers\\EventHandlers.jar");

// Create IContentTransfer object from updated JAR content.
IContentElementList contentList = Factory.ContentTransfer.CreateList();
IContentTransfer ctNew;
ctNew = Factory.ContentTransfer.CreateInstance();
ctNew.SetCaptureSource(fileStream);
ctNew.ContentType = "application/java-archive";
contentList.Add(ctNew);

// Check out current version of CodeModule object.
ICodeModule cm = Factory.CodeModule.GetInstance(os, "/CodeModules/EventHandlers.jar");
cm.Checkout(ReservationType.EXCLUSIVE, null, null, null);
cm.Save(RefreshMode.REFRESH);

// Get reservation object from the checked-out code module.
// This will become the new version of the code module.
ICodeModule cmUpdate = (ICodeModule)cm.Reservation;

// Set the new content on the reservation object.
cmUpdate.ContentElements = contentList;

// Check in the new version of the code module.
cmUpdate.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
cmUpdate.Save(RefreshMode.REFRESH);

/////////////////////////////////////////////
// Get event action to update its CodeModule property.
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeType(1, null, null, FilteredPropertyType.SINGLETON_OBJECT, 1);
pf.AddIncludeProperty(0, null, true, PropertyNames.CODE_MODULE, 1);
IEventAction eventAction = Factory.EventAction.FetchInstance(os, new Id("{94AF1BB3-A4A7-4851-9067-D6F88005C470}"), pf);

// Set CodeModule property.
eventAction.CodeModule = cmUpdate;

eventAction.Save(RefreshMode.REFRESH);
}


Last updated: October 2015
server_procedures_codemodule_updating.htm

© Copyright IBM Corporation 2015.