Index: sandbox/workflow/branches/609/inc/class.run_activity.inc.php
===================================================================
--- sandbox/workflow/branches/609/inc/class.run_activity.inc.php	(revision 2235)
+++ sandbox/workflow/branches/609/inc/class.run_activity.inc.php	(revision 2249)
@@ -13,5 +13,5 @@
 	require_once(dirname(__FILE__) . SEP . 'class.basecontroller.inc.php' ); /* module controller            */
 	require_once(dirname(__FILE__) . SEP . 'class.basemodel.inc.php'      ); /* module logic                 */
-	require_once(dirname(__FILE__) . SEP . 'class.process_factory.inc.php'); /* module process factory class */
+	//require_once(dirname(__FILE__) . SEP . 'class.process_factory.inc.php'); /* module process factory class */
 	require_once(dirname(__FILE__) . SEP . 'class.utils.security.php'     ); /* sanitizes input data         */
 
@@ -301,5 +301,5 @@
 			$this->process_version	= $this->process->getVersion();
 			$this->activity_name	= $activity->getName();
-			$this->user_name	= Factory::getForeignInstance('phpgwapi', 'phpgw')->accounts->id2name($GLOBALS['user']);
+			$this->user_name   		= $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']);
 			$this->view_activity	= $this->GUI->gui_get_process_view_activity($this->process_id);
 
@@ -440,5 +440,6 @@
 			$security             =& new SecurityUtils();              //input sanitizer class
 			$env['request']       =& $security->process($_REQUEST);    //sanitizes input data from client
-			$env['factory']       =& new ProcessFactory();             //instantiation controller class
+			//$env['factory']       =& new ProcessFactory();             //instantiation controller class
+			$env['factory']       =& Factory::getInstance('ProcessWrapperFactory');  //instantiation controller class
 			$env['natural']		  =& wf_create_object('wf_natural');   //data access object instance for mainframe
 			/* END WORKFLOW MVC SETTINGS */
@@ -473,4 +474,14 @@
 			/* activate the security policy */
 			Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy();
+
+			/**
+			 * XXX
+			 * here we are going to use our new Security static class.
+			 * From now, the factory frontend (static) will forward
+			 * the messages for the process factory instead of Workflow
+			 * factory.
+			 * XXX
+			*/
+			Security::enable();
 
 			/* include the files */
@@ -701,5 +712,6 @@
 			$security             =& new SecurityUtils();              //input sanitizer class
 			$env['request']       =& $security->process($_REQUEST); //sanitizes input data from client
-			$env['factory']       =& new ProcessFactory();			   //instantiation controller class
+			//$env['factory']       =& new ProcessFactory();			   //instantiation controller class
+			$env['factory']       =& Factory::newInstance('ProcessWrapperFactory');  //instantiation controller class
 			$env['natural']		  =& wf_create_object('wf_natural');   //data access object instance for mainframe
 			/* END WORKFLOW MVC SETTINGS */
@@ -713,4 +725,15 @@
 			/* activate the security policy */
 			Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy();
+
+			/**
+			 * XXX
+			 * here we are going to use our new Security static class.
+			 * From now, the factory frontend (static) will forward
+			 * the messages for the process factory instead of Workflow
+			 * factory. Note that this is the same comment as the previous
+			 * function... boooring.. =}
+			 * XXX
+			*/
+			Security::enable();
 
 			$GLOBALS['workflow_env'] = &$env;
