@Override
 public void deleteProcessInstance(final SProcessInstance sProcessInstance)
     throws SProcessInstanceModificationException {
   final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
   try {
     final long processDefinitionId = sProcessInstance.getProcessDefinitionId();
     final ClassLoader localClassLoader =
         classLoaderService.getLocalClassLoader("process", processDefinitionId);
     Thread.currentThread().setContextClassLoader(localClassLoader);
     deleteProcessInstanceElements(sProcessInstance);
     final DeleteRecord deleteRecord = new DeleteRecord(sProcessInstance);
     SDeleteEvent deleteEvent = null;
     if (eventService.hasHandlers(PROCESSINSTANCE, EventActionType.DELETED)) {
       deleteEvent =
           (SDeleteEvent)
               BuilderFactory.get(SEventBuilderFactory.class)
                   .createDeleteEvent(PROCESSINSTANCE)
                   .setObject(sProcessInstance)
                   .done();
     }
     recorder.recordDelete(deleteRecord, deleteEvent);
   } catch (final SBonitaException e) {
     throw new SProcessInstanceModificationException(e);
   } finally {
     Thread.currentThread().setContextClassLoader(contextClassLoader);
   }
 }
 @Override
 public void deleteArchivedProcessInstanceElements(
     final long processInstanceId, final long processDefinitionId)
     throws SProcessInstanceModificationException {
   final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
   try {
     final ClassLoader localClassLoader =
         classLoaderService.getLocalClassLoader("process", processDefinitionId);
     Thread.currentThread().setContextClassLoader(localClassLoader);
     deleteArchivedFlowNodeInstances(processInstanceId);
     dataInstanceService.deleteLocalArchivedDataInstances(
         processInstanceId, DataInstanceContainer.PROCESS_INSTANCE.toString());
     processDocumentService.deleteArchivedDocuments(processInstanceId);
     connectorInstanceService.deleteArchivedConnectorInstances(
         processInstanceId, SConnectorInstance.PROCESS_TYPE);
     transitionService.deleteArchivedTransitionsOfProcessInstance(processInstanceId);
     commentService.deleteArchivedComments(processInstanceId);
     deleteArchivedChidrenProcessInstanceElements(processInstanceId, processDefinitionId);
   } catch (final SBonitaException e) {
     throw new SProcessInstanceModificationException(e);
   } finally {
     Thread.currentThread().setContextClassLoader(contextClassLoader);
   }
 }