mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@125605 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,232 +1,232 @@
|
||||
package org.alfresco.repo.workflow;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowException;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.alfresco.util.collections.Filter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
/**
|
||||
* BPM Engine Registry
|
||||
*
|
||||
* Responsible for managing the list of registered BPM Engines for the
|
||||
* following components:
|
||||
*
|
||||
* - Workflow Component
|
||||
* - Task Component
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class BPMEngineRegistry
|
||||
{
|
||||
/** ID seperator used in global Ids */
|
||||
private static final String ID_SEPERATOR = "$";
|
||||
private static final String ID_SEPERATOR_REGEX = "\\$";
|
||||
|
||||
/** Logging support */
|
||||
private static Log logger = LogFactory.getLog("org.alfresco.repo.workflow");
|
||||
|
||||
private WorkflowAdminService workflowAdminService;
|
||||
|
||||
private Map<String, WorkflowComponent> workflowComponents;
|
||||
private Map<String, TaskComponent> taskComponents;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public BPMEngineRegistry()
|
||||
{
|
||||
workflowComponents = new HashMap<String, WorkflowComponent>();
|
||||
taskComponents = new HashMap<String, TaskComponent>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the workflow admin service
|
||||
*
|
||||
* @param workflowAdminService the workflow admin service
|
||||
*/
|
||||
public void setWorkflowAdminService(WorkflowAdminService workflowAdminService)
|
||||
{
|
||||
this.workflowAdminService = workflowAdminService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a BPM Engine Workflow Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @param engine implementing engine
|
||||
*/
|
||||
public void registerWorkflowComponent(String engineId, WorkflowComponent engine)
|
||||
{
|
||||
if (workflowComponents.containsKey(engineId))
|
||||
{
|
||||
throw new WorkflowException("Workflow Component already registered for engine id '" + engineId + "'");
|
||||
}
|
||||
workflowComponents.put(engineId, engine);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Registered Workflow Component '" + engineId + "' (" + engine.getClass() + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all registered Workflow Components
|
||||
*
|
||||
* @return array of engine ids
|
||||
*/
|
||||
public String[] getWorkflowComponents()
|
||||
{
|
||||
return getComponents(workflowComponents.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific BPM Engine Workflow Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @return the Workflow Component
|
||||
*/
|
||||
public WorkflowComponent getWorkflowComponent(String engineId)
|
||||
{
|
||||
if(false == workflowAdminService.isEngineEnabled(engineId))
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Ignoring disabled WorkflowComponent: "+engineId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return workflowComponents.get(engineId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a BPM Engine Task Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @param engine implementing engine
|
||||
*/
|
||||
public void registerTaskComponent(String engineId, TaskComponent engine)
|
||||
{
|
||||
if (taskComponents.containsKey(engineId))
|
||||
{
|
||||
throw new WorkflowException("Task Component already registered for engine id '" + engineId + "'");
|
||||
}
|
||||
taskComponents.put(engineId, engine);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Registered Task Component '" + engineId + "' (" + engine.getClass() + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all registered Task Components
|
||||
*
|
||||
* @return array of engine ids
|
||||
*/
|
||||
public String[] getTaskComponents()
|
||||
{
|
||||
return getComponents(taskComponents.keySet());
|
||||
}
|
||||
|
||||
private String[] getComponents(Set<String> components)
|
||||
{
|
||||
List<String> filtered = CollectionUtils.filter(components, new Filter<String>()
|
||||
{
|
||||
public Boolean apply(String engineId)
|
||||
{
|
||||
return workflowAdminService.isEngineEnabled(engineId);
|
||||
}
|
||||
});
|
||||
return filtered.toArray(new String[filtered.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific BPM Engine Task Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @return the Workflow Component
|
||||
*/
|
||||
public TaskComponent getTaskComponent(String engineId)
|
||||
{
|
||||
if(false == workflowAdminService.isEngineEnabled(engineId))
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Ignoring disabled TaskComponent: "+engineId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return taskComponents.get(engineId);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// BPM Engine Id support
|
||||
//
|
||||
|
||||
/**
|
||||
* Construct a global Id
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @param localId engine local id
|
||||
* @return the global id
|
||||
*/
|
||||
public static String createGlobalId(String engineId, String localId)
|
||||
{
|
||||
return engineId + ID_SEPERATOR + localId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Break apart a global id into its engine and local ids
|
||||
*
|
||||
* @param globalId the global id
|
||||
* @return array containing engine id and global id in that order
|
||||
*/
|
||||
public static String[] getGlobalIdParts(String globalId)
|
||||
{
|
||||
String[] parts = globalId.split(ID_SEPERATOR_REGEX);
|
||||
if (parts.length != 2)
|
||||
{
|
||||
throw new WorkflowException("Invalid Global Id '" + globalId + "'");
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the engine id from a global id
|
||||
*
|
||||
* @param globalId the global id
|
||||
* @return the engine id
|
||||
*/
|
||||
public static String getEngineId(String globalId)
|
||||
{
|
||||
return getGlobalIdParts(globalId)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local id from a global id
|
||||
*
|
||||
* @param globalId the global id
|
||||
* @return the local id
|
||||
*/
|
||||
public static String getLocalId(String globalId)
|
||||
{
|
||||
return getGlobalIdParts(globalId)[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the globalId parameter is a valid global Id
|
||||
* for the given engineId.
|
||||
*
|
||||
* @param globalId String
|
||||
* @param engineId String
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isGlobalId(String globalId, String engineId)
|
||||
{
|
||||
return globalId.startsWith(engineId+ID_SEPERATOR);
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.workflow;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowException;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.alfresco.util.collections.Filter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
/**
|
||||
* BPM Engine Registry
|
||||
*
|
||||
* Responsible for managing the list of registered BPM Engines for the
|
||||
* following components:
|
||||
*
|
||||
* - Workflow Component
|
||||
* - Task Component
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class BPMEngineRegistry
|
||||
{
|
||||
/** ID seperator used in global Ids */
|
||||
private static final String ID_SEPERATOR = "$";
|
||||
private static final String ID_SEPERATOR_REGEX = "\\$";
|
||||
|
||||
/** Logging support */
|
||||
private static Log logger = LogFactory.getLog("org.alfresco.repo.workflow");
|
||||
|
||||
private WorkflowAdminService workflowAdminService;
|
||||
|
||||
private Map<String, WorkflowComponent> workflowComponents;
|
||||
private Map<String, TaskComponent> taskComponents;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public BPMEngineRegistry()
|
||||
{
|
||||
workflowComponents = new HashMap<String, WorkflowComponent>();
|
||||
taskComponents = new HashMap<String, TaskComponent>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the workflow admin service
|
||||
*
|
||||
* @param workflowAdminService the workflow admin service
|
||||
*/
|
||||
public void setWorkflowAdminService(WorkflowAdminService workflowAdminService)
|
||||
{
|
||||
this.workflowAdminService = workflowAdminService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a BPM Engine Workflow Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @param engine implementing engine
|
||||
*/
|
||||
public void registerWorkflowComponent(String engineId, WorkflowComponent engine)
|
||||
{
|
||||
if (workflowComponents.containsKey(engineId))
|
||||
{
|
||||
throw new WorkflowException("Workflow Component already registered for engine id '" + engineId + "'");
|
||||
}
|
||||
workflowComponents.put(engineId, engine);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Registered Workflow Component '" + engineId + "' (" + engine.getClass() + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all registered Workflow Components
|
||||
*
|
||||
* @return array of engine ids
|
||||
*/
|
||||
public String[] getWorkflowComponents()
|
||||
{
|
||||
return getComponents(workflowComponents.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific BPM Engine Workflow Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @return the Workflow Component
|
||||
*/
|
||||
public WorkflowComponent getWorkflowComponent(String engineId)
|
||||
{
|
||||
if(false == workflowAdminService.isEngineEnabled(engineId))
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Ignoring disabled WorkflowComponent: "+engineId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return workflowComponents.get(engineId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a BPM Engine Task Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @param engine implementing engine
|
||||
*/
|
||||
public void registerTaskComponent(String engineId, TaskComponent engine)
|
||||
{
|
||||
if (taskComponents.containsKey(engineId))
|
||||
{
|
||||
throw new WorkflowException("Task Component already registered for engine id '" + engineId + "'");
|
||||
}
|
||||
taskComponents.put(engineId, engine);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Registered Task Component '" + engineId + "' (" + engine.getClass() + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all registered Task Components
|
||||
*
|
||||
* @return array of engine ids
|
||||
*/
|
||||
public String[] getTaskComponents()
|
||||
{
|
||||
return getComponents(taskComponents.keySet());
|
||||
}
|
||||
|
||||
private String[] getComponents(Set<String> components)
|
||||
{
|
||||
List<String> filtered = CollectionUtils.filter(components, new Filter<String>()
|
||||
{
|
||||
public Boolean apply(String engineId)
|
||||
{
|
||||
return workflowAdminService.isEngineEnabled(engineId);
|
||||
}
|
||||
});
|
||||
return filtered.toArray(new String[filtered.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific BPM Engine Task Component
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @return the Workflow Component
|
||||
*/
|
||||
public TaskComponent getTaskComponent(String engineId)
|
||||
{
|
||||
if(false == workflowAdminService.isEngineEnabled(engineId))
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Ignoring disabled TaskComponent: "+engineId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return taskComponents.get(engineId);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// BPM Engine Id support
|
||||
//
|
||||
|
||||
/**
|
||||
* Construct a global Id
|
||||
*
|
||||
* @param engineId engine id
|
||||
* @param localId engine local id
|
||||
* @return the global id
|
||||
*/
|
||||
public static String createGlobalId(String engineId, String localId)
|
||||
{
|
||||
return engineId + ID_SEPERATOR + localId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Break apart a global id into its engine and local ids
|
||||
*
|
||||
* @param globalId the global id
|
||||
* @return array containing engine id and global id in that order
|
||||
*/
|
||||
public static String[] getGlobalIdParts(String globalId)
|
||||
{
|
||||
String[] parts = globalId.split(ID_SEPERATOR_REGEX);
|
||||
if (parts.length != 2)
|
||||
{
|
||||
throw new WorkflowException("Invalid Global Id '" + globalId + "'");
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the engine id from a global id
|
||||
*
|
||||
* @param globalId the global id
|
||||
* @return the engine id
|
||||
*/
|
||||
public static String getEngineId(String globalId)
|
||||
{
|
||||
return getGlobalIdParts(globalId)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local id from a global id
|
||||
*
|
||||
* @param globalId the global id
|
||||
* @return the local id
|
||||
*/
|
||||
public static String getLocalId(String globalId)
|
||||
{
|
||||
return getGlobalIdParts(globalId)[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the globalId parameter is a valid global Id
|
||||
* for the given engineId.
|
||||
*
|
||||
* @param globalId String
|
||||
* @param engineId String
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isGlobalId(String globalId, String engineId)
|
||||
{
|
||||
return globalId.startsWith(engineId+ID_SEPERATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user