Index: sandbox/workflow/branches/609/inc/local/classes/class.wf_role.php
===================================================================
--- sandbox/workflow/branches/609/inc/local/classes/class.wf_role.php	(revision 1048)
+++ sandbox/workflow/branches/609/inc/local/classes/class.wf_role.php	(revision 2249)
@@ -186,5 +186,5 @@
 			$users = array((int) $users);
 		$roleID = $this->roleManager->get_role_id($this->processID, $roleName);
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = Factory::getInstance('WorkflowLDAP');
 		foreach ($users as $user)
 		{
@@ -212,5 +212,5 @@
 		$users = $this->roleManager->list_mapped_users($this->processID, false, array('wf_role_name' => $roleName));
 
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = Factory::getInstance('WorkflowLDAP');
 		$output = array();
 		foreach ($users as $id => $login)
@@ -367,5 +367,5 @@
 
 		/* get the roles */
-		$userGroups = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getUserGroups($userID);
+		$userGroups = Factory::getInstance('WorkflowLDAP')->getUserGroups($userID);
 		$query = 'SELECT DISTINCT role.wf_role_id, role.wf_name, role.wf_description FROM egw_wf_roles role, egw_wf_user_roles user_role WHERE (user_role.wf_role_id = role.wf_role_id) AND (role.wf_p_id = ?) AND (role.wf_role_id = ANY (?))';
 		$query .= ' AND (((user_role.wf_user = ?) AND (user_role.wf_account_type = ?))';
Index: sandbox/workflow/branches/609/inc/local/classes/class.JobBase.php
===================================================================
--- sandbox/workflow/branches/609/inc/local/classes/class.JobBase.php	(revision 1437)
+++ sandbox/workflow/branches/609/inc/local/classes/class.JobBase.php	(revision 2249)
@@ -89,9 +89,9 @@
 	{
 		require_once 'common.inc.php';
-		$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareEnvironment();
+		Factory::getInstance('WorkflowMacro')->prepareEnvironment();
 		$this->jobID = $jobID;
 		$this->processID = $processID;
 		$this->currentDate = $currentDate;
-		$this->jobManager = &$GLOBALS['workflow']['factory']->getInstance('WorkflowJobManager');
+		$this->jobManager = Factory::getInstance('WorkflowJobManager');
 		$this->testMode = $testMode;
 		$this->maximumExecutionTime = $maximumExecutionTime;
@@ -148,10 +148,8 @@
 	final private function prepareEnvironment()
 	{
-		$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareProcessEnvironment($this->processID);
-
-		require_once PHPGW_SERVER_ROOT . '/workflow/inc/class.process_factory.inc.php';
+		Factory::getInstance('WorkflowMacro')->prepareProcessEnvironment($this->processID);
 
 		$this->environment = array();
-		$this->environment['factory']  = &new ProcessFactory();
+		$this->environment['factory']  = &Factory::newInstance('ProcessWrapperFactory');
 	}
 
Index: sandbox/workflow/branches/609/inc/local/classes/class.wf_ldap.php
===================================================================
--- sandbox/workflow/branches/609/inc/local/classes/class.wf_ldap.php	(revision 1067)
+++ sandbox/workflow/branches/609/inc/local/classes/class.wf_ldap.php	(revision 2249)
@@ -41,5 +41,5 @@
 	function wf_ldap()
 	{
-		$tmpLDAP = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$tmpLDAP = Factory::getInstance('WorkflowLDAP');
 		$this->user_context  = $tmpLDAP->getUserContext();
 		$this->group_context = $tmpLDAP->getGroupContext();
Index: sandbox/workflow/branches/609/inc/smarty/wf_plugins/function.wf_redir_menu.php
===================================================================
--- sandbox/workflow/branches/609/inc/smarty/wf_plugins/function.wf_redir_menu.php	(revision 2233)
+++ sandbox/workflow/branches/609/inc/smarty/wf_plugins/function.wf_redir_menu.php	(revision 2249)
@@ -54,9 +54,8 @@
 
 	$user_is_admin = Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']);
-	$phpgw =& Factory::getForeignInstance('phpgwapi','phpgw');
-	if ($user_is_admin || ($phpgw->acl->check('admin_workflow',1,'workflow'))) {
+	if ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_workflow',1,'workflow'))) {
 		$select_tag .= "<option value=\"ad\">Administração</option>";
 	}
-	if ($user_is_admin ||  ($phpgw->acl->check('monitor_workflow',1,'workflow'))) {
+	if ($user_is_admin ||  ($GLOBALS['phpgw']->acl->check('monitor_workflow',1,'workflow'))) {
 		$select_tag .= "<option value=\"mo\">Monitoramento</option>";
 	}
Index: sandbox/workflow/branches/609/inc/class.process_factory.inc.php
===================================================================
--- sandbox/workflow/branches/609/inc/class.process_factory.inc.php	(revision 2235)
+++ 	(revision )
@@ -1,42 +1,0 @@
-<?php
-/**************************************************************************\
-* eGroupWare                                                               *
-* http://www.egroupware.org                                                *
-* --------------------------------------------                             *
-*  This program is free software; you can redistribute it and/or modify it *
-*  under the terms of the GNU General Public License as published by the   *
-*  Free Software Foundation; either version 2 of the License, or (at your  *
-*  option) any later version.                                              *
-\**************************************************************************/
-
-require_once dirname(__FILE__) . SEP . 'class.factory.inc.php';
-
-/**
- * Implementa o design pattern factory para os processos Workflow
- * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
- * @author Carlos Eduardo Nogueira Gonçalves
- * @version 1.0
- * @package Workflow
- * @license http://www.gnu.org/copyleft/gpl.html GPL
- */
-class ProcessFactory extends Factory
-{
-	/**
-	 * Construtor da classe
-	 * @return object
-	 * @access public
-	 */
-	function ProcessFactory()
-	{
-		parent::Factory();
-
-		/* configuration for the workflow processes */
-		$this->classPath = PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'classes';
-		$this->preffix = 'class.';
-		$this->suffix = '.php';
-	}
-
-	function &getForeignInstance(){}
-	function &newForeignInstance(){}
-}
-?>
Index: sandbox/workflow/branches/609/inc/class.factory.inc.php
===================================================================
--- sandbox/workflow/branches/609/inc/class.factory.inc.php	(revision 2235)
+++ 	(revision )
@@ -1,198 +1,0 @@
-<?php
-/**************************************************************************\
-* eGroupWare                                                               *
-* http://www.egroupware.org                                                *
-* --------------------------------------------                             *
-*  This program is free software; you can redistribute it and/or modify it *
-*  under the terms of the GNU General Public License as published by the   *
-*  Free Software Foundation; either version 2 of the License, or (at your  *
-*  option) any later version.                                              *
-\**************************************************************************/
-
-/**
- * Implementa o design pattern factory para o módulo Workflow
- * @author Carlos Eduardo Nogueira Gonçalves
- * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
- * @version 1.1
- * @package Workflow
- * @license http://www.gnu.org/copyleft/gpl.html GPL
- */
-class Factory
-{
-	/**
-	 * @var array $_cache Cache dos objetos
-	 * @access private
-	 */
-	private $_cache;
-
-	/**
-	 * @var array $classPath Caminho de busca das classes
-	 * @access protected
-	 */
-	protected $classPath;
-
-	/**
-	 * @var array $preffix Prefixo para o nome das classes
-	 * @access protected
-	 */
-	protected $preffix;
-
-	/**
-	 * @var array $suffix Sufixo para o nome das classes
-	 * @access protected
-	 */
-	protected $suffix;
-
-	/**
-	 * Construtor da classe
-	 * @return object
-	 * @access public
-	 */
-	function Factory()
-	{
-		$this->_cache = array();
-		$this->classPath = dirname(__FILE__);
-		$this->preffix = 'class.';
-		$this->suffix = '.inc.php';
-	}
-
-	/**
-	 * Importa os arquivos da classe
-	 * @param string $input Nome da classe
-	 * @access private
-	 * @return void
-	 */
-	private function _import($input)
-	{
-		$file = $this->classPath . '/' . $this->preffix . $input . $this->suffix;
-		if (@file_exists($file))
-			require_once $file;
-		else
-			trigger_error("O arquivo " . $file . " não existe.", E_USER_ERROR);
-	}
-
-	/**
-	 * Armazena referências aos objetos recém criados
-	 * @param string $key O nome da classe
-	 * @param object &$item A instância da classe
-	 * @return void
-	 * @access private
-	 */
-	private function _setEntry($key, &$item)
-	{
-		$this->_cache[$key] = &$item;
-	}
-
-	/**
-	 * Retorna a referência ao objeto armazenado
-	 * @param string $key Nome da classe
-	 * @return object
-	 * @access private
-	 */
-	private function &_getEntry($key)
-	{
-		return $this->_cache[$key];
-	}
-
-	/**
-	 * Verifica se uma determinada classe possui objeto armazenado no cache da Factory
-	 * @param string $key Nome da classe
-	 * @return boolean
-	 * @access public
-	 */
-	function isEntry($key)
-	{
-		return ($this->_getEntry($key) !== null);
-	}
-
-	/**
-	 * Retorna objetos armazenados ou cria novos objetos utilizando o pattern singleton
-	 * @param string $className Nome da classe
-	 * @return object
-	 * @access public
-	 */
-	function &getInstance()
-	{
-		if (func_num_args() > 0)
-		{
-			$args = func_get_args();
-			if ($this->isEntry($args[0]))
-			{
-				return($this->_getEntry($args[0]));
-			}
-			else
-			{
-				$instance = call_user_func_array(array(&$this, 'newInstance'), $args);
-				$this->_setEntry($args[0], &$instance);
-				return $instance;
-			}
-		}
-	}
-
-	/**
-	 * Cria novos objetos
-	 * @param string $className Nome da classe
-	 * @return object
-	 * @access public
-	 */
-	function &newInstance()
-	{
-		if (func_num_args() > 0)
-		{
-			$args = func_get_args();
-			$className = $args[0];
-			array_splice($args, 0, 1);
-			$this->_import($className);
-
-			$reflectionObj = new ReflectionClass($className);
-			return $reflectionObj->newInstanceArgs($args);
-		}
-	}
-
-	/**
-	 * Retorna objetos armazenados ou cria novos objetos utilizando o pattern singleton (somente para módulos externos)
-	 * @param string $moduleName O nome do módulo
-	 * @param string $className Nome da classe
-	 * @return object
-	 * @access public
-	 */
-	function &getForeignInstance()
-	{
-		if (func_num_args() > 1)
-		{
-			$args = func_get_args();
-
-			$oldClassPath = $this->classPath;
-			$this->classPath .= '/../../' . $args[0] . '/inc';
-
-			array_splice($args, 0, 1);
-			$instance = call_user_func_array(array(&$this, 'getInstance'), $args);
-			$this->classPath = $oldClassPath;
-			return $instance;
-		}
-	}
-
-	/**
-	 * Cria novos objetos (somente para módulos externos)
-	 * @param string $moduleName O nome do módulo
-	 * @param string $className Nome da classe
-	 * @return object
-	 * @access public
-	 */
-	function &newForeignInstance()
-	{
-		if (func_num_args() > 1)
-		{
-			$args = func_get_args();
-
-			$oldClassPath = $this->classPath;
-			$this->classPath .= '/../../' . $args[0] . '/inc';
-
-			array_splice($args, 0, 1);
-			$instance = call_user_func_array(array(&$this, 'newInstance'), $args);
-			$this->classPath = $oldClassPath;
-			return $instance;
-		}
-	}
-}
-?>
