private void deleteDataInstancesIfNecessary(
     final SProcessInstance processInstance, final SProcessDefinition processDefinition)
     throws SDataInstanceException {
   boolean dataPresent = true;
   if (processDefinition != null) {
     dataPresent = processDefinition.getProcessContainer().getDataDefinitions().size() > 0;
   }
   dataInstanceService.deleteLocalDataInstances(
       processInstance.getId(), DataInstanceContainer.PROCESS_INSTANCE.toString(), dataPresent);
 }
 @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);
   }
 }