Index: sandbox/workflow/trunk/showUserPicture.php
===================================================================
--- sandbox/workflow/trunk/showUserPicture.php	(revision 1468)
+++ sandbox/workflow/trunk/showUserPicture.php	(revision 2372)
@@ -12,4 +12,4 @@
 if (empty($_SESSION))
 	exit(0);
-$GLOBALS['workflow']['factory']->getInstance('UserPictureProvider')->serve();
+Factory::getInstance('UserPictureProvider')->serve();
 ?>
Index: sandbox/workflow/trunk/templateFile.php
===================================================================
--- sandbox/workflow/trunk/templateFile.php	(revision 1468)
+++ sandbox/workflow/trunk/templateFile.php	(revision 2372)
@@ -12,4 +12,4 @@
 if (empty($_SESSION))
 	exit(0);
-$GLOBALS['workflow']['factory']->getInstance('TemplateServer')->redirect();
+Factory::getInstance('TemplateServer')->redirect();
 ?>
Index: sandbox/workflow/trunk/lib/factory/BaseFactory.php
===================================================================
--- sandbox/workflow/trunk/lib/factory/BaseFactory.php	(revision 2372)
+++ sandbox/workflow/trunk/lib/factory/BaseFactory.php	(revision 2372)
@@ -0,0 +1,184 @@
+<?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.                                              *
+\**************************************************************************/
+
+/**
+ * Base Factory abstract class.
+ * This class implements all the common behaviour of
+ * it's specialized classes (ProcessFactory and WorkflowFactory).
+ * The only class allowed to use it's methods should be the
+ * Factory frontend.
+ *
+ * @package Factory
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+abstract class BaseFactory {
+
+	/**
+	 * @var array $_fileInfo Store what classes we can instantiate.
+	 * @access private
+	 */
+	private $_fileInfo;
+
+
+	/**
+	 * Registers classes into '$_fileInfo' private
+	 * atribute.
+	 *
+	 * @param string $className Class name.
+	 * @param string $fileName Name of the file that contains the class definition.
+	 * @param string $relativePath The path to the file, relative to $basePath.
+	 * @param string $basePath Base path to append $relativePath. Optional.
+	 * @access protected
+	 * @return void
+	 */
+	protected final function registerFileInfo($className, $fileName, $relativePath, $basePath = WF_SERVER_ROOT) {
+
+		/* default is to override */
+		$this->_fileInfo[$className] = array(	'filename' => $fileName,
+												'path' => $relativePath,
+												'basePath' => $basePath,
+												'instance' => null);
+	}
+
+
+	/**
+	 * Here we should do all the factory stuff.
+	 * The classes instatiated here will be stored
+	 * into our private object cache. If there is no
+	 * object of the given type into the cache, 'newInstance'
+	 * will be called. This method must deal with
+	 * pointers (&) to avoid object duplications.
+	 *
+	 * @param string $className Name of the class.
+	 * @param array $classArgs Parameters to the class's constructor.
+	 * @access public
+	 * @return object
+	 */
+	public function &getInstance($className, $classArgs){
+
+		/* have we a class name? */
+		if (empty($className))
+			return null;
+
+		/* recovering class data */
+		if ($entry = &$this->_getEntry($className)) {
+
+			if (is_null($entry['instance'])) {
+
+				/* we must instantiate it */
+                if (($obj = &$this->newInstance($className, $classArgs)) == null)
+					throw new Exception("Unable to instantiate '".$className."'");
+
+				/* saving the object reference */
+				$this->_setEntryInstance($className, $obj);
+				return $obj;
+			}
+			return $entry['instance'];
+
+		}
+		/* class not allowed */
+		else
+			throw new Exception("You are not allowed to instantiate class '".$className."'.");
+	}
+
+	/**
+	 * Instantiating classes.
+	 *
+	 * @todo Maybe we don't have to use the reflection
+	 *		 class here. Future work...
+	 * @param string $className Name of the class.
+	 * @param array $classArgs Parameters to the class's constructor.
+	 * @access public
+	 * @return object
+	 */
+	public function &newInstance($className, $classArgs){
+
+		/* have we a class name? */
+		if (empty($className))
+			return null;
+
+		/* just to be sure. If this method fails, it will throw an exception anyway... */
+		if(!$this->_import($className))
+			return null;
+
+		/**
+		 * Here we use this big white elephant (by big white elephant I mean php
+		 * reflection interface) just because we have to pass an unknown number
+		 * of parameters to the constructor of the class.
+		 * If you know a better way to do this, please update this code =D
+		 */
+		$reflectionObj = new ReflectionClass($className);
+
+		if (count($classArgs) == 0)
+			return $reflectionObj->newInstance();
+		return $reflectionObj->newInstanceArgs($classArgs);
+	}
+
+
+	/**
+	 * Private stuff. Handles the cache and information
+	 * '$_fileInfo' array.
+	 *
+	 * @param string $className Key to search for into the internal cache.
+	 * @access private
+	 * @return array
+	 */
+	private function &_getEntry($className){
+		return $this->_fileInfo[$className];
+	}
+
+
+	/**
+	 * Stores the given object into the internal cache
+	 * for upcoming requests.
+	 *
+	 * @param string $className Name of the class.
+	 * @param object Object whose reference will be stored.
+	 * @access private
+	 * @return boolean
+	 */
+	private function _setEntryInstance($className, &$obj){
+
+		if (is_array($this->_fileInfo[$className])) {
+			$this->_fileInfo[$className]['instance'] = &$obj;
+			return true;
+		}
+		return false;
+	}
+
+
+	/**
+	 * Including (requiring_once ;P ) the file(s) itself. Ideally,
+	 * it could be the only place to include files.
+	 *
+	 * @param string $className Key to search for into internal cache.
+	 * @access private
+	 * @return boolean
+	 */
+	private function _import($className){
+
+		/* not found */
+		if (!($entry = $this->_getEntry($className)))
+			throw new Exception('You are not allowed to instantiate \''.$className.'\' class.');
+
+		$fullPath = $entry['basePath'] . '/' . $entry['path'] . '/' . $entry['filename'];
+
+		/* file not found */
+		if (!file_exists($fullPath))
+			throw new Exception("File '".$fullPath."' not found.");
+
+		/* including file */
+		require_once $fullPath;
+		return true;
+	}
+}
+?>
Index: sandbox/workflow/trunk/lib/factory/WorkflowFactory.php
===================================================================
--- sandbox/workflow/trunk/lib/factory/WorkflowFactory.php	(revision 2372)
+++ sandbox/workflow/trunk/lib/factory/WorkflowFactory.php	(revision 2372)
@@ -0,0 +1,170 @@
+<?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.                                              *
+\**************************************************************************/
+
+/**
+ * Specialization of the BaseFactory class.
+ * This class is used to instantiate classes by
+ * the workflow module (not by processes). You
+ * cannot access this class directly, but requests
+ * to the Factory frontend class in 'unsecured mode'
+ * will be forwarded to this class.
+ *
+ * @package Factory
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+final class WorkflowFactory extends BaseFactory {
+
+
+	/**
+	 * @var boolean $_instantiated Attribute that stores whether this
+	 *		class was instantiated or not. This is used to limit the
+	 * 		instantiation of this class.
+	 * @access private
+	 * @static
+	 */
+	private static $_instantiated = false;
+
+
+	/**
+	 * Construct the class. This function will inform which classes
+	 * you will be able to instantiate and where to find it.
+	 * This function implements a kind of singleton design pattern too.
+	 * @access public
+	 */
+	public function __construct() {
+
+		/* don't let the user to instantiate this class more than once. */
+		if (self::$_instantiated)
+			throw new Exception("You can't instantiate this class again.");
+
+		/* registering allowed classes */
+		$this->registerFileInfo('WorkflowObjects', 'class.WorkflowObjects.inc.php', 'inc');
+		$this->registerFileInfo('WorkflowWatcher', 'class.WorkflowWatcher.inc.php', 'inc');
+		$this->registerFileInfo('WorkflowLDAP', 'class.WorkflowLDAP.inc.php', 'inc');
+		$this->registerFileInfo('WorkflowSecurity', 'class.WorkflowSecurity.inc.php', 'inc');
+		$this->registerFileInfo('WorkflowMacro', 'class.WorkflowMacro.inc.php', 'inc');
+		$this->registerFileInfo('WorkflowJobManager', 'class.WorkflowJobManager.inc.php', 'inc');
+		$this->registerFileInfo('SecurityUtils', 'class.utils.security.php', 'inc');
+		$this->registerFileInfo('ResourcesRedirector', 'class.ResourcesRedirector.inc.php', 'inc');
+		$this->registerFileInfo('TemplateServer', 'class.TemplateServer.inc.php', 'inc');
+		$this->registerFileInfo('CachedLDAP', 'class.CachedLDAP.inc.php', 'inc');
+		$this->registerFileInfo('BrowserInfo', 'class.BrowserInfo.inc.php', 'inc');
+		$this->registerFileInfo('JobScheduler', 'class.JobScheduler.inc.php', 'inc');
+		$this->registerFileInfo('JobRunner', 'class.JobRunner.inc.php', 'inc');
+		$this->registerFileInfo('Thread', 'class.Thread.inc.php', 'inc');
+		$this->registerFileInfo('Paging', 'class.Paging.inc.php', 'inc');
+		$this->registerFileInfo('FsUtils', 'class.fsutils.inc.php', 'inc');
+		$this->registerFileInfo('UserPictureProvider', 'class.UserPictureProvider.inc.php', 'inc');
+		$this->registerFileInfo('powergraphic', 'class.powergraphic.inc.php', 'inc');
+
+		$this->registerFileInfo('run_activity', 'class.run_activity.inc.php', 'inc');
+		$this->registerFileInfo('process_smarty', 'class.process_smarty.inc.php', 'inc');
+		$this->registerFileInfo('workflow_smarty', 'class.workflow_smarty.inc.php', 'inc');
+		$this->registerFileInfo('workflow_acl', 'class.workflow_acl.inc.php', 'inc');
+		$this->registerFileInfo('workflow_process', 'class.workflow_process.inc.php', 'inc');
+		$this->registerFileInfo('workflow_processmanager', 'class.workflow_processmanager.inc.php', 'inc');
+		$this->registerFileInfo('workflow_wfruntime', 'class.workflow_wfruntime.inc.php', 'inc');
+		$this->registerFileInfo('workflow_gui', 'class.workflow_gui.inc.php', 'inc');
+		$this->registerFileInfo('workflow_rolemanager', 'class.workflow_rolemanager.inc.php', 'inc');
+		$this->registerFileInfo('workflow_baseactivity', 'class.workflow_baseactivity.inc.php', 'inc');
+		$this->registerFileInfo('workflow_activitymanager', 'class.workflow_activitymanager.inc.php', 'inc');
+		$this->registerFileInfo('workflow_instance', 'class.workflow_instance.inc.php', 'inc');
+
+		$this->registerFileInfo('bo_monitors', 'class.bo_monitors.inc.php', 'inc');
+		$this->registerFileInfo('bo_adminaccess', 'class.bo_adminaccess.inc.php', 'inc');
+		$this->registerFileInfo('bo_userinterface', 'class.bo_userinterface.inc.php', 'inc');
+		$this->registerFileInfo('bo_participants', 'class.bo_participants.inc.php', 'inc');
+		$this->registerFileInfo('bo_agent_mail_smtp', 'class.bo_agent_mail_smtp.inc.php', 'inc');
+		$this->registerFileInfo('bo_editor', 'class.bo_editor.inc.php', 'inc');
+		$this->registerFileInfo('bo_utils', 'class.bo_utils.inc.php', 'inc');
+
+		$this->registerFileInfo('so_agent_mail_smtp', 'class.so_agent_mail_smtp.inc.php', 'inc');
+		$this->registerFileInfo('so_external_applications', 'class.so_external_applications.inc.php', 'inc');
+		$this->registerFileInfo('so_adminaccess', 'class.so_adminaccess.inc.php', 'inc');
+		$this->registerFileInfo('so_orgchart', 'class.so_orgchart.inc.php', 'inc');
+		$this->registerFileInfo('so_userinterface', 'class.so_userinterface.inc.php', 'inc');
+		$this->registerFileInfo('so_adminjobs', 'class.so_adminjobs.inc.php', 'inc');
+		$this->registerFileInfo('so_move_instances', 'class.so_move_instances.inc.php', 'inc');
+
+		/* job classes */
+		$this->registerFileInfo('AbsoluteDate', 'class.AbsoluteDate.inc.php', 'inc/jobs');
+		$this->registerFileInfo('RelativeDate', 'class.RelativeDate.inc.php', 'inc/jobs');
+		$this->registerFileInfo('WeekDate', 'class.WeekDate.inc.php', 'inc/jobs');
+
+		/* galaxia engine classes */
+		$this->registerFileInfo('GUI', 'GUI.php', 'inc/engine/src/GUI');
+		$this->registerFileInfo('ProcessManager', 'ProcessManager.php', 'inc/engine/src/ProcessManager');
+		$this->registerFileInfo('ActivityManager', 'ActivityManager.php', 'inc/engine/src/ProcessManager');
+		$this->registerFileInfo('InstanceManager', 'InstanceManager.php', 'inc/engine/src/ProcessManager');
+		$this->registerFileInfo('RoleManager', 'RoleManager.php', 'inc/engine/src/ProcessManager');
+		$this->registerFileInfo('JobManager', 'JobManager.php', 'inc/engine/src/ProcessManager');
+		$this->registerFileInfo('Process_GraphViz', 'GraphViz.php', 'inc/engine/src/ProcessManager');
+		$this->registerFileInfo('ProcessMonitor', 'ProcessMonitor.php', 'inc/engine/src/ProcessMonitor');
+		$this->registerFileInfo('Process', 'Process.php', 'inc/engine/src/API');
+		$this->registerFileInfo('Instance', 'Instance.php', 'inc/engine/src/API');
+		$this->registerFileInfo('Start', 'Start.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('End', 'End.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('Join', 'Join.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('Split', 'Split.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('Standalone', 'Standalone.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('View', 'View.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('SwitchActivity', 'SwitchActivity.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('Activity', 'Activity.php', 'inc/engine/src/API/activities');
+		$this->registerFileInfo('BaseActivity', 'BaseActivity.php', 'inc/engine/src/API');
+
+		$this->registerFileInfo('ajax_ldap', 'class.ajax_ldap.inc.php', 'inc/engine');
+		$this->registerFileInfo('ajax_config', 'class.ajax_config.inc.php', 'inc/engine');
+		$this->registerFileInfo('WfRuntime', 'WfRuntime.php', 'inc/engine/src/common');
+		$this->registerFileInfo('WfSecurity', 'WfSecurity.php', 'inc/engine/src/common');
+
+		/* nano classes */
+		$this->registerFileInfo('Services_JSON', 'JSON.php', 'inc/nano');
+		$this->registerFileInfo('NanoRequest', 'NanoRequest.class.php', 'inc/nano');
+		$this->registerFileInfo('NanoController', 'NanoController.class.php', 'inc/nano');
+		$this->registerFileInfo('NanoJsonConverter', 'NanoJsonConverter.class.php', 'inc/nano');
+		$this->registerFileInfo('NanoSanitizer', 'NanoSanitizer.class.php', 'inc/nano');
+
+		/* registering egw external classes */
+		$this->registerFileInfo('db', 'class.db.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('acl', 'class.acl.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('accounts', 'class.accounts.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('config', 'class.config.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('common', 'class.common.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('session', 'class.session.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('nextmatchs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('categories', 'class.categories.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('listbox', 'class.listbox.inc.php', '', EGW_INC_ROOT);
+		$this->registerFileInfo('phpmailer', 'class.phpmailer.inc.php', '', EGW_INC_ROOT);
+
+		/**
+		 * It can cause some troubles. A class named 'bo' must be instantiated by a
+		 * Factory::getInstance('bo') call, that isn't really intuitive.. Something to
+		 * think about...
+		 */
+		$this->registerFileInfo('bo', 'class.bo.inc.php', 'emailadmin/inc', EGW_SERVER_ROOT);
+
+
+		/**
+		 * TODO - This is a veeery big workaround to maintain compatibility with
+		 * processes that uses the old non-static factory. So, we made this wrapper
+		 * (adapter) that just calls the new and cute static factory class in the
+		 * right way. It should be removed as soon as possible.
+		*/
+		$this->registerFileInfo('ProcessWrapperFactory', 'ProcessWrapperFactory.php', 'lib/factory/');
+
+
+		/* ok. no more instances of this class.. */
+		self::$_instantiated = true;
+	}
+}
+
+?>
Index: sandbox/workflow/trunk/lib/factory/ProcessFactory.php
===================================================================
--- sandbox/workflow/trunk/lib/factory/ProcessFactory.php	(revision 2372)
+++ sandbox/workflow/trunk/lib/factory/ProcessFactory.php	(revision 2372)
@@ -0,0 +1,78 @@
+<?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.                                              *
+\**************************************************************************/
+
+/**
+ * Specialization of the BaseFactory class.
+ * This class is used to instantiate classes for
+ * processes. You cannot access this class directly,
+ * but requests to the Factory frontend class in
+ * 'secured mode' will be forwarded to this class.
+ * It should be much more restrictive than its
+ * older brother (or sister), WorkflowFactory...
+ *
+ * @package Factory
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+final class ProcessFactory extends BaseFactory {
+
+
+	/**
+	 * @var boolean $_instantiated Attribute that stores whether this
+	 *		class was instantiated or not. This is used to limit the
+	 * 		instantiation of this class.
+	 * @access private
+	 * @static
+	 */
+	private static $_instantiated = false;
+
+	/**
+	 * Construct the class. This function will inform which classes
+	 * you will be able to instantiate and where to find it.
+	 * This function implements a kind of singleton design pattern too.
+	 * @access public
+	 */
+	public function __construct() {
+
+		/* don't let the user to instantiate this class more than once. */
+		if (self::$_instantiated)
+			throw new Exception("You can't instantiate this class again.");
+
+		/* registering allowed classes */
+		$this->registerFileInfo('wf_cached_ldap', 'class.wf_cached_ldap.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_crypt', 'class.wf_crypt.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_date', 'class.wf_date.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_db', 'class.wf_db.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_engine', 'class.wf_engine.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_fpdf', 'class.wf_fpdf.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_instance', 'class.wf_instance.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_ldap', 'class.wf_ldap.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_location', 'class.wf_location.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_log', 'class.wf_log.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_mail', 'class.wf_mail.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_mem_image', 'class.wf_mem_image.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_natural', 'class.wf_natural.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_orgchart', 'class.wf_orgchart.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_paging', 'class.wf_paging.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_phplot', 'class.wf_phplot.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_regex', 'class.wf_regex.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_role', 'class.wf_role.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_string', 'class.wf_string.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_type', 'class.wf_type.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_url', 'class.wf_url.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_util', 'class.wf_util.php', 'inc/local/classes');
+		$this->registerFileInfo('wf_workitem', 'class.wf_workitem.php', 'inc/local/classes');
+
+		/* ok. no more instances of this class.. */
+		self::$_instantiated = true;
+	}
+}
+?>
Index: sandbox/workflow/trunk/lib/factory/Factory.php
===================================================================
--- sandbox/workflow/trunk/lib/factory/Factory.php	(revision 2372)
+++ sandbox/workflow/trunk/lib/factory/Factory.php	(revision 2372)
@@ -0,0 +1,153 @@
+<?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.                                              *
+\**************************************************************************/
+
+/**
+ * The Factory frontend class.
+ * This class controls which concrete Factory
+ * will be used, depending on the current
+ * 'security mode'. It lazy instantiates both
+ * factories (process and module) when they are
+ * required, and stores these objects. All the
+ * accesses to factories are done through this class,
+ * implementing a kind of Proxy design pattern.
+ * This class depends on Security frontend class
+ * to decide which factory to call.
+ *
+ * @package Factory
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+class Factory {
+
+
+	/**
+	 * @var object $_unsecuredFactory Stores WorkflowFactory object.
+	 * @access private
+	 * @static
+	 */
+	private static $_unsecuredFactory = null;
+
+
+	/**
+	 * @var object $_securedFactory Stores ProcessFactory object.
+	 * @access private
+	 * @static
+	 */
+	private static $_securedFactory = null;
+
+
+	/**
+	 * Constructor. Just disable direct instantiation.
+	 *
+	 * @access public
+	 * @return void
+	 * @static
+	 */
+	public function __construct() {
+		throw new Exception("Oops! Static only class.");
+	}
+
+
+	/**
+	 * Just forward this call.
+	 *
+	 * @access public
+	 * @return object
+	 * @static
+	 */
+	public static function &getInstance() {
+
+		$args = func_get_args();
+		return self::_callMethod(__FUNCTION__, $args);
+	}
+
+
+	/**
+	 * Just forward this call.
+	 *
+	 * @access public
+	 * @return object
+	 * @static
+	 */
+	public static function &newInstance() {
+
+		$args = func_get_args();
+		return self::_callMethod(__FUNCTION__, $args);
+	}
+
+
+	/**
+	 * Selecting the proper factory to call. This function
+	 * should never be called with a random $methodName. Allowed
+	 * values are 'getInstance' and 'newInstance'.
+	 *
+	 * @param string $methodName Name of the BaseFactory method to call.
+	 * @param array $args Parameters to class's constructor.
+	 * @access private
+	 * @return object
+	 * @static
+	 */
+	private static function &_callMethod($methodName, $args) {
+
+		/* security off (module space) */
+		if (!Security::isEnabled()) {
+
+			/* it must be instatiated */
+			if (is_null(self::$_unsecuredFactory))
+				self::$_unsecuredFactory = new WorkflowFactory();
+
+			$className = array_shift($args);
+			return self::$_unsecuredFactory->$methodName($className, $args);
+		}
+		/* oops. we are in the process space (restricted). */
+		else {
+
+			/* it must be instatiated */
+			if (is_null(self::$_securedFactory))
+				self::$_securedFactory = new ProcessFactory();
+
+			$className = array_shift($args);
+
+			/**
+			 * If the class is not allowed, we must check who is trying
+			 * to instantiate it. If it's a module guy, let's allow him.
+			 * Throw up the exception otherwise.
+			 */
+			try {
+				$obj = &self::$_securedFactory->$methodName($className, $args);
+			}
+
+			/**
+			 * We are erroneously catching any exceptions. We should catch only the 'class not allowed'
+			 * types of exceptions. To do so, a custom exception class must be defined.
+		 	 */
+			catch(Exception $e) {
+
+				/**
+				 * Here we are using depth 2 in isSafeDir method, because we are on a private
+				 * method. Thus, we need to know if the "caller's caller's" function is on a
+				 * safe dir, instead of the direct caller's method.
+				 */
+				if (Security::isSafeDir(2))
+					$obj = &self::$_unsecuredFactory->$methodName($className, $args);
+
+				/* naaasty one. take this! */
+				else
+					throw($e);
+			}
+
+			// finally
+			return $obj;
+		}
+	}
+}
+
+?>
Index: sandbox/workflow/trunk/lib/factory/ProcessWrapperFactory.php
===================================================================
--- sandbox/workflow/trunk/lib/factory/ProcessWrapperFactory.php	(revision 2372)
+++ sandbox/workflow/trunk/lib/factory/ProcessWrapperFactory.php	(revision 2372)
@@ -0,0 +1,61 @@
+<?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.                                              *
+\**************************************************************************/
+
+/**
+ * This class is temporary. We just need to use it until all the
+ * processes are updated and using our new static factory. The
+ * only purpose of this class is to forward the calls to our
+ * frontend factory class. Formally, it's an Adapter Design Pattern.
+ *
+ * @package Factory
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+class ProcessWrapperFactory
+{
+
+	/**
+	 * Just forward the call.
+	 *
+	 * @access public
+	 * @return object
+	 */
+	public function &getInstance() {
+
+		$args = func_get_args();
+
+		/**
+		 * To save memory and processing, we store caches of objects instantiated
+		 * by the factory. When we use this beautiful function (call_user_func_array),
+		 * it makes an unexpected copy of the object. Of course we don't want it.
+		 * For now, we will keep doing copies.
+		 */
+		return call_user_func_array(array(Factory, "getInstance"), $args);
+
+	}
+
+
+	/**
+	 * Just forward the call.
+	 *
+	 * @access public
+	 * @return object
+	 */
+	public function &newInstance() {
+
+		$args = func_get_args();
+
+		/* read the comment above */
+		return call_user_func_array(array(Factory, "newInstance"), $args);
+
+	}
+}
+?>
Index: sandbox/workflow/trunk/lib/security/Security.php
===================================================================
--- sandbox/workflow/trunk/lib/security/Security.php	(revision 2372)
+++ sandbox/workflow/trunk/lib/security/Security.php	(revision 2372)
@@ -0,0 +1,112 @@
+<?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.                                              *
+\**************************************************************************/
+
+/**
+ * Security class for Workflow module.
+ * You should never forget to call 'enable'
+ * public method to enable security before
+ * executing process code.
+ *
+ * @package Security
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+class Security {
+
+	/**
+	 * @var boolean $_protection Stores the current security mode.
+	 * @access private
+	 * @static
+	 */
+	private static $_protection = false;
+
+
+	/**
+	 * Disallow the instantiation of this class.
+	 * @access public
+	 * @return void
+	 */
+	public function __construct() {
+		throw new Exception("Oops! Static only class.");
+	}
+
+
+	/**
+	 * Returns the current security mode.
+	 * @access public
+	 * @return boolean
+	 * @static
+	 */
+	public static function isEnabled() {
+		return self::$_protection;
+	}
+
+
+	/**
+	 * Change to secured mode.
+	 * @access public
+	 * @return boolean
+	 * @static
+	 */
+	public static function enable() {
+
+		if (self::isSafeDir())
+			self::$_protection = true;
+		else
+			throw new Exception('You are not allowed to change the security mode.');
+		return true;
+	}
+
+	/**
+	 * Change to unsecured mode.
+	 * @access public
+	 * @return boolean
+	 * @static
+	 */
+	public static function disable() {
+
+		if (self::isSafeDir())
+			self::$_protection = false;
+		else
+			throw new Exception('You are not allowed to change the security mode.');
+		return true;
+	}
+
+
+	/**
+	 * Implements the security validation.
+	 * This function tell us if a fileName is on a safe directory.
+	 * For safe dir we mean that no process code exists under it.
+	 * The 'depth' parameter specifies the deepness of the file that
+	 * we are validating. Default value is to validate the imediate
+	 * previous function.
+	 *
+	 * @param integer $depth The deepness of the fileName in backtrace.
+	 * @access public
+	 * @return boolean
+	 * @static
+	 */
+	public static function isSafeDir($depth = 1) {
+
+		/* our backtrace based policy */
+		$backtrace = debug_backtrace();
+		$originFile = $backtrace[$depth]['file'];
+
+		if (empty($originFile))
+			return false;
+
+		/* if $fileName is a file under our server root, then it's safe. */
+		if (substr_compare($originFile, EGW_SERVER_ROOT, 0, strlen(EGW_SERVER_ROOT)) == 0)
+			return true;
+		return false;
+	}
+}
+?>
Index: sandbox/workflow/trunk/redirect.php
===================================================================
--- sandbox/workflow/trunk/redirect.php	(revision 1468)
+++ sandbox/workflow/trunk/redirect.php	(revision 2372)
@@ -12,4 +12,4 @@
 if (empty($_SESSION))
 	exit(0);
-$GLOBALS['workflow']['factory']->getInstance('ResourcesRedirector')->redirect();
+Factory::getInstance('ResourcesRedirector')->redirect();
 ?>
Index: sandbox/workflow/trunk/controller.php
===================================================================
--- sandbox/workflow/trunk/controller.php	(revision 1484)
+++ sandbox/workflow/trunk/controller.php	(revision 2372)
@@ -16,5 +16,5 @@
 	{
 		require_once dirname(__FILE__) . '/inc/common.inc.php';
-		$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareEnvironment();
+		Factory::getInstance('WorkflowMacro')->prepareEnvironment();
 	}
 
Index: sandbox/workflow/trunk/inc/class.workflow_processmonitor.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_processmonitor.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_processmonitor.inc.php	(revision 2372)
@@ -17,5 +17,5 @@
 		function workflow_processmonitor()
 		{
-			parent::ProcessMonitor($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::ProcessMonitor(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.bo_utils.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_utils.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_utils.inc.php	(revision 2372)
@@ -11,6 +11,4 @@
 
 require_once 'class.bo_ajaxinterface.inc.php';
-require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'GUI' . SEP . 'GUI.php';
-require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php';
 
 /**
@@ -34,5 +32,5 @@
 	{
 		parent::bo_ajaxinterface();
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
+		$this->db =& Factory::getInstance('WorkflowObjects')->getDBExpresso();
 	}
 
@@ -88,5 +86,5 @@
 			$ret_name = empty($params['name']) ? 'cn' : $params['name'];
 
-			$ajaxConfig = new ajax_config('contactcenter');
+			$ajaxConfig = &Factory::newInstance('ajax_config', 'contactcenter');
 			$config = $ajaxConfig->read_repository();
 
Index: sandbox/workflow/trunk/inc/class.run_activity.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.run_activity.inc.php	(revision 2072)
+++ sandbox/workflow/trunk/inc/class.run_activity.inc.php	(revision 2372)
@@ -10,9 +10,8 @@
 	\**************************************************************************/
 
+	require_once(dirname(__FILE__) . SEP . 'common.inc.php'); 				 /* including common deifinitions */
 	require_once(dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php'  ); /* superclass source code       */
 	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.utils.security.php'     ); /* sanitizes input data         */
 
 	/**
@@ -206,12 +205,17 @@
 		{
 			parent::WorkflowUtils();
-			$this->runtime		= CreateObject('workflow.workflow_wfruntime');
+
+			/**
+			 * We should always use newInstance to instantiate
+			 * 'workflow_wfruntime'
+			 */
+			$this->runtime			= &Factory::newInstance('workflow_wfruntime');
 			$this->runtime->setDebug(_DEBUG);
-			//$this->base_activity	= CreateObject('workflow.workflow_baseactivity');
-			//$this->process		= CreateObject('workflow.workflow_process');
-			$this->GUI		= CreateObject('workflow.workflow_gui');
-			$this->categories 	= CreateObject('phpgwapi.categories');
-
-			$this->workflowSmarty = CreateObject('workflow.workflow_smarty', false);
+			//$this->base_activity	= Factory::getInstance('workflow_baseactivity');
+			//$this->process		= Factory::getInstance('workflow_process');
+			$this->GUI				= &Factory::getInstance('workflow_gui');
+			$this->categories 		= &Factory::getInstance('categories');
+
+			$this->workflowSmarty 	= &Factory::getInstance('workflow_smarty', false);
 			// TODO: open a new connection to the database under a different username to allow privilege handling on tables
 			/* CELEPAR */
@@ -301,5 +305,5 @@
 			$this->process_version	= $this->process->getVersion();
 			$this->activity_name	= $activity->getName();
-			$this->user_name	= $GLOBALS['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);
 
@@ -318,8 +322,8 @@
 			$GLOBALS['workflow']['wf_workflow_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow';
 			$GLOBALS['workflow']['wf_resources_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file=';
-			$GLOBALS['workflow']['wf_default_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('processes');
-			$GLOBALS['workflow']['wf_workflow_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('');
+			$GLOBALS['workflow']['wf_default_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('processes');
+			$GLOBALS['workflow']['wf_workflow_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('');
 			$GLOBALS['workflow']['wf_activity_url']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id;
-			$GLOBALS['workflow']['wf_user_cnname']				= $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
+			$GLOBALS['workflow']['wf_user_cnname']				= Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
 			$GLOBALS['workflow']['wf_back_link']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1';
 			$GLOBALS['workflow']['wf_js_path']					= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode';
@@ -376,5 +380,5 @@
 
 				/* check some permissions */
-				if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || ($GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($newUser) === false))
+				if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || (Factory::getInstance('WorkflowLDAP')->getName($newUser) === false))
 				{
 					$_SESSION['phpgw_info']['workflow']['user_groups'] = $actualUserGroups;
@@ -386,5 +390,5 @@
 					return false;
 				}
-				$smarty = CreateObject('workflow.process_smarty');
+				$smarty = Factory::getInstance('process_smarty');
 			}
 
@@ -399,5 +403,5 @@
 				/* #celepar# smarty code*/
 
-				$smarty = CreateObject('workflow.process_smarty');
+				$smarty = Factory::getInstance('process_smarty');
 
 				$smarty->template_dir  = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'code'.SEP.'templates';
@@ -438,7 +442,8 @@
 			$env['instance']      =& $instance;                        //process manager instance
 			$env['activity']      =& $activity;                        //activity manager instance
-			$security             =& new SecurityUtils();              //input sanitizer class
+			$security             =& Factory::newInstance('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 */
@@ -472,5 +477,15 @@
 
 			/* activate the security policy */
-			$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy();
+			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 */
@@ -661,8 +676,8 @@
 			$GLOBALS['workflow']['wf_workflow_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow';
 			$GLOBALS['workflow']['wf_resources_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file=';
-			$GLOBALS['workflow']['wf_default_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('processes');
-			$GLOBALS['workflow']['wf_workflow_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('');
+			$GLOBALS['workflow']['wf_default_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('processes');
+			$GLOBALS['workflow']['wf_workflow_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('');
 			$GLOBALS['workflow']['wf_activity_url']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id;
-			$GLOBALS['workflow']['wf_user_cnname']				= $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
+			$GLOBALS['workflow']['wf_user_cnname']				= Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
 			$GLOBALS['workflow']['wf_back_link']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1';
 			$GLOBALS['workflow']['wf_js_path']					= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode';
@@ -699,7 +714,8 @@
 			$env['instance']      =& $instance;                        //process manager instance
 			$env['activity']      =& $activity;                        //activity manager instance
-			$security             =& new SecurityUtils();              //input sanitizer class
+			$security             =& Factory::newInstance('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 */
@@ -712,8 +728,19 @@
 
 			/* activate the security policy */
-			$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy();
+			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;
-			$nc = new NanoController();
+			$nc = &Factory::newInstance('NanoController');
 			$nc->setClassPath(GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code');
 			$nc->iterateOverVirtualRequests();
Index: sandbox/workflow/trunk/inc/class.workflow_baseactivity.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_baseactivity.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_baseactivity.inc.php	(revision 2372)
@@ -17,5 +17,5 @@
 		function workflow_baseactivity()
 		{
-			parent::BaseActivity($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::BaseActivity(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.bo_agent_mail_smtp.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_agent_mail_smtp.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_agent_mail_smtp.inc.php	(revision 2372)
@@ -109,6 +109,6 @@
 	{
 		parent::bo_agent();
-		$this->so_agent = CreateObject('workflow.so_agent_mail_smtp');
-		$this->bo_emailadmin = CreateObject('emailadmin.bo');
+		$this->so_agent = Factory::getInstance('so_agent_mail_smtp');
+		$this->bo_emailadmin = Factory::getInstance('bo');
 		//the showProcessConfigurationFields is not done here, quite harder to build
 		$this->ProcessConfigurationFieldsdefault = array(
@@ -312,5 +312,5 @@
 	function init()
 	{
-		$this->mail = CreateObject('phpgwapi.phpmailer');
+		$this->mail = Factory::getInstance('phpmailer');
 		//set the $this->conf
 		$this->getProcessConfigurationFields($this->activity->getProcessId());
@@ -466,5 +466,5 @@
 		}
 
-		$process = CreateObject('workflow.workflow_process');
+		$process = Factory::getInstance('workflow_process');
 		$process->getProcess($this->process_id);
 		$this->process_name = $process->getName();
@@ -637,5 +637,5 @@
 					if ($this->process_name=='')
 					{
-						$process = CreateObject('workflow.workflow_process');
+						$process = Factory::getInstance('workflow_process');
 						$process->getProcess($this->process_id);
 						$this->process_name = $process->getName();
@@ -648,5 +648,5 @@
 					if ($this->process_version=='')
 					{
-						$process = CreateObject('workflow.workflow_process');
+						$process = Factory::getInstance('workflow_process');
 						$process->getProcess($this->process_id);
 						$this->process_name = $process->getName();
@@ -674,5 +674,5 @@
 					if (!is_object($this->account))
 					{
-						$this->account = CreateObject('phpgwapi.accounts');
+						$this->account = Factory::getInstance('accounts');
 					}
 					$ask_user = $this->instance->getOwner();
@@ -683,9 +683,9 @@
 					if (!is_object($this->role_manager))
 					{
-						$this->role_manager = CreateObject('workflow.workflow_rolemanager');
+						$this->role_manager = Factory::getInstance('workflow_rolemanager');
 					}
 					if (!is_object($this->account))
 					{
-						$this->account = CreateObject('phpgwapi.accounts');
+						$this->account = Factory::getInstance('accounts');
 					}
 					$my_subset = array('wf_activity_name' => $this->activity->getName());
@@ -718,5 +718,5 @@
 							if (!is_object($this->account))
 							{
-								$this->account = CreateObject('phpgwapi.accounts');
+								$this->account = Factory::getInstance('accounts');
 							}
 							$ask_user = $this->account->name2id($second_part);
@@ -731,9 +731,9 @@
 							if (!is_object($this->role_manager))
 							{
-								$this->role_manager = CreateObject('workflow.workflow_rolemanager');
+								$this->role_manager = Factory::getInstance('workflow_rolemanager');
 							}
 							if (!is_object($this->account))
 							{
-								$this->account = CreateObject('phpgwapi.accounts');
+								$this->account = Factory::getInstance('accounts');
 							}
 							$my_subset = array('wf_role_name' => $second_part);
Index: sandbox/workflow/trunk/inc/local/classes/class.wf_role.php
===================================================================
--- sandbox/workflow/trunk/inc/local/classes/class.wf_role.php	(revision 1048)
+++ sandbox/workflow/trunk/inc/local/classes/class.wf_role.php	(revision 2372)
@@ -58,6 +58,6 @@
 
 		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID;
-		$this->roleManager = CreateObject('workflow.workflow_rolemanager');
-		$this->activityManager = CreateObject('workflow.workflow_activitymanager');
+		$this->roleManager = Factory::getInstance('workflow_rolemanager');
+		$this->activityManager = Factory::getInstance('workflow_activitymanager');
 	}
 
@@ -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/trunk/inc/local/classes/class.wf_instance.php
===================================================================
--- sandbox/workflow/trunk/inc/local/classes/class.wf_instance.php	(revision 1385)
+++ sandbox/workflow/trunk/inc/local/classes/class.wf_instance.php	(revision 2372)
@@ -77,5 +77,5 @@
 	{
 		$instanceID = (int) $instanceID;
-		$instance = CreateObject('workflow.workflow_instance');
+		$instance = Factory::getInstance('workflow_instance');
 		if (!$instance->getInstance($instanceID))
 			return false;
@@ -118,5 +118,5 @@
 		$instance = $this->getInstanceObject($instanceID);
 
-		$runActivity = CreateObject('workflow.run_activity');
+		$runActivity = Factory::getInstance('run_activity');
 
 		ob_start();
@@ -423,6 +423,5 @@
 
 		/* load the required instance (for the required user) */
-		require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'GUI' . SEP . 'GUI.php';
-		$GUI = new GUI($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$GUI = &Factory::newInstance('GUI');
 		$userInstance = $GUI->gui_list_user_instances($userID, 0, -1, '', '', "(ga.wf_is_interactive = 'y') AND (gia.wf_activity_id = {$activityID}) AND (gia.wf_instance_id = {$instanceID})", false, $this->processID, true, false, true, false, false, false);
 		$userInstance = $userInstance['data'];
@@ -456,9 +455,6 @@
 		if ($userID !== '*')
 		{
-			require_once dirname(__FILE__) . '/class.wf_role.php';
-			require_once dirname(__FILE__) . '/class.wf_engine.php';
-
-			$wfRole = new wf_role();
-			$engine = new wf_engine();
+			$wfRole = Factory::getInstance('wf_role');
+			$engine = Factory::getInstance('wf_engine');
 			/* get information about the activity */
 			if (($activityInfo = $engine->getActivityInformationByID($activityID)) === false)
@@ -529,6 +525,5 @@
 
 		/* try to get the role id */
-		require_once dirname(__FILE__) . '/class.wf_role.php';
-		$wfRole = new wf_role();
+		$wfRole = Factory::getInstance('wf_role');
 		if (($roleID = $wfRole->getRoleIdByName($roleName)) === false)
 			return false;
Index: sandbox/workflow/trunk/inc/local/classes/class.wf_engine.php
===================================================================
--- sandbox/workflow/trunk/inc/local/classes/class.wf_engine.php	(revision 795)
+++ sandbox/workflow/trunk/inc/local/classes/class.wf_engine.php	(revision 2372)
@@ -68,5 +68,5 @@
 		$flagObject[0] = is_null($this->processManager);
 		if ($flagObject[0])
-			$this->processManager = CreateObject('workflow.workflow_processmanager');
+			$this->processManager = Factory::getInstance('workflow_processmanager');
 
 		$output = array();
@@ -90,6 +90,5 @@
 	function continueInstance($activityID, $instanceID)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->continueInstance($activityID, $instanceID);
 	}
@@ -104,6 +103,5 @@
 	function abortInstance($instanceID)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->abort($instanceID);
 	}
@@ -119,6 +117,5 @@
 	function setInstanceName($instanceID, $name)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->setName($instanceID, $name);
 	}
@@ -134,6 +131,5 @@
 	function setInstancePriority($instanceID, $priority)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->setPriority($instanceID, $priority);
 	}
@@ -149,6 +145,5 @@
 	function getIdleInstances($numberOfDays, $activities = null)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->getIdle($numberOfDays, $activities);
 	}
@@ -175,6 +170,5 @@
 	function getInstancesByName($name)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		$preOutput = $WFInstance->getByName($name);
 		$output = array();
@@ -197,6 +191,5 @@
 	function getChildInstances($instanceID = null, $activityID = null)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		$preOutput = $WFInstance->getChildren($instanceID, $activityID);
 		$output = array();
@@ -217,6 +210,5 @@
 	function getInstanceProperties($instanceID)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->getProperties($instanceID);
 	}
@@ -231,6 +223,5 @@
 	function getChildInstanceProperties($instanceID)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->getProperties($instanceID);
 	}
@@ -247,5 +238,5 @@
 		$flagObject[0] = is_null($this->acl);
 		if ($flagObject[0])
-			$this->acl = CreateObject('workflow.workflow_acl');
+			$this->acl = Factory::getInstance('workflow_acl');
 
 		$output = $this->acl->getUserPermissions($type, $uid);
@@ -268,5 +259,5 @@
 		$flagObject[0] = is_null($this->acl);
 		if ($flagObject[0])
-			$this->acl = CreateObject('workflow.workflow_acl');
+			$this->acl = Factory::getInstance('workflow_acl');
 
 		$output = $this->acl->getUserGroupPermissions($type, $uid);
@@ -346,6 +337,5 @@
 	function getUserInstances($users, $activities = null, $status = null)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->getByUser($users, $activities, $status);
 	}
@@ -360,6 +350,5 @@
 	function setInstanceProperty($instanceID, $nameProperty, $value)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->setProperty($instanceID, $nameProperty, $value);
 	}
@@ -377,6 +366,5 @@
 	function checkUserAccessToInstance($userID, $instanceID, $activityID, $writeAccess = true)
 	{
-		require_once 'class.wf_instance.php';
-		$WFInstance = new wf_instance();
+		$WFInstance = &Factory::getInstance('wf_instance');
 		return $WFInstance->checkUserAccess($userID, $instanceID, $activityID, $writeAccess);
 	}
Index: sandbox/workflow/trunk/inc/local/classes/class.JobBase.php
===================================================================
--- sandbox/workflow/trunk/inc/local/classes/class.JobBase.php	(revision 1437)
+++ sandbox/workflow/trunk/inc/local/classes/class.JobBase.php	(revision 2372)
@@ -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');
 	}
 
@@ -202,5 +200,5 @@
 	final public function createNewInstance($startActivityId, $instanceName=false, $properties=false, $user=false)
 	{
-		$activityManager = CreateObject('workflow.workflow_activitymanager');
+		$activityManager = Factory::getInstance('workflow_activitymanager');
 		$activity = $activityManager->get_activity($startActivityId);
 
Index: sandbox/workflow/trunk/inc/local/classes/class.wf_ldap.php
===================================================================
--- sandbox/workflow/trunk/inc/local/classes/class.wf_ldap.php	(revision 1067)
+++ sandbox/workflow/trunk/inc/local/classes/class.wf_ldap.php	(revision 2372)
@@ -1,4 +1,3 @@
 <?php
-require_once PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'classes' . SEP . 'class.wf_cached_ldap.php';
 
 /**
@@ -41,5 +40,5 @@
 	function wf_ldap()
 	{
-		$tmpLDAP = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$tmpLDAP = Factory::getInstance('WorkflowLDAP');
 		$this->user_context  = $tmpLDAP->getUserContext();
 		$this->group_context = $tmpLDAP->getGroupContext();
@@ -47,5 +46,5 @@
 		$this->ds = &$GLOBALS['workflow']['workflowObjects']->getLDAP();
 
-		$this->cachedLDAP = new wf_cached_ldap();
+		$this->cachedLDAP = &Factory::getInstance('wf_cached_ldap');
 		$this->cachedLDAP->setOperationMode($this->cachedLDAP->OPERATION_MODE_LDAP);
 	}
Index: sandbox/workflow/trunk/inc/local/classes/class.wf_mail.php
===================================================================
--- sandbox/workflow/trunk/inc/local/classes/class.wf_mail.php	(revision 795)
+++ sandbox/workflow/trunk/inc/local/classes/class.wf_mail.php	(revision 2372)
@@ -39,5 +39,5 @@
 		$requiredConfiguration = array('mail_smtp_profile' => false);
 		$configuration = $GLOBALS['workflow']['wf_runtime']->process->getConfigValues($requiredConfiguration);
-		$bo_emailadmin = CreateObject('emailadmin.bo');
+		$bo_emailadmin = Factory::getInstance('bo');
 		$profileData = $bo_emailadmin->getProfile($configuration['mail_smtp_profile']);
 
Index: sandbox/workflow/trunk/inc/class.workflow_acl.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_acl.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_acl.inc.php	(revision 2372)
@@ -30,5 +30,5 @@
 	function workflow_acl()
 	{
-		parent::so_adminaccess($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		parent::so_adminaccess(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 	}
 
Index: sandbox/workflow/trunk/inc/class.bo_adminaccess.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_adminaccess.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_adminaccess.inc.php	(revision 2372)
@@ -11,8 +11,5 @@
 
 require_once('class.bo_ajaxinterface.inc.php');
-require_once('class.so_adminaccess.inc.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
 require_once(PHPGW_API_INC . SEP . 'common_functions.inc.php');
-require_once(PHPGW_API_INC . SEP . 'class.acl.inc.php');
 
 /**
@@ -43,8 +40,8 @@
 		parent::bo_ajaxinterface();
 
-		if (!$GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($_SESSION['phpgw_info']['workflow']['account_id']))
+		if (!Factory::getInstance('workflow_acl')->checkWorkflowAdmin($_SESSION['phpgw_info']['workflow']['account_id']))
 			exit(serialize(array('error' => 'Você não tem permissão para executar esta operação.')));
 
-		$this->so = new so_adminaccess($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$this->so = &Factory::getInstance('so_adminaccess', Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 	}
 
@@ -57,5 +54,5 @@
 	function get_all_processes()
 	{
-		$proc_mng = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$proc_mng = &Factory::newInstance('ProcessManager');
 		$proc_list = $proc_mng->list_processes(0,-1,'wf_name__ASC');
 
@@ -315,5 +312,5 @@
 	{
 		$GLOBALS['phpgw']->db = $GLOBALS['ajax']->db;
-		$acl = new ACL();
+		$acl = &Factory::getInstance('acl');
 		$output = $this->so->getUserNames($acl->get_ids_for_location('admin_workflow', 1, 'workflow'));
 		unset($GLOBALS['phpgw']->db);
@@ -332,5 +329,5 @@
 		$ids = explode('.', str_replace('g', '', str_replace('u', '', $params['user_ids'])));
 		$GLOBALS['phpgw']->db = $GLOBALS['ajax']->db;
-		$acl = new ACL();
+		$acl = &Factory::getInstance('acl');
 		foreach ($ids as $id)
 			$acl->add_repository('workflow', 'admin_workflow', $id, 1);
@@ -350,5 +347,5 @@
 	{
 		$GLOBALS['phpgw']->db = $GLOBALS['ajax']->db;
-		$acl = new ACL();
+		$acl = &Factory::getInstance('acl');
 		$acl->delete_repository('workflow', 'admin_workflow', (int) $params['admin_id']);
 		unset($GLOBALS['phpgw']->db);
Index: sandbox/workflow/trunk/inc/class.powergraphic.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.powergraphic.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.powergraphic.inc.php	(revision 2372)
@@ -139,7 +139,7 @@
 
 
-
-
-$PowerGraphic = new powergraphic;
+require_once 'common.inc.php';
+
+$PowerGraphic = &Factory::newInstance('powergraphic');
 
 $PowerGraphic->start();
Index: sandbox/workflow/trunk/inc/class.ui_userinterface.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_userinterface.inc.php	(revision 2107)
+++ sandbox/workflow/trunk/inc/class.ui_userinterface.inc.php	(revision 2372)
@@ -45,5 +45,5 @@
 		$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'];
 		$GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$smarty = Factory::getInstance('workflow_smarty');
 
 		// Check if workflow config is ok
@@ -114,8 +114,8 @@
 
 		// Get a connection to db workflow and galaxia (module)
-		if ($GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Error)
+		if (Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Error)
 			$errors[] = 'Unable to connect to database Workflow';
 
-		if ($errormsg = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Error)
+		if ($errormsg = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Error)
 			$errors[] = 'Unable to connect to database Galaxia';
 
@@ -129,7 +129,6 @@
 
 		/* create some objects */
-		require_once 'class.so_userinterface.inc.php';
-		$so = new so_userinterface();
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$so = &Factory::getInstance('so_userinterface');
+		$smarty = &Factory::getInstance('workflow_smarty');
 
 		/* get the user's organization */
Index: sandbox/workflow/trunk/inc/class.bo_move_instances.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_move_instances.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_move_instances.inc.php	(revision 2372)
@@ -12,6 +12,4 @@
 
 require_once('class.bo_ajaxinterface.inc.php');
-require_once('class.so_move_instances.inc.php');
-require_once('nano/JSON.php');
 
 
@@ -39,5 +37,5 @@
 	{
 		parent::bo_ajaxinterface();
-		$this->so = new so_move_instances();
+		$this->so = &Factory::getInstance('so_move_instances');
 	}
 
@@ -79,5 +77,5 @@
 	function moveInstances($params)
 	{
-		$JSON = new Services_JSON();
+		$JSON = &Factory::newInstance('Services_JSON');
 
 		/* convert the mappgin element to array */
Index: sandbox/workflow/trunk/inc/class.TemplateServer.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.TemplateServer.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.TemplateServer.inc.php	(revision 2372)
@@ -99,5 +99,5 @@
 				else
 				{
-					$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareEnvironment();
+					Factory::getInstance('WorkflowMacro')->prepareEnvironment();
 					if (!isset($GLOBALS['phpgw_info']['login_template_set']))
 						return false;
@@ -131,5 +131,5 @@
 				{
 					/* se não for encontrado em nenhuma variável de ambiente, tenta carregar do banco de dados */
-					$webServerURL = (string) $GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID->GetOne('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'webserver_url'));
+					$webServerURL = (string) Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID->GetOne('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'webserver_url'));
 					$this->WEB_WORKFLOW_BASE = str_replace('//', '/', "{$webServerURL}/workflow");
 				}
Index: sandbox/workflow/trunk/inc/class.ui_adminjobs.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_adminjobs.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_adminjobs.inc.php	(revision 2372)
@@ -41,5 +41,5 @@
 			'app_header' => $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Jobs')
 		);
-		$smarty = &$GLOBALS['workflow']['factory']->getInstance('workflow_smarty');
+		$smarty = &Factory::getInstance('workflow_smarty');
 
 		$javaScripts = $this->get_common_js();
@@ -54,5 +54,5 @@
 		$css .= $this->get_css_link('adminjobs');
 
-		$processInfo = $GLOBALS['workflow']['factory']->getInstance('workflow_processmanager')->get_process((int) $_REQUEST['p_id']);
+		$processInfo = Factory::getInstance('workflow_processmanager')->get_process((int) $_REQUEST['p_id']);
 		$smarty->assign('processNameVersion', "{$processInfo['wf_name']} v{$processInfo['wf_version']}");
 		$smarty->assign('processID', (int) $processInfo['wf_p_id']);
Index: sandbox/workflow/trunk/inc/class.workflow_processmanager.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_processmanager.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_processmanager.inc.php	(revision 2372)
@@ -5,7 +5,5 @@
 
 	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'RoleManager.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Process.php');
+
 	/**
 	 * @package Workflow
@@ -26,5 +24,5 @@
 			'database_user',
 			'database_password'
-		); 
+		);
 	   /**
 		 * Constructor
@@ -34,7 +32,7 @@
 		function workflow_processmanager()
 		{
-			parent::ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-			$this->workflow_acl = CreateObject('workflow.workflow_acl');
-			
+			parent::ProcessManager();
+			$this->workflow_acl = Factory::getInstance('workflow_acl');
+
 			/* allow regular users to see the process graph */
 			if ($_GET['menuaction'] == "workflow.ui_adminactivities.show_graph")
@@ -62,5 +60,5 @@
 		function import_process(&$data)
 		{
-			if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
+			if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
 
 			if (parent::import_process($data))
@@ -121,7 +119,7 @@
 		function serialize_process($pId)
 	  	{
-			if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
+			if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
 			if (!isset($this->jobManager))
-				$this->jobManager = new JobManager($this->db);
+				$this->jobManager = &Factory::newInstance('JobManager');
 		
 			//if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
Index: sandbox/workflow/trunk/inc/class.ui_generic_select.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_generic_select.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_generic_select.inc.php	(revision 2372)
@@ -79,5 +79,5 @@
 	function form()
 	{
-		$smarty = $GLOBALS['workflow']['factory']->getInstance('workflow_smarty', false);
+		$smarty = Factory::getInstance('workflow_smarty', false);
 		$smarty->setHeader(workflow_smarty::SHOW_HEADER | workflow_smarty::SHOW_FOOTER);
 
Index: sandbox/workflow/trunk/inc/class.CachedLDAP.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.CachedLDAP.inc.php	(revision 1310)
+++ sandbox/workflow/trunk/inc/class.CachedLDAP.inc.php	(revision 2372)
@@ -97,8 +97,8 @@
 
 		/* load the information and establish a connection */
-		$tmpLDAP = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$tmpLDAP =& Factory::getInstance('WorkflowLDAP');
 		$this->userContext  = $tmpLDAP->getUserContext();
 		$this->groupContext = $tmpLDAP->getGroupContext();
-		$this->dataSource = &$GLOBALS['workflow']['workflowObjects']->getLDAP();
+		$this->dataSource =& Factory::getInstance('WorkflowObjects')->getLDAP();
 	}
 
@@ -115,5 +115,5 @@
 
 		/* establish a connection */
-		$this->DBLink = &$GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID;
+		$this->DBLink =& Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID;
 	}
 
Index: sandbox/workflow/trunk/inc/class.ui_adminprocesses.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_adminprocesses.inc.php	(revision 989)
+++ sandbox/workflow/trunk/inc/class.ui_adminprocesses.inc.php	(revision 2372)
@@ -1,3 +1,4 @@
 <?php
+require_once 'common.inc.php';
 require_once(dirname(__FILE__) . SEP . 'class.bo_workflow_forms.inc.php');
 require_once('engine' . SEP . 'config.egw.inc.php');
@@ -54,5 +55,5 @@
 		parent::bo_workflow_forms('admin_processes');
 
-		$this->workflow_acl = CreateObject('workflow.workflow_acl');
+		$this->workflow_acl = Factory::getInstance('workflow_acl');
 		$denyAccess = true;
 		if ($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
@@ -83,6 +84,6 @@
 		}
 
-		$this->process_manager	= CreateObject('workflow.workflow_processmanager');
-		$this->activity_manager	= CreateObject('workflow.workflow_activitymanager');
+		$this->process_manager	= Factory::getInstance('workflow_processmanager');
+		$this->activity_manager	= Factory::getInstance('workflow_activitymanager');
 
 		$this->form_action = $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminprocesses.form');
@@ -127,5 +128,5 @@
 		}
 
-		if (!$GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
+		if (!Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
 		{
 			$proc_ids = $this->workflow_acl->get_granted_processes($GLOBALS['phpgw_info']['user']['account_id']);
@@ -190,5 +191,5 @@
 		$known_config_items = array_merge($known_config_items, array('Log Options' => 'title', 'log_level' => $log_levels));
 
-		$bo_agent = CreateObject('workflow.bo_agent_mail_smtp');
+		$bo_agent = Factory::getInstance('bo_agent_mail_smtp');
 		$known_config_items = array_merge($known_config_items, $bo_agent->listProcessConfigurationFields());
 
@@ -589,5 +590,5 @@
 
 			$myp_id = $item['wf_p_id'];
-			$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+			$templateServer = &Factory::getInstance('TemplateServer');
 			$this->t->set_var(array(
 				'item_wf_p_id'		=> $myp_id,
Index: sandbox/workflow/trunk/inc/class.so_move_instances.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_move_instances.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.so_move_instances.inc.php	(revision 2372)
@@ -11,6 +11,4 @@
 \**************************************************************************/
 
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
 
 /**
@@ -91,6 +89,6 @@
 		$this->userID = $_SESSION['phpgw_info']['workflow']['account_id'];
 		$this->isAdmin = $_SESSION['phpgw_info']['workflow']['user_is_admin'];
-		$this->acl = &$GLOBALS['ajax']->acl;
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID;
+		$this->acl =& $GLOBALS['ajax']->acl;
+		$this->db =& Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID;
 	}
 
@@ -113,5 +111,5 @@
 				$where[] = 'wf_p_id IS NULL';
 		}
-		$processManager = new ProcessManager($this->db);
+		$processManager = &Factory::getInstance('ProcessManager', $this->db);
 
 		/* workaround to sort the result using two columns */
@@ -137,5 +135,5 @@
 		$this->_checkAccess($processID);
 
-		$activityManager = new ActivityManager($this->db);
+		$activityManager = &Factory::newInstance('ActivityManager');
 		$activities = $activityManager->list_activities($processID, 0, -1, 'wf_name__ASC', '', 'wf_type <> \'standalone\' AND wf_type <> \'view\'');
 		$output = array();
Index: sandbox/workflow/trunk/inc/class.workflow_activitymanager.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_activitymanager.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_activitymanager.inc.php	(revision 2372)
@@ -5,7 +5,4 @@
 
 	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'GraphViz.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'common' . SEP . 'WfSecurity.php');
 	/**
 	 * @package Workflow
@@ -20,5 +17,5 @@
 		function workflow_activitymanager()
 		{
-			parent::ActivityManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::ActivityManager(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.WorkflowObjects.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.WorkflowObjects.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.WorkflowObjects.inc.php	(revision 2372)
@@ -87,5 +87,5 @@
 			{
 				/* connect to the database */
-				$this->cache['DBGalaxia'] = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $GLOBALS['workflow']['factory']->newForeignInstance('phpgwapi', 'db'));
+				$this->cache['DBGalaxia'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
 				$this->cache['DBGalaxia']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */
 				$this->cache['DBGalaxia']->Halt_On_Error = 'no';
@@ -98,6 +98,6 @@
 					$dbConfigValues['workflow_database_type']
 				);
-				$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']);
-				$this->cache['DBGalaxia']->Link_ID = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $this->cache['DBGalaxia']->Link_ID);
+				Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']);
+				$this->cache['DBGalaxia']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBGalaxia']->Link_ID);
 			}
 			else
@@ -128,5 +128,5 @@
 			if (!isset($connectionInfo['db_name']))
 			{
-				$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareEnvironment();
+				Factory::getInstance('WorkflowMacro')->prepareEnvironment();
 				if (isset($GLOBALS['phpgw_info']['server']))
 					$connectionInfo = $GLOBALS['phpgw_info']['server'];
@@ -136,5 +136,5 @@
 
 			/* connect to the database */
-			$this->cache['DBExpresso'] = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $GLOBALS['workflow']['factory']->newForeignInstance('phpgwapi', 'db'));
+			$this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
 			$this->cache['DBExpresso']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */
 			$this->cache['DBExpresso']->Halt_On_Error = 'no';
@@ -147,6 +147,6 @@
 				$connectionInfo['db_type']
 			);
-			$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']);
-			$this->cache['DBExpresso']->Link_ID = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $this->cache['DBExpresso']->Link_ID);
+			Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']);
+			$this->cache['DBExpresso']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBExpresso']->Link_ID);
 		}
 
@@ -177,5 +177,5 @@
 
 			/* connect to the database */
-			$this->cache['DBWorkflow'] = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $GLOBALS['workflow']['factory']->newForeignInstance('phpgwapi', 'db'));
+			$this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
 			$this->cache['DBWorkflow']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */
 			$this->cache['DBWorkflow']->Halt_On_Error = 'no';
@@ -188,6 +188,6 @@
 				$dbConfigValues['database_type']
 			);
-			$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']);
-			$this->cache['DBWorkflow']->Link_ID = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $this->cache['DBWorkflow']->Link_ID);
+			Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']);
+			$this->cache['DBWorkflow']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBWorkflow']->Link_ID);
 		}
 
Index: sandbox/workflow/trunk/inc/class.bo_ajaxinterface.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_ajaxinterface.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_ajaxinterface.inc.php	(revision 2372)
@@ -36,9 +36,6 @@
 
 require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'common.inc.php');
-require_once(PHPGW_API_INC . SEP . 'class.db.inc.php');
-require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'engine' . SEP . 'class.ajax_ldap.inc.php');
 require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'engine' . SEP . 'class.ajax_config.inc.php');
 require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'engine' . SEP . 'config.ajax.inc.php');
-require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'class.so_adminaccess.inc.php');
 
 /**
@@ -66,13 +63,13 @@
 		if (isset($_SESSION['phpgw_info']['workflow']['account_id']))
 		{
-			$GLOBALS['ajax']->ldap = new ajax_ldap();
-			$GLOBALS['ajax']->db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
+			$GLOBALS['ajax']->ldap = &Factory::getInstance('ajax_ldap');
+			$GLOBALS['ajax']->db =& Factory::getInstance('WorkflowObjects')->getDBExpresso();
 			$GLOBALS['ajax']->db->Halt_On_Error = 'no';
 
-			$GLOBALS['ajax']->db_workflow = &$GLOBALS['workflow']['workflowObjects']->getDBWorkflow();
+			$GLOBALS['ajax']->db_workflow =& Factory::getInstance('WorkflowObjects')->getDBWorkflow();
 			$GLOBALS['ajax']->db_workflow->Halt_On_Error = 'no';
 
 			$GLOBALS['phpgw']->ADOdb = &$GLOBALS['ajax']->db->Link_ID;
-			$GLOBALS['ajax']->acl = new so_adminaccess($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			$GLOBALS['ajax']->acl = &Factory::getInstance('so_adminaccess', Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 		else
Index: sandbox/workflow/trunk/inc/class.ui_external_applications.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_external_applications.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_external_applications.inc.php	(revision 2372)
@@ -49,5 +49,5 @@
 	function draw()
 	{
-		if (!$GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
+		if (!Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
 		{
 			$GLOBALS['phpgw']->common->phpgw_header();
@@ -61,5 +61,5 @@
 		$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'];
 		$GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$smarty = Factory::getInstance('workflow_smarty');
 
 		$this->set_wf_session();
Index: sandbox/workflow/trunk/inc/class.UserPictureProvider.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.UserPictureProvider.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.UserPictureProvider.inc.php	(revision 2372)
@@ -114,5 +114,5 @@
 					/* em último caso, tenta buscar a informação em banco de dados */
 					/* prepara o ambiente para a carga de informações sobre o banco de dados */
-					$result = $GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir'));
+					$result = Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir'));
 					if (empty($result))
 						return;
@@ -141,5 +141,5 @@
 				mkdir($baseDirectory, 0770, true);
 
-			$contents = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getUserPicture($this->userID);
+			$contents = Factory::getInstance('WorkflowLDAP')->getUserPicture($this->userID);
 			$success = true;
 			if ($contents !== false)
@@ -165,5 +165,5 @@
 		}
 
-		$GLOBALS['workflow']['factory']->getInstance('ResourcesRedirector')->show($filename);
+		Factory::getInstance('ResourcesRedirector')->show($filename);
 	}
 }
Index: sandbox/workflow/trunk/inc/class.workflow_rolemanager.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_rolemanager.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_rolemanager.inc.php	(revision 2372)
@@ -17,5 +17,5 @@
 		function workflow_rolemanager()
 		{
-			parent::RoleManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::RoleManager(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.so_agent.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_agent.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.so_agent.inc.php	(revision 2372)
@@ -26,8 +26,8 @@
 {
 	//public functions
-	
+
 	/**
 	 * @var array $public_functions Array of public functions
-	 * @access public 
+	 * @access public
 	 */
 	var $public_functions = array(
@@ -36,34 +36,34 @@
 	);
 	/**
-	 * @var array $wf_table 
+	 * @var array $wf_table
 	 * @access public
 	 */
 	var $wf_table = 'egw_wf_agent_';
 	/**
-	 * @var string $agent_table 
+	 * @var string $agent_table
 	 * @access public
 	 */
 	var $agent_table = '';
-	
+
 	// link to the global db-object
-	
+
 	/**
-	 * @var object $db objeto para conexao do banco de dados 
+	 * @var object $db objeto para conexao do banco de dados
 	 * @access public
 	 */
 	var $db;
-	
+
 	/**
 	 * Constructor of the so_agent class
 	 * do not forget to call it (parent::so_agent();) in child classes
 	 * @access public
-	 * @return object 
+	 * @return object
 	 */
-	
+
 	function so_agent()
 	{
-		$this->db =& $GLOBALS['workflow']['workflowObjects']->getDBGalaxia();
+		$this->db =& Factory::getInstance('WorkflowObjects')->getDBGalaxia();
 	}
-	
+
 	/**
 	 * @abstract read all agent datas from the database
Index: sandbox/workflow/trunk/inc/class.bo_workflow_forms.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_workflow_forms.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_workflow_forms.inc.php	(revision 2372)
@@ -90,5 +90,5 @@
 			$this->sort_mode	= $this->order . '__' . $this->sort;
 			$this->search_str	= get_var('find', 'any', '');
-			$this->nextmatchs	= CreateObject('phpgwapi.nextmatchs');
+			$this->nextmatchs	= Factory::getInstance('nextmatchs');
 			
 			// number of rows allowed
Index: sandbox/workflow/trunk/inc/class.WorkflowSecurity.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.WorkflowSecurity.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.WorkflowSecurity.inc.php	(revision 2372)
@@ -51,5 +51,5 @@
 	{
 		/* garante que o objeto de DataBase do Expresso estará disponível */
-		$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
+		Factory::getInstance('WorkflowObjects')->getDBExpresso();
 	}
 
@@ -77,5 +77,5 @@
 				continue;
 			$this->removeSensitiveInformationFromDatabaseObject($variable);
-			$variable = $GLOBALS['workflow']['factory']->newInstance('WorkflowWatcher', $variable);
+			$variable = Factory::newInstance('WorkflowWatcher', $variable);
 		}
 	}
Index: sandbox/workflow/trunk/inc/engine/config.egw.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/config.egw.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/config.egw.inc.php	(revision 2372)
@@ -151,5 +151,5 @@
 	function galaxia_user_can_admin_process()
 	{
-		return ($GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow'));
+		return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow'));
 	}
 }
@@ -165,5 +165,5 @@
 	function galaxia_user_can_admin_instance()
 	{
-		return ($GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('admin_instance_workflow', 1, 'workflow'));
+		return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('admin_instance_workflow', 1, 'workflow'));
 	}
 }
@@ -179,5 +179,5 @@
 	function galaxia_user_can_clean_instances()
 	{
-		return ($GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('cleanup_workflow', 1, 'workflow'));
+		return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('cleanup_workflow', 1, 'workflow'));
 	}
 }
@@ -191,5 +191,5 @@
 	function galaxia_user_can_clean_aborted_instances()
 	{
-		return ($GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('cleanup_aborted_workflow', 1, 'workflow'));
+		return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('cleanup_aborted_workflow', 1, 'workflow'));
 	}
 }
@@ -203,5 +203,5 @@
 	function galaxia_user_can_monitor()
 	{
-		return ($GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('monitor_workflow', 1, 'workflow'));
+		return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('monitor_workflow', 1, 'workflow'));
 	}
 }
@@ -221,5 +221,5 @@
 				$user = $GLOBALS['phpgw_info']['user']['account_id'];
 
-			$memberships = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getUserGroups($user);
+			$memberships = Factory::getInstance('WorkflowLDAP')->getUserGroups($user);
 
 			if ($memberships === false)
@@ -245,5 +245,5 @@
 		{
 			/* get information regarding the members of the group */
-			$members = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getGroupUsers($group);
+			$members = &Factory::getInstance('WorkflowLDAP')->getGroupUsers($group);
 
 			/* checl for error in the LDAP query */
@@ -305,5 +305,5 @@
 		{
 			// This way we create a new run_activity instance for the next activity
-			$run_activity = CreateObject('workflow.run_activity.go');
+			$run_activity = Factory::getInstance('run_activity');
 			$data = $run_activity->go($activityId, $iid, $auto);
 			return $data;
@@ -325,5 +325,5 @@
 	function galaxia_get_config_values($parameters=array())
 	{
-			$config = CreateObject('phpgwapi.config');
+			$config = Factory::getInstance('config');
 			$config->read_repository();
 
Index: sandbox/workflow/trunk/inc/engine/class.ajax_ldap.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/class.ajax_ldap.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/class.ajax_ldap.inc.php	(revision 2372)
@@ -29,9 +29,9 @@
 	function ajax_ldap()
 	{
-		$tmpLDAP = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$tmpLDAP = &Factory::getInstance('WorkflowLDAP');
 		$this->user_context  = $tmpLDAP->getUserContext();
 		$this->group_context = $tmpLDAP->getGroupContext();
 
-		$this->ds = &$GLOBALS['workflow']['workflowObjects']->getLDAP();
+		$this->ds =& Factory::getInstance('WorkflowObjects')->getLDAP();
 	}
 
@@ -83,5 +83,5 @@
 	function id2fullname($account_id)
     {
-		return $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($account_id);
+		return Factory::getInstance('WorkflowLDAP')->getName($account_id);
     }
 
@@ -107,5 +107,5 @@
 			$accountID = $_SESSION['phpgw_info']['workflow']['account_id'];
 
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap =& Factory::getInstance('WorkflowLDAP');
 		if (count($output = $ldap->getUserGroups($accountID)) == 0)
 			return false;
Index: sandbox/workflow/trunk/inc/engine/config.ajax.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/config.ajax.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/config.ajax.inc.php	(revision 2372)
@@ -170,5 +170,5 @@
 		if ($loadGroups)
 		{
-			$memberships = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getUserGroups($user);
+			$memberships = Factory::getInstance('WorkflowLDAP')->getUserGroups($user);
 			if ($user == $_SESSION['phpgw_info']['workflow']['account_id'])
 				$_SESSION['phpgw_info']['workflow']['user_groups'] = $memberships;
@@ -196,5 +196,5 @@
 		{
 			/* get information regarding the members of the group */
-			$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+			$ldap = &Factory::getInstance('WorkflowLDAP');
 			$members = $ldap->getGroupUsers($group);
 
@@ -256,5 +256,5 @@
 	function galaxia_get_config_values($parameters=array())
 	{
-			$config = new ajax_config();
+			$config = &Factory::getInstance('ajax_config');
 			$config->read_repository();
 
Index: sandbox/workflow/trunk/inc/engine/src/GUI/GUI.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/GUI/GUI.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/GUI/GUI.php	(revision 2372)
@@ -32,10 +32,9 @@
    * @access public
    */
-  function GUI(&$db) 
+  function GUI()
   {
     $this->child_name = 'GUI';
-    parent::Base($db);
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'WfSecurity.php');
-    $this->wf_security =& new WfSecurity($this->db); 
+    parent::Base();
+    $this->wf_security = &Factory::getInstance('WfSecurity');
   }
 
@@ -703,6 +702,5 @@
       if (!(isset($this->pm)))
       {
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'ProcessManager'.SEP.'ProcessManager.php');
-        $this->pm =& new ProcessManager($this->db);
+        $this->pm = &Factory::newInstance('ProcessManager');
       }
       $this->process_cache[$pId]['view'] = $this->pm->get_process_view_activity($pId);
@@ -871,5 +869,5 @@
     {
       //the security object said everything was fine
-      $instance = new Instance($this->db);
+      $instance = &Factory::newInstance('Instance');
       $instance->getInstance($instanceId);
       if (!empty($instance->instanceId)) 
@@ -975,5 +973,5 @@
     {
       //the security object said everything was fine
-      $instance =& new Instance($this->db);
+      $instance = &Factory::newInstance('Instance');
       $instance->getInstance($instanceId);
       // we force the execution of the activity
@@ -1012,5 +1010,5 @@
     {
       //the security object said everything was fine
-      $instance =& new Instance($this->db);
+      $instance = &Factory::newInstance('Instance');
       $instance->getInstance($instanceId);
       // we force the continuation of the flow
Index: sandbox/workflow/trunk/inc/engine/src/ProcessMonitor/ProcessMonitor.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessMonitor/ProcessMonitor.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessMonitor/ProcessMonitor.php	(revision 2372)
@@ -18,8 +18,8 @@
    * @access public
    */
-  function ProcessMonitor(&$db)
+  function ProcessMonitor()
   {
     $this->child_name = 'ProcessMonitor';
-    parent::Base($db);
+    parent::Base();
     // check the the actual user can really do this
     if ( !(galaxia_user_can_monitor()))
Index: sandbox/workflow/trunk/inc/engine/src/common/Base.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/common/Base.php	(revision 2165)
+++ sandbox/workflow/trunk/inc/engine/src/common/Base.php	(revision 2372)
@@ -39,4 +39,12 @@
   	var $child_name = 'Base';
 
+	/**
+	 * @var object $db_shared_obj The database abstraction object shared between
+	 *						      all instances of this class.
+	 * @acess private
+	 * @static
+	 */
+	private static $db_shared_obj = null;
+
   /**
    * Constructor receiving a database abstraction object
@@ -46,14 +54,34 @@
    * @access public
    */
-  function Base(&$db)
+  function Base()
   {
-    if(!$db) {
+  	/**
+	 * New Stuff!
+	 * We decided to get here the database object. In a recent past,
+	 * all the classes that specialize this one passed a db object.
+	 * Now, to simplify and save memory, we store the database object
+	 * into a single and static atribute shared among each instance
+	 * of this class.
+	 *
+	 * To prevent to modify all sub-classes to use "self::$db" instead
+	 * of "this->db", we made a very tiny workaround here. In the first
+	 * instantiation of this class, we instantiate the database object
+	 * and store it into 'self::$db_shared_obj'. Any subsequent
+	 * instantiations will just point to the static one.
+	 */
+	if (!self::$db_shared_obj)
+		self::$db_shared_obj = &Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID;
+
+	$this->db = &self::$db_shared_obj;
+
+
+    if(!$this->db) {
       die('Invalid db object passed to '.$this->child_name.' constructor');
     }
     //Force transactionnal mysql (Innodb) -> mysqlt
-    if ($db->databaseType=='mysql')
+    if ($this->db->databaseType=='mysql')
     {
     	$GLOBALS['phpgw']->db->disconnect();
-    	$db = $GLOBALS['phpgw']->db->connect(
+    	$this->db = $GLOBALS['phpgw']->db->connect(
 			$GLOBALS['phpgw_info']['server']['db_name'],
 			$GLOBALS['phpgw_info']['server']['db_host'],
@@ -64,5 +92,4 @@
 		);
     }
-    $this->db = &$db;
   }
 
Index: sandbox/workflow/trunk/inc/engine/src/common/WfRuntime.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/common/WfRuntime.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/common/WfRuntime.php	(revision 2372)
@@ -86,18 +86,14 @@
    * @access public
    */
-  function WfRuntime(&$db) 
+  function WfRuntime() 
   {
     $this->child_name = 'WfRuntime';
-    parent::Base($db);
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'BaseActivity.php');
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'Process.php');
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'Instance.php');
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'WfSecurity.php');
-    
+    parent::Base();
+
     //first the activity is not set
     $this->activity = null;
-    $this->instance = new Instance($this->db);
-    $this->process = new Process($this->db);
-    $this->security = new WfSecurity($this->db); 
+    $this->instance = &Factory::newInstance('Instance');
+    $this->process = &Factory::newInstance('Process');
+    $this->security = &Factory::getInstance('WfSecurity');
   }
 
@@ -276,5 +272,5 @@
       return false;
     }
-    $base_activity = new BaseActivity($this->db);
+    $base_activity = &Factory::newInstance('BaseActivity');
     $this->activity =& $base_activity->getActivity($activity_id, $with_roles, $with_agents);
     if (!$this->activity)
@@ -1091,5 +1087,5 @@
     $workflow = $GLOBALS['workflow'];
     unset($_REQUEST['iid']);
-    $run_activity = CreateObject('workflow.run_activity');
+    $run_activity = Factory::getInstance('run_activity');
     $run_activity->runtime->instance->parentInstanceId = $this->instance_id;
     $run_activity->runtime->instance->parentActivityId = $this->activity_id;
Index: sandbox/workflow/trunk/inc/engine/src/common/WfSecurity.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/common/WfSecurity.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/common/WfSecurity.php	(revision 2372)
@@ -23,11 +23,8 @@
    * @access public
    */
-  function WfSecurity(&$db) 
+  function WfSecurity() 
   {
     $this->child_name = 'WfSecurity';
-    parent::Base($db);
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'Instance.php');
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'Process.php');
-    require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'BaseActivity.php');
+    parent::Base();
   }
 
@@ -58,5 +55,5 @@
       );
       //check theses values for this process and store the result for this object life duration
-      $myProcess = new Process($this->db);
+      $myProcess = &Factory::newInstance('Process');
       $myProcess->getProcess($pId);
       $this->processesConfig[$pId] = $myProcess->getConfigValues($arrayConf);
@@ -78,4 +75,9 @@
   function checkUserAccess($user, $activity_id, $readonly=false) 
   {
+	/* if activity is non-interactive is not necessary checking user access */
+	$activity = &Factory::getInstance('BaseActivity')->getActivity($activity_id);
+	if (!$activity->isInteractive())
+		return true;
+
     //group mapping, warning groups and user can have the same id
     if ($user[0] != 'p')
@@ -577,6 +579,5 @@
       if (!(isset($this->pm)))
       {
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'ProcessManager'.SEP.'ProcessManager.php');
-        $this->pm = new ProcessManager($this->db);
+        $this->pm = &Factory::newInstance('ProcessManager');
       }
       //$this->error[] = 'DEBUG: checking to see if there is no view activities on process :'.$pId.':'.$this->pm->get_process_view_activity($pId);
Index: sandbox/workflow/trunk/inc/engine/src/API/Process.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/Process.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/Process.php	(revision 2372)
@@ -48,8 +48,8 @@
 	 * @access public
 	 */
-	function Process(&$db) 
+	function Process() 
 	{
 		$this->child_name = 'Process';
-		parent::Base($db);
+		parent::Base();
 	}
 
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/View.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/View.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/View.php	(revision 2372)
@@ -16,7 +16,7 @@
 	 * @access public
 	 */	
-	function View(&$db)
+	function View()
 	{
-	 	parent::Base($db);
+	 	parent::Base();
 		$this->child_name = 'View';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/Split.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/Split.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/Split.php	(revision 2372)
@@ -15,7 +15,7 @@
 	 * @access public
 	 */
-	function Split(&$db)
+	function Split()
 	{
-	 	parent::Base($db);
+	 	parent::Base();
 		$this->child_name = 'Split';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/Activity.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/Activity.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/Activity.php	(revision 2372)
@@ -16,7 +16,7 @@
 	 * @access public
 	 */
-	function Activity(&$db)
+	function Activity()
 	{
-		parent::Base($db);
+		parent::Base();
 		$this->child_name = 'Activity';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/Start.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/Start.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/Start.php	(revision 2372)
@@ -15,7 +15,7 @@
 	 * @access public
 	 */
-	function Start(&$db)
+	function Start()
 	{
-	 	parent::Base($db);
+	 	parent::Base();
 		$this->child_name = 'Start';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/SwitchActivity.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/SwitchActivity.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/SwitchActivity.php	(revision 2372)
@@ -16,7 +16,7 @@
 	 * @access public
 	 */
-	function SwitchActivity(&$db)
+	function SwitchActivity()
 	{
-	   parent::Base($db);
+	   parent::Base();
 	   $this->child_name = 'Switch';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/Join.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/Join.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/Join.php	(revision 2372)
@@ -15,7 +15,7 @@
 	 * @access public
 	 */
-	function Join(&$db)
+	function Join()
 	{
-	 	parent::Base($db);
+	 	parent::Base();
 		$this->child_name = 'Join';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/End.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/End.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/End.php	(revision 2372)
@@ -15,7 +15,7 @@
 	 * @access public
 	 */
-	function End(&$db)
+	function End()
 	{
-	 	parent::Base($db);
+	 	parent::Base();
 		$this->child_name = 'End';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/activities/Standalone.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/activities/Standalone.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/activities/Standalone.php	(revision 2372)
@@ -15,7 +15,7 @@
 	 * @access public
 	 */
-	function Standalone(&$db)
+	function Standalone()
 	{
-	 	parent::Base($db);
+	 	parent::Base();
 		$this->child_name = 'Standalone';
 	}
Index: sandbox/workflow/trunk/inc/engine/src/API/Instance.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/Instance.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/Instance.php	(revision 2372)
@@ -1,5 +1,4 @@
 <?php
 require_once (GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'common' . SEP . 'WfSecurity.php');
 require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
 
@@ -141,8 +140,8 @@
 
   var $activityID = null;
-  function Instance($db) 
+  function Instance() 
   {
     $this->child_name = 'Instance';
-    parent::Base($db);
+    parent::Base();
   }
 
@@ -1171,5 +1170,5 @@
     
     //lock rows and ensure access is granted
-    if (!(isset($this->security))) $this->security =& new WfSecurity($this->db); 
+    if (!(isset($this->security))) $this->security = &Factory::getInstance('WfSecurity', $this->db);
     if (!($this->security->checkUserAction($activityId,$this->instanceId,'complete')))
     {
@@ -1551,5 +1550,5 @@
     {
       //we check rights for this user on the next activity
-      if (!(isset($this->security))) $this->security =& new WfSecurity($this->db); 
+      if (!(isset($this->security))) $this->security = &Factory::getInstance('WfSecurity');
       if ($this->security->checkUserAccess($the_next_user,$activityId))
       {
@@ -1560,5 +1559,5 @@
     {
       // then check to see if there is a default user
-      $activity_manager =& new ActivityManager($this->db);
+      $activity_manager = &Factory::newInstance('ActivityManager');
       //get_default_user will give us '*' if there is no default_user or if the default user has no role
       //mapped anymore
Index: sandbox/workflow/trunk/inc/engine/src/API/BaseActivity.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/API/BaseActivity.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/API/BaseActivity.php	(revision 2372)
@@ -97,9 +97,9 @@
    * @access public
    */
-  function BaseActivity(&$db)
+  function BaseActivity()
   {
     $this->type='base';
     $this->child_name = 'BaseActivity';
-    parent::Base($db);
+    parent::Base();
   }
 
@@ -122,41 +122,42 @@
     if(!$result || !$result->numRows() ) return false;
     $res = $result->fetchRow();
+
     switch($res['wf_type']) {
       case 'start':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Start.php');
-        $act = new Start($this->db);  
-        break;
+        $act = &Factory::newInstance('Start');
+        break;
+
       case 'end':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'End.php');
-        $act = new End($this->db);
-        break;
+        $act = &Factory::newInstance('End');
+        break;
+
       case 'join':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Join.php');
-        $act = new Join($this->db);
-        break;
+        $act = &Factory::newInstance('Join');
+        break;
+
       case 'split':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Split.php');
-        $act = new Split($this->db);
-        break;
+        $act = &Factory::newInstance('Split');
+        break;
+
       case 'standalone':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Standalone.php');
-        $act = new Standalone($this->db);
-        break;
+        $act = &Factory::newInstance('Standalone');
+        break;
+
       case 'view':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'View.php');
-        $act = new View($this->db);
-        break;
+        $act = &Factory::newInstance('View');
+        break;
+
       case 'switch':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'SwitchActivity.php');
-        $act = new SwitchActivity($this->db);
-        break;
+        $act = &Factory::newInstance('SwitchActivity');
+        break;
+
       case 'activity':
-        require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Activity.php');
-        $act = new Activity($this->db);
-        break;
+        $act = &Factory::newInstance('Activity');
+        break;
+
       default:
         trigger_error('Unknown activity type:'.$res['wf_type'],E_USER_WARNING);
     }
-    
+
     $act->setName($res['wf_name']);
     $act->setProcessId($res['wf_p_id']);
Index: sandbox/workflow/trunk/inc/engine/src/ProcessManager/ProcessManager.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessManager/ProcessManager.php	(revision 2165)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessManager/ProcessManager.php	(revision 2372)
@@ -66,10 +66,8 @@
 	 * @access public
 	 */
-	function ProcessManager(&$db)
-	{
-		parent::BaseManager($db);
+	function ProcessManager()
+	{
+		parent::BaseManager();
 		$this->child_name = 'ProcessManager';
-		require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'ProcessManager'.SEP.'ActivityManager.php');
-		require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'ProcessManager'.SEP.'JobManager.php');
 		// $this->activity_manager is not set here to avoid objects loading object A loading object B loading object A, etc
 		//$this->role_manager will only be loaded when needed as well
@@ -131,5 +129,5 @@
 	function serialize_process($pId)
 	{
-		if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
+		if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
 		// <process>
 		$out = '<process>'."\n";
@@ -459,8 +457,8 @@
 	{
 		//Now the show begins
-		if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
-		if (!(isset($this->role_manager))) $this->role_manager = new RoleManager($this->db);
+		if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
+		if (!(isset($this->role_manager))) $this->role_manager = &Factory::newInstance('RoleManager');
 		if (!isset($this->jobManager))
-			$this->jobManager = new JobManager($this->db);
+			$this->jobManager = &Factory::newInstance('JobManager');
 
 		// First create the process. Always inactive and inactive first.
@@ -620,5 +618,5 @@
 	function new_process_version($pId, $minor=true)
 	{
-		if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
+		if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
 		$oldpid = $pId;
 		//retrieve process info with config rows
@@ -671,5 +669,5 @@
 		}
 		// create roles
-		if (!(isset($this->role_manager))) $this->role_manager = new RoleManager($this->db);
+		if (!(isset($this->role_manager))) $this->role_manager = &Factory::newInstance('RoleManager');
 		$query = 'select * from '.GALAXIA_TABLE_PREFIX.'roles where wf_p_id=?';
 		$result = $this->query($query, array($oldpid));
@@ -853,7 +851,7 @@
 	function remove_process($pId)
 	{
-		if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
+		if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
 		if (!isset($this->jobManager))
-			$this->jobManager = new JobManager($this->db);
+			$this->jobManager = &Factory::newInstance('JobManager');
 		$this->deactivate_process($pId);
 		$name = $this->_get_normalized_name($pId);
@@ -919,5 +917,5 @@
 	function replace_process($pId, &$vars, $create = true)
 	{
-		if (!(isset($this->activity_manager)))  $this->activity_manager = new ActivityManager($this->db);
+		if (!(isset($this->activity_manager)))  $this->activity_manager = &Factory::newInstance('ActivityManager');
 		$TABLE_NAME = GALAXIA_TABLE_PREFIX.'processes';
 		$now = date("U");
@@ -1296,5 +1294,5 @@
 		{
 			//Warning: this means you have to include the Process.php from the API
-			$this->Process = new Process($this->db);
+			$this->Process = &Factory::newInstance('Process');
 			$this->Process->getProcess($pId);
 			$result_array = $this->Process->getConfigValues($config_array);
@@ -1316,5 +1314,5 @@
 	{
 		//Warning: this means you have to include the Process.php from the API
-		$this->Process = new Process($this->db);
+		$this->Process = &Factory::newInstance('Process');
 		$this->Process->getProcess($pId);
 		$this->Process->setConfigValues($config_array);
Index: sandbox/workflow/trunk/inc/engine/src/ProcessManager/RoleManager.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessManager/RoleManager.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessManager/RoleManager.php	(revision 2372)
@@ -19,7 +19,7 @@
    * @access public
    */
-  function RoleManager(&$db) 
-  {
-    parent::Base($db);
+  function RoleManager() 
+  {
+    parent::Base();
     $this->child_name = 'RoleManager';
   }
@@ -247,5 +247,5 @@
     $result = $this->query($query,$bindvars);
     $ret = Array();
-    $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+    $ldap = &Factory::getInstance('WorkflowLDAP');
     if (!(empty($result)))
     {
@@ -256,8 +256,10 @@
           //we have a group instead of a simple user and we want real users
           $real_users = galaxia_retrieve_group_users($res['wf_user'], true);
-          foreach ($real_users as $key => $value)
-          {
-            $ret[$key]=$value;
-          }
+		  if (!empty($real_users)) {
+            foreach ($real_users as $key => $value)
+            {
+              $ret[$key]=$value;
+            }
+		  }
         }
         else
Index: sandbox/workflow/trunk/inc/engine/src/ProcessManager/InstanceManager.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessManager/InstanceManager.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessManager/InstanceManager.php	(revision 2372)
@@ -16,7 +16,7 @@
    * @access public
    */
-  function InstanceManager(&$db) 
-  {
-    parent::BaseManager($db);
+  function InstanceManager() 
+  {
+    parent::BaseManager();
     $this->child_name = 'InstanceManager';
   }
Index: sandbox/workflow/trunk/inc/engine/src/ProcessManager/BaseManager.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessManager/BaseManager.php	(revision 2165)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessManager/BaseManager.php	(revision 2372)
@@ -18,8 +18,8 @@
    * @access public
    */
-  function BaseManager(&$db)
+  function BaseManager()
   {
     $this->child_name = 'BaseManager';
-    parent::Base($db);
+    parent::Base();
   }
 
Index: sandbox/workflow/trunk/inc/engine/src/ProcessManager/JobManager.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessManager/JobManager.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessManager/JobManager.php	(revision 2372)
@@ -76,12 +76,12 @@
 	 * @access public
 	 */
-	public function JobManager(&$db)
-	{
-		parent::BaseManager($db);
+	public function JobManager()
+	{
+		parent::BaseManager();
 		$this->child_name = 'JobManager';
 
 		$this->jobTable = GALAXIA_TABLE_PREFIX . 'jobs';
 		$this->logTable = GALAXIA_TABLE_PREFIX . 'job_logs';
-		$this->processManager = new ProcessManager($this->db);
+		$this->processManager = &Factory::newInstance('ProcessManager');
 	}
 
Index: sandbox/workflow/trunk/inc/engine/src/ProcessManager/ActivityManager.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/src/ProcessManager/ActivityManager.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/src/ProcessManager/ActivityManager.php	(revision 2372)
@@ -26,7 +26,7 @@
    * @access public
    */
-  function ActivityManager(&$db)
-  {
-    parent::BaseManager($db);
+  function ActivityManager()
+  {
+    parent::BaseManager();
     $this->child_name = 'ActivityManager';
     require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'ProcessManager' .SEP . 'ProcessManager.php');
@@ -370,9 +370,9 @@
   function build_process_graph($pId)
   {
-    if (!(isset($this->process_manager))) $this->process_manager = new ProcessManager($this->db);
+    if (!(isset($this->process_manager))) $this->process_manager = &Factory::newInstance('ProcessManager');
     $attributes = Array(
     
     );
-    $graph = new Process_GraphViz(true,$attributes);
+    $graph = &Factory::newInstance('Process_GraphViz', true, $attributes);
     $name = $this->process_manager->_get_normalized_name($pId);
     $graph->set_pid($name);
@@ -747,5 +747,5 @@
   {
     require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP . 'BaseActivity.php');
-    $act = new BaseActivity($this->db);
+    $act = &Factory::newInstance('BaseActivity');
     //Warning, we now use the BaseActivity object for it, interactivity and autorouting is now true/fales, not y/n
     return ($act->getActivity($activityId,false,true, true));
@@ -825,5 +825,5 @@
   function remove_activity($pId, $activityId, $transaction = true)
   {
-    if (!(isset($this->process_manager))) $this->process_manager = new ProcessManager($this->db);
+    if (!(isset($this->process_manager))) $this->process_manager = &Factory::newInstance('ProcessManager');
     $proc_info = $this->process_manager->get_process($pId);
     $actname = $this->_get_normalized_name($activityId);
@@ -888,5 +888,5 @@
   function replace_activity($pId, $activityId, $vars, $create_files=true)
   {
-    if (!(isset($this->process_manager))) $this->process_manager = new ProcessManager($this->db);
+    if (!(isset($this->process_manager))) $this->process_manager = &Factory::newInstance('ProcessManager');
     $TABLE_NAME = GALAXIA_TABLE_PREFIX.'activities';
     $now = date("U");
@@ -1195,5 +1195,5 @@
     elseif ( (!($result=='*')) && $performAccessCheck)
     {
-      $wf_security = new WfSecurity($this->db);
+      $wf_security = &Factory::getInstance('WfSecurity', $this->db);
       // perform the check
       if (!($wf_security->checkUserAccess($result,$activityId)))
Index: sandbox/workflow/trunk/inc/engine/class.ajax_config.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/engine/class.ajax_config.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/engine/class.ajax_config.inc.php	(revision 2372)
@@ -45,5 +45,5 @@
 		}
 
-		$this->db      = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
+		$this->db      =& Factory::getInstance('WorkflowObjects')->getDBExpresso();
 		$this->appname = $appname;
   	}
@@ -51,5 +51,5 @@
  	/**
    	* Reads the whole repository for $this->appname, appname has to be set via the constructor
-   	* 
+   	*
    	* @return array the whole config-array for that app
    	* @access public
Index: sandbox/workflow/trunk/inc/hook_home.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/hook_home.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/hook_home.inc.php	(revision 2372)
@@ -1,3 +1,5 @@
 <?php
+require_once 'common.inc.php';
+
 $GLOBALS['phpgw_info']['flags']['currentapp'] = "workflow";
 if (!isset($_SESSION['phpgw_info']['workflow']['server']))
@@ -22,5 +24,5 @@
 
 $title = lang("External Applications");
-$bo	= CreateObject('workflow.bo_userinterface');
+$bo	= Factory::getInstance('bo_userinterface');
 $externals 	= $bo -> externals();
 $extra_data = '';
@@ -42,5 +44,5 @@
 }
 $extra_data .= "</table></div>";
-$portalbox = CreateObject('phpgwapi.listbox',
+$portalbox = Factory::getInstance('listbox',
 	Array(
 		'title'     => $title,
Index: sandbox/workflow/trunk/inc/class.workflow_process.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_process.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_process.inc.php	(revision 2372)
@@ -16,5 +16,5 @@
 		function workflow_process()
 		{
-			parent::Process($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::Process(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.JobScheduler.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.JobScheduler.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.JobScheduler.inc.php	(revision 2372)
@@ -11,7 +11,4 @@
 
 require_once 'jobs/class.JobEnum.inc.php';
-require_once 'jobs/class.AbsoluteDate.inc.php';
-require_once 'jobs/class.WeekDate.inc.php';
-require_once 'jobs/class.RelativeDate.inc.php';
 
 /**
@@ -57,6 +54,6 @@
 	{
 		$this->currentDate = new DateTime(date('Y-n-j G:i:00'));
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID;
-		$this->jobManager = &$GLOBALS['workflow']['factory']->getInstance('WorkflowJobManager');
+		$this->db = &Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID;
+		$this->jobManager = &Factory::getInstance('WorkflowJobManager');
 	}
 
@@ -76,14 +73,14 @@
 		{
 			case DateType::ABSOLUTE_DATE:
-				$object = new AbsoluteDate($startDate, $interval);
+				$object = &Factory::getInstance('AbsoluteDate', $startDate, $interval);
 				break;
 
 			case DateType::WEEK_DATE:
-				$object = new WeekDate($startDate, $interval);
+				$object = &Factory::getInstance('WeekDate', $startDate, $interval);
 				$object->setWeekDays($record['week_days']);
 				break;
 
 			case DateType::RELATIVE_DATE:
-				$object = new RelativeDate($startDate, $interval);
+				$object = &Factory::getInstance('RelativeDate', $startDate, $interval);
 				$object->setOffset($record['month_offset']);
 				break;
@@ -171,5 +168,5 @@
 		$previousDir = getcwd();
 		chdir(GALAXIA_LIBRARY . '/../');
-		$output = $GLOBALS['workflow']['factory']->newInstance('Thread', 'class.JobRunner.inc.php "' . $parameters . '"');
+		$output = Factory::newInstance('Thread', 'class.JobRunner.inc.php "' . $parameters . '"');
 		chdir($previousDir);
 		return $output;
@@ -192,7 +189,7 @@
 {
 	require_once 'common.inc.php';
-	$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareEnvironment();
+	Factory::getInstance('WorkflowMacro')->prepareEnvironment();
 
-	$job = new JobScheduler();
+	$job = Factory::newInstance('JobScheduler');
 	$job->run();
 }
Index: sandbox/workflow/trunk/inc/class.so_orgchart.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_orgchart.inc.php	(revision 2063)
+++ sandbox/workflow/trunk/inc/class.so_orgchart.inc.php	(revision 2372)
@@ -127,6 +127,6 @@
 		$this->isAdmin = $_SESSION['phpgw_info']['workflow']['user_is_admin'];
 		$this->acl = &$GLOBALS['ajax']->acl;
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Link_ID;
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Link_ID;
+		$this->db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID;
+		$this->db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID;
 		$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
 	}
@@ -711,5 +711,5 @@
 
 		$output = $result->GetArray(-1);
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = Factory::newInstance('CachedLDAP');
 		$cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP_DATABASE);
 		for ($i = 0; $i < count($output); $i++)
@@ -765,6 +765,6 @@
 
 		/* search for the $searchTerm in the LDAP */
-		$ldap = &$GLOBALS['workflow']['workflowObjects']->getLDAP();
-		$list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), $ldapSearch, array('uidnumber', 'cn', 'uid'));
+		$ldap = &Factory::getInstance('WorkflowObjects')->getLDAP();
+		$list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), $ldapSearch, array('uidnumber', 'cn', 'uid'));
 		if ($list === false)
 			die(serialize("O sistema de busca não pode ser utilizado nesta organização."));
@@ -774,5 +774,5 @@
 
 		/* search for the $searchTerm in the DB */
-		$resultSet = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID->query($DBSearch, $DBValues)->GetArray(-1);
+		$resultSet = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID->query($DBSearch, $DBValues)->GetArray(-1);
 		foreach ($resultSet as $row)
 			if (!isset($unifiedResult[$row['uidnumber']]))
@@ -823,5 +823,5 @@
 		{
 			$errors = array(
-				"O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($employeeID) . "\" já pertença à área \"{$row['sigla']}\".",
+				"O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($employeeID) . "\" já pertença à área \"{$row['sigla']}\".",
 				'-----------------',
 				'Caso você queira colocá-lo na área selecionada, siga o procedimento: faça uma busca por seu nome, clique para editá-lo e, troque pela área desejada.'
@@ -881,5 +881,5 @@
 		{
 			$errors = array(
-				"O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($employeeID) . "\" é titular, substituto, já participou de substituição ou é auxiliar administrativo das seguintes áreas: " . implode(", ", $areas),
+				"O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($employeeID) . "\" é titular, substituto, já participou de substituição ou é auxiliar administrativo das seguintes áreas: " . implode(", ", $areas),
 				'-----------------',
 				'Se você quiser excluir este funcionário, precisa removê-lo dos "cargos" que ele possui nas áreas citadas.'
@@ -919,5 +919,5 @@
 		$this->_checkError($result);
 
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
 		{
@@ -999,5 +999,5 @@
 			$query = 'SELECT 1 FROM funcionario WHERE (funcionario_id = ?)';
 			if (!$this->db->query($query, $checkEmployee)->fetchRow())
-				$errors[] = "O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área.";
+				$errors[] = "O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área.";
 		}
 
@@ -1044,5 +1044,5 @@
 			$query = 'SELECT 1 FROM funcionario WHERE (funcionario_id = ?)';
 			if (!$this->db->query($query, $checkEmployee)->fetchRow())
-				$errors[] = "O funcionário \"" . $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área.";
+				$errors[] = "O funcionário \"" . Factory::getInstance('WorkflowLDAP')->getName($checkEmployee) . "\" não está vinculado a uma área.";
 		}
 
@@ -1091,4 +1091,9 @@
 		$this->_checkAccess($organizationID, false, true);
 
+		/**
+		 * This is so wrong.. We should always use the factory to
+		 * instantiate stuff. Besides, module class should not
+		 * use process classes; the correct is to do the inverse.
+		 */
 		require_once dirname(__FILE__) . '/local/classes/class.wf_orgchart.php';
 		$orgchart = new wf_orgchart();
@@ -1096,5 +1101,5 @@
 		$outputInfo = array();
 
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = Factory::newInstance('CachedLDAP');
 
 		/* here we need fresh information. Let's access ldap first */
@@ -1262,5 +1267,5 @@
 		);
 
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = Factory::newInstance('CachedLDAP');
 		$cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP_DATABASE);
 		if (!empty($areaInfo['titular_funcionario_id']))
@@ -1512,7 +1517,5 @@
 
 		/* we must query ldap to get full user names. In workflow db we just store uids */
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
-
-		$cachedLDAP->getEntryByID();
+		$cachedLDAP = Factory::getInstance('CachedLDAP');
 
 		$output = $result->GetArray(-1);
Index: sandbox/workflow/trunk/inc/class.so_adminaccess.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_adminaccess.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.so_adminaccess.inc.php	(revision 2372)
@@ -77,5 +77,5 @@
 	{
 		$output = array();
-		$names = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getNames($userIDs);
+		$names = Factory::getInstance('WorkflowLDAP')->getNames($userIDs);
 		foreach ($names as $name)
 			$output[] = array(
@@ -201,6 +201,6 @@
 		if (!is_object($GLOBALS['phpgw']->acl))
 		{
-			$GLOBALS['phpgw']->db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
-			$GLOBALS['phpgw']->acl = &$GLOBALS['workflow']['factory']->getForeignInstance('phpgwapi', 'acl', $userID);
+			$GLOBALS['phpgw']->db =& Factory::getInstance('WorkflowObjects')->getDBExpresso();
+			$GLOBALS['phpgw']->acl =& Factory::getInstance('acl', $userID);
 		}
 
Index: sandbox/workflow/trunk/inc/class.bo_agent.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_agent.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_agent.inc.php	(revision 2372)
@@ -278,5 +278,5 @@
 			if (!(isset($this->process)))
 			{
-				$this->process = CreateObject('workflow.workflow_process');
+				$this->process = Factory::getInstance('workflow_process');
 				$this->process->getProcess($wf_p_id);
 			}
Index: sandbox/workflow/trunk/inc/class.bo_participants.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_participants.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_participants.inc.php	(revision 2372)
@@ -34,5 +34,5 @@
 	function bo_participants()
 	{
-		$this->ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$this->ldap = &Factory::getInstance('WorkflowLDAP');
 	}
 
Index: sandbox/workflow/trunk/inc/common.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/common.inc.php	(revision 1484)
+++ sandbox/workflow/trunk/inc/common.inc.php	(revision 2372)
@@ -1,29 +1,74 @@
 <?php
-if (file_exists(dirname(__FILE__) . '/../../header.session.inc.php')) {
-	require_once dirname(__FILE__) . '/../../header.session.inc.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.                                              *
+\**************************************************************************/
+
+/**
+ * Server base path. This constant is somewhat simililar to
+ * 'PHPGW_SERVER_ROOT'. Nevertheless, there are cases that we
+ * access Workflow directly and it must be defined somewhere.
+ * Recently discovered, when we are runnnig jobs HTTP_SERVER_VARS
+ * exported by apache are not available.
+ * Therefore, we are using this workaround here, setting
+ * EGW_SERVER_ROOT based on the location of this file. This constant
+ * should be updated properly every time we move this file.
+ * @name EGW_SERVER_ROOT
+ */
+define('EGW_SERVER_ROOT', dirname(dirname(dirname(__FILE__))));
+//define('EGW_SERVER_ROOT', $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']);
+
+/**
+ * Server include base path. We must define our own constants
+ * because there are several cases in which workflow is called
+ * directly, thus PHPGW constants are not defined.
+ * @name EGW_INC_ROOT
+ */
+define('EGW_INC_ROOT', EGW_SERVER_ROOT . '/phpgwapi/inc/');
+
+/**
+ * Workflow base path.
+ * @name WF_SERVER_ROOT
+ */
+define('WF_SERVER_ROOT', EGW_SERVER_ROOT.'/workflow/');
+
+/**
+ * Workflow include path.
+ * @name WF_INC_ROOT
+ */
+define('WF_INC_ROOT', WF_SERVER_ROOT.'/inc/');
+
+/**
+ * Workflow lib base dir.
+ * @name WF_LIB_ROOT
+ */
+define('WF_LIB_ROOT', WF_SERVER_ROOT.'/lib/');
+
+
+if (file_exists(EGW_SERVER_ROOT . '/header.session.inc.php')) {
+	require_once EGW_SERVER_ROOT . '/header.session.inc.php';
 }
 
-/* garante que durante a execução de funções que modificam strings, os
- * caracteres acentuados sejam tratados corretamente (e.g. strtoupper)
- */
+
+/* assure that the correct encondig will be used (e.g string functions) */
 setlocale(LC_CTYPE, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8');
+
 
 /* define o umask para a criação de arquivos por parte do Workflow */
 umask(007);
 
-require_once dirname(__FILE__) . '/class.factory.inc.php';
 
-/**
- * Objeto que implementa uma Factory
- * @global object $GLOBALS['workflow']['factory']
- * @name $factory
- */
-$GLOBALS['workflow']['factory'] = new Factory();
+/* including common classes */
+require_once WF_LIB_ROOT . 'security/Security.php';
+require_once WF_LIB_ROOT . 'factory/Factory.php';
+require_once WF_LIB_ROOT . 'factory/BaseFactory.php';
+require_once WF_LIB_ROOT . 'factory/WorkflowFactory.php';
+require_once WF_LIB_ROOT . 'factory/ProcessFactory.php';
 
-/**
- * Objeto que cria objetos voltados exclusivamente para o módulo Workflow
- * @global object $GLOBALS['workflow']['workflowObjects']
- * @name $workflowObjects
- */
-$GLOBALS['workflow']['workflowObjects'] = $GLOBALS['workflow']['factory']->newInstance('WorkflowObjects');
+$GLOBALS['workflow']['workflowObjects'] = Factory::getInstance('WorkflowObjects');
 ?>
Index: sandbox/workflow/trunk/inc/class.ui_adminroles.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_adminroles.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_adminroles.inc.php	(revision 2372)
@@ -42,5 +42,5 @@
 		parent::WorkflowUtils();
 
-		$this->workflow_acl = CreateObject('workflow.workflow_acl');
+		$this->workflow_acl = Factory::getInstance('workflow_acl');
 		$denyAccess = true;
 		if ($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
@@ -71,7 +71,7 @@
 		}
 
-		$this->process_manager	= CreateObject('workflow.workflow_processmanager');
-		$this->activity_manager	= CreateObject('workflow.workflow_activitymanager');
-		$this->role_manager	= CreateObject('workflow.workflow_rolemanager');
+		$this->process_manager	= Factory::getInstance('workflow_processmanager');
+		$this->activity_manager	= Factory::getInstance('workflow_activitymanager');
+		$this->role_manager	= Factory::getInstance('workflow_rolemanager');
 		$this->form_action = $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form');
 		
@@ -254,8 +254,8 @@
 			$this->t->set_var('list_mappings', '<tr><td colspan="3" align="center">'. lang('There are no mappings defined for this process')  .'</td></tr>');
 		}
-		else {	
+		else {
 			/* load the LDAP information */
-			$cachedLDAP = $GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
-			$tmpLDAP = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+			$cachedLDAP = Factory::getInstance('CachedLDAP');
+			$tmpLDAP = &Factory::getInstance('WorkflowLDAP');
 			$userContext  = $tmpLDAP->getUserContext();
 			$groupContext = $tmpLDAP->getGroupContext();
@@ -264,10 +264,10 @@
 			{
 				if ($mapping['wf_account_type'] == 'g') {
-					$sri = ldap_search($GLOBALS['workflow']['workflowObjects']->getLDAP(), 
-									$groupContext, 
+					$sri = ldap_search(Factory::getInstance('WorkflowObjects')->getLDAP(),
+									$groupContext,
 									'(&(gidnumber=' . (int)$mapping['wf_user'] . ')(phpgwAccountType=g))');
-									
-					$allValues = ldap_get_entries($GLOBALS['workflow']['workflowObjects']->getLDAP(), $sri);
-					
+
+					$allValues = ldap_get_entries(Factory::getInstance('WorkflowObjects')->getLDAP(), $sri);
+
 					$cname = $GLOBALS['phpgw']->translation->convert($allValues[0]['cn'][0],'utf-8');
 					$glabel = '[' . lang('Group') . ']';
@@ -280,5 +280,5 @@
 						$glabel = '<font color="red">(excluído)</font>';
 				}
-				
+
 				$this->t->set_var(array(
 					'map_user_id'	=> $mapping['wf_user'],
@@ -313,9 +313,9 @@
 	 * Show users roles selects
 	 * @param string $all_roles_data
-	 * @return 
+	 * @return
 	 */
 	function show_users_roles_selects($all_roles_data)
 	{
-		$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+		$templateServer = &Factory::getInstance('TemplateServer');
 		$imgaddusers = $templateServer->generateImageLink('add_group.png');
 		$imgdelusers = $templateServer->generateImageLink('delete_group.png');
@@ -325,5 +325,5 @@
 			'src_img_del_users' => $imgdelusers
 		));
-		
+
 		$this->t->set_block('admin_roles', 'block_select_roles', 'select_roles');
 		foreach ($all_roles_data as $role)
Index: sandbox/workflow/trunk/inc/class.WorkflowUtils.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.WorkflowUtils.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.WorkflowUtils.inc.php	(revision 2372)
@@ -1,3 +1,5 @@
 <?php
+	require_once 'common.inc.php';
+
 	//set here the global DEBUG level which is actually 0 (nothing) or 1 (all)
 	if (!defined('_DEBUG')) define('_DEBUG', 0);
@@ -102,10 +104,10 @@
 			$this->start		= (int)get_var('start', 'any', 0);
 			$this->search_str	= get_var('find', 'any', '');
-			$this->nextmatchs	= CreateObject('phpgwapi.nextmatchs');
+			$this->nextmatchs	= Factory::getInstance('nextmatchs');
 		}
 
 		/**
 		 * Fill the process bar
-		 * 
+		 *
 		 * @param array $proc_info
 		 * @access public
@@ -116,5 +118,5 @@
 			//echo "proc_info: <pre>";print_r($proc_info);echo "</pre>";
 			$this->t->set_file('proc_bar_tpl', 'proc_bar.tpl');
-			$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+			$templateServer = &Factory::getInstance('TemplateServer');
 
 			if ($proc_info['wf_is_valid'] == 'y')
@@ -170,5 +172,5 @@
 		/**
 		 * Select activity representation icon
-		 *  
+		 *
 		 * @var string $type type of activity
 		 * @var bool   $interactive interactive?
@@ -207,10 +209,10 @@
 					$ic="no-activity.gif";
 			}
-			return '<img src="'. $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink($ic) .'" alt="'. lang($type) .'" title="'. lang($type) .'" />';
-		}
-	
+			return '<img src="'. Factory::getInstance('TemplateServer')->generateImageLink($ic) .'" alt="'. lang($type) .'" title="'. lang($type) .'" />';
+		}
+
 		/**
 		 * Translate template file
-		 * @param string $template_name template name 
+		 * @param string $template_name template name
 		 * @return void
 		 * @access public
@@ -359,5 +361,5 @@
 		function export()
 		{
-			$this->process_manager	= CreateObject('workflow.workflow_processmanager');
+			$this->process_manager	= Factory::getInstance('workflow_processmanager');
 
 			// retrieve process info
@@ -387,12 +389,12 @@
 		{
 			$file = "css/$css_name" . (($print_mode !== false) ? '_print' : '') . '.css';
-			return $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->getWebFile($file);
-		}
-		
+			return Factory::getInstance('TemplateServer')->getWebFile($file);
+		}
+
 		/**
 		 * Return a given duration in human readable form, usefull for workitems duration
 		 * @param int $to given duration
 		 * @return string given duration in human readable form
-		 * @access public 
+		 * @access public
 		 */
 		function time_diff($to) {
Index: sandbox/workflow/trunk/inc/class.WorkflowMacro.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.WorkflowMacro.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.WorkflowMacro.inc.php	(revision 2372)
@@ -40,5 +40,5 @@
 		require dirname(__FILE__) . '/../setup/setup.inc.php'; /* DO NOT USE require_once */
 		$GLOBALS['phpgw_info']['apps']['workflow'] = $setup_info['workflow'];
-		$row = $GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir'))->fetchRow();
+		$row = Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir'))->fetchRow();
 		$_SESSION['phpgw_info']['workflow']['vfs_basedir'] = ($row !== false) ? $row['config_value'] : '/home/expressolivre';
 		$_SESSION['phpgw_info']['workflow']['phpgw_api_inc'] = PHPGW_API_INC;
@@ -48,7 +48,6 @@
 		require_once PHPGW_API_INC . '/functions.inc.php';
 		require_once 'engine/class.ajax_config.inc.php';
-		require_once 'engine/class.ajax_ldap.inc.php';
 		require_once 'engine/config.ajax.inc.php';
-		$GLOBALS['ajax']->ldap = new ajax_ldap();
+		$GLOBALS['ajax']->ldap = &Factory::getInstance('ajax_ldap');
 
 		/* definição de algumas constantes */
@@ -64,8 +63,7 @@
 	public function prepareProcessEnvironment($processID)
 	{
-		require_once GALAXIA_LIBRARY . '/src/common/WfRuntime.php';
 		require_once PHPGW_SERVER_ROOT . '/workflow/inc/local/functions/local.functions.php';
 
-		$runtime = new WfRuntime($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$runtime = &Factory::getInstance('WfRuntime', Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		$runtime->loadProcess($processID);
 
Index: sandbox/workflow/trunk/inc/class.workflow_instance.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_instance.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_instance.inc.php	(revision 2372)
@@ -6,6 +6,4 @@
 
 	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Instance.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'common' . SEP . 'WfSecurity.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
 	/**
 	 * @package Workflow
@@ -20,5 +18,5 @@
 		function workflow_Instance()
 		{
-			parent::Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::Instance(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.external_bridge.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.external_bridge.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.external_bridge.inc.php	(revision 2372)
@@ -13,5 +13,4 @@
 require_once 'common.inc.php';
 require_once 'engine/config.egw.inc.php';
-require_once 'class.so_adminaccess.inc.php';
 
 /**
@@ -52,6 +51,6 @@
 	function external_bridge()
 	{
-		$this->db = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia();
-		$this->acl = new so_adminaccess($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$this->db = Factory::getInstance('WorkflowObjects')->getDBGalaxia();
+		$this->acl = &Factory::getInstance('so_adminaccess', Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 	}
 	/**
@@ -156,5 +155,5 @@
 
 		/* assign variables to the template */
-		$smarty = $GLOBALS['workflow']['factory']->getInstance('workflow_smarty', false);
+		$smarty = Factory::getInstance('workflow_smarty', false);
 		$smarty->assign('encodedForm', $encodedForm);
 		$smarty->assign('siteAddress', $this->siteAddress);
Index: sandbox/workflow/trunk/inc/class.ui_participants.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_participants.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_participants.inc.php	(revision 2372)
@@ -41,5 +41,5 @@
 	function ui_participants()
 	{
-		$this->bo = $GLOBALS['workflow']['factory']->getInstance('bo_participants');
+		$this->bo = Factory::getInstance('bo_participants');
 	}
 
@@ -51,9 +51,9 @@
 	function form()
 	{
-		$smarty = $GLOBALS['workflow']['factory']->getInstance('workflow_smarty', false);
+		$smarty = Factory::getInstance('workflow_smarty', false);
 		$smarty->setHeader(workflow_smarty::SHOW_HEADER | workflow_smarty::SHOW_FOOTER);
-		$ldap = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = Factory::getInstance('WorkflowLDAP');
 		$userDN = $GLOBALS['phpgw_info']['user']['account_dn'];
-		$account = $GLOBALS['workflow']['factory']->getForeignInstance('phpgwapi', 'accounts', $userDN);
+		$account = Factory::getInstance('accounts', $userDN);
 		$organizationList = $this->bo->getOrganizations();
 
Index: sandbox/workflow/trunk/inc/class.so_userinterface.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_userinterface.inc.php	(revision 2094)
+++ sandbox/workflow/trunk/inc/class.so_userinterface.inc.php	(revision 2372)
@@ -1,4 +1,3 @@
 <?php
-require_once($_SESSION['phpgw_info']['workflow']['phpgw_api_inc'] . '/class.config.inc.php');
 
 /**
@@ -22,5 +21,5 @@
 	function so_userinterface()
 	{
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Link_ID;
+		$this->db =& Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID;
 		$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
 	}
@@ -61,5 +60,5 @@
 		$oldDB = $GLOBALS['phpgw']->db;
 		$GLOBALS['phpgw']->db = $GLOBALS['ajax']->db;
-		$config = new config('workflow');
+		$config = &Factory::getInstance('config', 'workflow');
 		$configValues = $config->read_repository();
 		$submasksString = $configValues['intranet_subnetworks'];
@@ -93,5 +92,5 @@
 		if (!empty($externalApplicationsID))
 		{
-			$result = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID->query("SELECT DISTINCT external_application_id, name, address, image, authentication, intranet_only FROM egw_wf_external_application WHERE (external_application_id IN (" . implode(', ', $externalApplicationsID)  . ")) ORDER BY name");
+			$result = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID->query("SELECT DISTINCT external_application_id, name, address, image, authentication, intranet_only FROM egw_wf_external_application WHERE (external_application_id IN (" . implode(', ', $externalApplicationsID)  . ")) ORDER BY name");
 			$preOutput = $result->GetArray(-1);
 
@@ -245,5 +244,5 @@
 
 		$employees = $result->GetArray(-1);
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = Factory::newInstance('CachedLDAP');
 		$cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_NORMAL);
 		$categoriesCount = array();
@@ -318,5 +317,5 @@
 
 		$employees = $result->GetArray(-1);
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = Factory::newInstance('CachedLDAP');
 		$cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_NORMAL);
 		for ($i = 0; $i < count($employees); $i++)
@@ -370,5 +369,5 @@
 
 		/* searching employees by name in the ldap server */
-		$list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(cn=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber'));
+		$list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(cn=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber'));
 		if ($list === false)
 			return false;
@@ -466,5 +465,5 @@
 
 		/* executing it */
-		$list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), $ldap_query, array('uidNumber', 'cn', 'telephoneNumber'));
+		$list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), $ldap_query, array('uidNumber', 'cn', 'telephoneNumber'));
 		$entries = ldap_get_entries($ldap, $list);
 
@@ -475,5 +474,5 @@
 
 		/* we will need to search into database 'cache' for users deleted in ldap */
-		$cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] -> newInstance( 'CachedLDAP' );
+		$cachedLDAP = Factory::newInstance( 'CachedLDAP' );
 		$cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_DATABASE );
 
@@ -531,5 +530,5 @@
 
 		/* searching employees by telephoneNumber in the ldap server */
-		$list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(telephoneNumber=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber'));
+		$list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(telephoneNumber=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber'));
 
 		if (!$list) return false;
@@ -594,7 +593,5 @@
 	function getEmployeeInfo($employeeID, $organizationID)
 	{
-		require_once dirname(__FILE__) . '/class.so_orgchart.inc.php';
-
-		$SOOrgchart = new so_orgchart();
+		$SOOrgchart = &Factory::getInstance('so_orgchart');
 		$SOOrgchart->setExternalCalls(true);
 		$output = $SOOrgchart->getEmployeeInfo($employeeID, $organizationID);
@@ -614,7 +611,5 @@
 	function getAreaInfo($areaID, $organizationID)
 	{
-		require_once dirname(__FILE__) . '/class.so_orgchart.inc.php';
-
-		$SOOrgchart = new so_orgchart();
+		$SOOrgchart = &Factory::getInstance('so_orgchart');
 		$SOOrgchart->setExternalCalls(true);
 		$output = $SOOrgchart->getAreaInfo($areaID, $organizationID);
@@ -652,5 +647,5 @@
 		$result = $this -> db -> query( "SELECT a.sigla as area, a.titular_funcionario_id as titular, s.funcionario_id as substituto, s.data_inicio, s.data_fim FROM area a INNER JOIN substituicao s ON ((a.area_id = s.area_id) AND (CURRENT_DATE BETWEEN s.data_inicio AND s.data_fim)) WHERE (organizacao_id = ?) ORDER BY area", array( $organizationID ) );
 
-		$cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] -> newInstance( 'CachedLDAP' );
+		$cachedLDAP = Factory::newInstance( 'CachedLDAP' );
 		$cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_LDAP_DATABASE );
 
@@ -719,5 +714,5 @@
 
 		$employees = $result -> GetArray( -1 );
-		$cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] -> newInstance( 'CachedLDAP' );
+		$cachedLDAP = Factory::newInstance( 'CachedLDAP' );
 		$cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_NORMAL );
 
@@ -791,5 +786,5 @@
 		$employees = $result -> GetArray( -1 );
 
-		$cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] -> newInstance( 'CachedLDAP' );
+		$cachedLDAP = Factory::newInstance( 'CachedLDAP' );
 		$cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_NORMAL );
 
@@ -817,5 +812,5 @@
 		usort( $employees, create_function( '$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);' ) );
 
-		$paging = $GLOBALS['workflow']['factory']->newInstance('Paging', 50, $_POST);
+		$paging = Factory::newInstance('Paging', 50, $_POST);
 		$employees = $paging->restrictItems( $employees );
 
Index: sandbox/workflow/trunk/inc/class.WorkflowJobManager.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.WorkflowJobManager.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.WorkflowJobManager.inc.php	(revision 2372)
@@ -16,5 +16,5 @@
 	public function WorkflowJobManager()
 	{
-		parent::JobManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		parent::JobManager(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 	}
 }
Index: sandbox/workflow/trunk/inc/class.ui_ajaxinterface.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_ajaxinterface.inc.php	(revision 1452)
+++ sandbox/workflow/trunk/inc/class.ui_ajaxinterface.inc.php	(revision 2372)
@@ -11,5 +11,4 @@
 \**************************************************************************/
 
-require_once 'class.workflow_acl.inc.php';
 require_once 'common.inc.php';
 require_once 'engine/class.ajax_config.inc.php';
@@ -50,5 +49,5 @@
 	function set_wf_session()
 	{
-		$acl = new workflow_acl();
+		$acl = Factory::getInstance('workflow_acl');
 		$_SESSION['phpgw_info']['workflow']['server_root'] = PHPGW_SERVER_ROOT;
 		$_SESSION['phpgw_info']['workflow']['phpgw_api_inc'] = PHPGW_API_INC;
@@ -56,12 +55,12 @@
 		$vfs = createobject('phpgwapi.vfs');
 		$_SESSION['phpgw_info']['workflow']['vfs_basedir'] = $vfs->basedir;
-		$_SESSION['phpgw_info']['workflow']['server'] = $GLOBALS['phpgw_info']['server'];			
+		$_SESSION['phpgw_info']['workflow']['server'] = $GLOBALS['phpgw_info']['server'];
 		$_SESSION['phpgw_info']['workflow']['lang'] = $GLOBALS['lang'];
 		$_SESSION['phpgw_info']['workflow']['account_id'] = $GLOBALS['phpgw_info']['user']['account_id'];
-		$_SESSION['phpgw_info']['workflow']['user_groups'] = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getUserGroups($GLOBALS['phpgw_info']['user']['account_id']);
+		$_SESSION['phpgw_info']['workflow']['user_groups'] = Factory::getInstance('WorkflowLDAP')->getUserGroups($GLOBALS['phpgw_info']['user']['account_id']);
 		$user_is_admin = $acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']);
-		$_SESSION['phpgw_info']['workflow']['user_is_admin'] = $user_is_admin; 
+		$_SESSION['phpgw_info']['workflow']['user_is_admin'] = $user_is_admin;
 		$_SESSION['phpgw_info']['workflow']['user_can_admin_process'] = ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_workflow',1,'workflow')));
-		$_SESSION['phpgw_info']['workflow']['user_can_admin_instance'] = ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_instance_workflow',1,'workflow'))); 
+		$_SESSION['phpgw_info']['workflow']['user_can_admin_instance'] = ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_instance_workflow',1,'workflow')));
 
 		$can_monitor = $acl->checkUserGroupAccessToType('MON', $GLOBALS['phpgw_info']['user']['account_id']);
@@ -118,5 +117,5 @@
 	{
 		$CSSName = "css/{$CSSName}.css";
-		$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+		$templateServer = &Factory::getInstance('TemplateServer');
 		$CSSLink = $templateServer->getWebFile($CSSName);
 		$CSSFile = $templateServer->getSystemFile($CSSName);
Index: sandbox/workflow/trunk/inc/class.JobRunner.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.JobRunner.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.JobRunner.inc.php	(revision 2372)
@@ -43,5 +43,5 @@
 		$this->parameters = unserialize(base64_decode($parameters));
 		$this->parameters['currentDate'] = new DateTime($this->parameters['currentDate']);
-		$this->jobManager = &$GLOBALS['workflow']['factory']->getInstance('WorkflowJobManager');
+		$this->jobManager =& Factory::getInstance('WorkflowJobManager');
 	}
 
@@ -66,5 +66,11 @@
 	{
 		/* activate the security policy */
-		$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy();
+		Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy();
+
+		/**
+		 * Since all jobs must run in process mode, e. g. it's user code,
+		 * we must enable the security.
+		 */
+		Security::enable();
 
 		if (!file_exists($this->parameters['file']))
@@ -94,7 +100,7 @@
 
 require_once 'common.inc.php';
-$GLOBALS['workflow']['factory']->getInstance('WorkflowMacro')->prepareEnvironment();
+Factory::getInstance('WorkflowMacro')->prepareEnvironment();
 
-$jobRunner = new JobRunner($argv[1]);
+$jobRunner = &Factory::newInstance('JobRunner', $argv[1]);
 $jobRunner->run();
 ?>
Index: sandbox/workflow/trunk/inc/class.ui_adminsource.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_adminsource.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_adminsource.inc.php	(revision 2372)
@@ -17,5 +17,4 @@
  */
 require_once dirname(__FILE__) . SEP . 'class.ui_ajaxinterface.inc.php';
-require_once dirname(__FILE__) . SEP . 'class.workflow_acl.inc.php';
 require_once 'engine' . SEP . 'config.ajax.inc.php';
 
@@ -43,5 +42,5 @@
 	function ui_adminsource()
 	{
-		$this->workflow_acl = new workflow_acl();
+		$this->workflow_acl = Factory::getInstance('workflow_acl');
 		$denyAccess = true;
 		if ($this->workflow_acl->checkWorkflowAdmin($_SESSION['phpgw_info']['workflow']['account_id']))
@@ -78,5 +77,5 @@
 	function form()
 	{
-		$smarty = $GLOBALS['workflow']['factory']->getInstance('workflow_smarty', false);
+		$smarty = Factory::getInstance('workflow_smarty', false);
 		$smarty->setHeader(workflow_smarty::SHOW_HEADER | workflow_smarty::SHOW_NAVIGATION_BAR | workflow_smarty::SHOW_FOOTER, $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Processes Sources'));
 
Index: sandbox/workflow/trunk/inc/class.so_adminjobs.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_adminjobs.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.so_adminjobs.inc.php	(revision 2372)
@@ -10,7 +10,4 @@
 \**************************************************************************/
 
-require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php';
-require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'JobManager.php';
-require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php';
 
 /**
@@ -96,6 +93,6 @@
 		$this->isAdmin = $_SESSION['phpgw_info']['workflow']['user_is_admin'];
 		$this->acl = &$GLOBALS['ajax']->acl;
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID;
-		$this->jobManager = new JobManager(&$this->db);
+		$this->db = &Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID;
+		$this->jobManager = &Factory::newInstance('JobManager');
 	}
 
@@ -229,5 +226,5 @@
 		$output = array();
 		$job = $this->jobManager->getJob($jobID);
-		$jobScheduler = &$GLOBALS['workflow']['factory']->getInstance('JobScheduler');
+		$jobScheduler =& Factory::getInstance('JobScheduler');
 		$totalTime = microtime(true);
 		$thread = $jobScheduler->execute($job, true);
Index: sandbox/workflow/trunk/inc/class.workflow_smarty.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_smarty.inc.php	(revision 1227)
+++ sandbox/workflow/trunk/inc/class.workflow_smarty.inc.php	(revision 2372)
@@ -11,5 +11,4 @@
 
 require_once 'smarty/Smarty.class.php';
-//require_once 'class.ui_ajaxinterface.inc.php';
 
 /**
Index: sandbox/workflow/trunk/inc/class.ui_move_instances.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_move_instances.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_move_instances.inc.php	(revision 2372)
@@ -36,5 +36,5 @@
 	{
 		$GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$smarty = Factory::getInstance('workflow_smarty');
 
 		$javaScripts = $this->get_common_js();
Index: sandbox/workflow/trunk/inc/class.ui_adminactivities.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_adminactivities.inc.php	(revision 1710)
+++ sandbox/workflow/trunk/inc/class.ui_adminactivities.inc.php	(revision 2372)
@@ -2,5 +2,4 @@
 
 require_once dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php';
-require_once dirname(__FILE__) . SEP . 'class.fsutils.inc.php'; /* toolkit for filesystem handling */
 require_once 'engine' . SEP . 'config.egw.inc.php';
 /**
@@ -73,5 +72,5 @@
 		parent::WorkflowUtils();
 
-		$this->workflow_acl = CreateObject('workflow.workflow_acl');
+		$this->workflow_acl = Factory::getInstance('workflow_acl');
 		$denyAccess = true;
 		if ($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
@@ -106,8 +105,8 @@
 		}
 
-		$this->process_manager	= CreateObject('workflow.workflow_processmanager');
-		$this->activity_manager	= CreateObject('workflow.workflow_activitymanager');
-		$this->role_manager	= CreateObject('workflow.workflow_rolemanager');
-		$this->fs = new FsUtils(); /* gets instance */
+		$this->process_manager	= Factory::getInstance('workflow_processmanager');
+		$this->activity_manager	= Factory::getInstance('workflow_activitymanager');
+		$this->role_manager	= Factory::getInstance('workflow_rolemanager');
+		$this->fs = &Factory::newInstance('FsUtils'); /* gets instance */
 
 	}
@@ -374,5 +373,5 @@
 		// fill proc_bar
 		$this->t->set_var('proc_bar', $this->fill_proc_bar($proc_info));
-		
+
 		//collect some messages from used objects
 		$this->message[] = $this->activity_manager->get_error(false, _DEBUG);
@@ -380,5 +379,5 @@
 		$this->message[] = $this->role_manager->get_error(false, _DEBUG);
 
-		$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+		$templateServer = &Factory::getInstance('TemplateServer');
 
 		// fill the general variables of the template
@@ -732,5 +731,5 @@
 			$this->translate_template('block_process_activities_header');
 			$this->t->parse('process_activities_header', 'block_process_activities_header', True);
-			$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+			$templateServer = &Factory::getInstance('TemplateServer');
 			foreach ($process_activities_data as $activity)
 			{
@@ -792,5 +791,5 @@
 				'trans_href_from'	=> $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $transition['wf_act_from_id']),
 				'trans_actFromName'	=> $transition['wf_act_from_name'],
-				'trans_arrow'		=> $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink('next.gif'),
+				'trans_arrow'		=> Factory::getInstance('TemplateServer')->generateImageLink('next.gif'),
 				'trans_href_to'		=> $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $transition['wf_act_to_id']),
 				'trans_actToName'	=> $transition['wf_act_to_name'],
@@ -1036,5 +1035,5 @@
 		$image_name = $proc_info['wf_normalized_name'] . SEP . 'graph' . SEP . $proc_info['wf_normalized_name'] . '.png';
 		$image = GALAXIA_PROCESSES . SEP . $image_name;
-		if ($GLOBALS['workflow']['factory']->getInstance('BrowserInfo')->isOpera())
+		if (Factory::getInstance('BrowserInfo')->isOpera())
 			$maximumDimension = 1000000;
 		else
@@ -1069,5 +1068,5 @@
 		}
 	}
-	
+
 	/**
 	 * Dislays the activity agents config rows
@@ -1090,5 +1089,5 @@
 			}
 			$this->translate_template('admin_agents');
-												$this->t->parse('agents_config_rows', 'admin_agents');
+			$this->t->parse('agents_config_rows', 'admin_agents');
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.workflow_wfruntime.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_wfruntime.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_wfruntime.inc.php	(revision 2372)
@@ -18,5 +18,5 @@
 		function workflow_wfruntime()
 		{
-			parent::WfRuntime($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::WfRuntime(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.WorkflowLDAP.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.WorkflowLDAP.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.WorkflowLDAP.inc.php	(revision 2372)
@@ -50,5 +50,5 @@
 	function WorkflowLDAP()
 	{
-		$this->dataSource = &$GLOBALS['workflow']['workflowObjects']->getLDAP();
+		$this->dataSource =& Factory::getInstance('WorkflowObjects')->getLDAP();
 
 		/* get the required parameters */
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_user.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_user.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_user.php	(revision 2372)
@@ -94,5 +94,5 @@
 		$extraParams .= "&hideSectors=1";
 
-	$image = $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink('add_user.png');
+	$image = Factory::getInstance('TemplateServer')->generateImageLink('add_user.png');
 
 $output .= <<<EOF
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_state.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_state.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_state.php	(revision 2372)
@@ -46,5 +46,5 @@
 	$sql = "SELECT id_state, state_name FROM phpgw_cc_state WHERE id_country = 'BR' ORDER BY state_name";
 
-	$result = $GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID->query($sql);
+	$result = Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID->query($sql);
 	$estados = array();
 	while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_ldap_users.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_ldap_users.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_ldap_users.php	(revision 2372)
@@ -25,5 +25,5 @@
 {
     require_once $smarty->_get_plugin_filepath('function','html_options');
-	$imagesPath = substr($GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink(''), 0, -1);
+	$imagesPath = substr(Factory::getInstance('TemplateServer')->generateImageLink(''), 0, -1);
 
 	$requiredParams = array(
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_city.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_city.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_city.php	(revision 2372)
@@ -37,14 +37,14 @@
 		if (!array_key_exists($required, $params) || (empty($params[$required])))
 			$smarty->trigger_error("[wf_select_city] missing required parameter(s): $required", E_USER_ERROR);
-	
+
 	/* atribui valores default para os parâmetros não passados */
 	foreach ($defaultValues as $key => $value)
 		if (!isset($params[$key]))
 			$params[$key] = $value;
-	
+
 	/* extrai alguns parâmetros da matriz de parâmetros */
 	foreach ($extractParams as $extract)
 		$$extract = $params[$extract];
-	
+
 	/* parâmetros extras são "acumulados" em uma única variável */
 	$extraParams = array();
@@ -53,5 +53,5 @@
 			$extraParams[$key] = $value_params;
 
-	$db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID;
+	$db = &Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID;
 	if (isset($params['value']))
 	{
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_generic_select.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_generic_select.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_generic_select.php	(revision 2372)
@@ -53,5 +53,5 @@
 EOF;
 
-	$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+	$templateServer = &Factory::getInstance('TemplateServer');
 	$imageAdd = $templateServer->generateImageLink('add.png');
 	$imageRemove = $templateServer->generateImageLink('close.png');
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/prefilter.wf_default_template.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/prefilter.wf_default_template.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/prefilter.wf_default_template.php	(revision 2372)
@@ -31,5 +31,5 @@
 	{
 		/* get the header and footer location */
-		$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+		$templateServer = &Factory::getInstance('TemplateServer');
 		$header = $templateServer->getSystemFile('processes/header.tpl');
 		$footer = $templateServer->getSystemFile('processes/footer.tpl');
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_redir_menu.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_redir_menu.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_redir_menu.php	(revision 2372)
@@ -53,5 +53,5 @@
 	$select_tag .= "<option value=\"og\">Organograma</option>";
 
-	$user_is_admin = $GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']);
+	$user_is_admin = Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']);
 	if ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_workflow',1,'workflow'))) {
 		$select_tag .= "<option value=\"ad\">Administração</option>";
Index: sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_users.php
===================================================================
--- sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_users.php	(revision 795)
+++ sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_select_users.php	(revision 2372)
@@ -16,5 +16,5 @@
 {
     require_once $smarty->_get_plugin_filepath('function','html_options');
-	$imagesPath = substr($GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink(''), 0, -1);
+	$imagesPath = substr(Factory::getInstance('TemplateServer')->generateImageLink(''), 0, -1);
 	$requiredParams = array(
 		'name');
Index: sandbox/workflow/trunk/inc/class.workflow_gui.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_gui.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_gui.inc.php	(revision 2372)
@@ -5,7 +5,5 @@
 
 	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'GUI' . SEP . 'GUI.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Process.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Instance.php');
-	require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'common' . SEP . 'WfSecurity.php');
+
 	/**
 	 * @package Workflow
@@ -20,5 +18,5 @@
 		function workflow_gui()
 		{
-			parent::GUI($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::GUI(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.bo_userinterface.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_userinterface.inc.php	(revision 2085)
+++ sandbox/workflow/trunk/inc/class.bo_userinterface.inc.php	(revision 2372)
@@ -10,10 +10,6 @@
 \**************************************************************************/
 
-require_once('class.so_userinterface.inc.php');
 require_once('class.bo_ajaxinterface.inc.php');
-require_once('class.Paging.inc.php');
-
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'GUI' . SEP . 'GUI.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
+
 /**
  * @package Workflow
@@ -43,7 +39,7 @@
 	function bo_userinterface()
 	{
-		parent::bo_ajaxinterface();	
-		$this->so = new so_userinterface();
-		$GLOBALS['ajax']->gui = new GUI($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		parent::bo_ajaxinterface();
+		$this->so = &Factory::getInstance('so_userinterface');
+		$GLOBALS['ajax']->gui = &Factory::newInstance('GUI');
 	}
 
@@ -68,5 +64,5 @@
 		$webserver_url = $_SESSION['phpgw_info']['workflow']['server']['webserver_url'];
 
-		$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+		$templateServer =& Factory::getInstance('TemplateServer');
 		foreach ($result['data'] as $line)
 		{
@@ -120,17 +116,17 @@
 		$pid = $params['pid'];
 		$result = array();
-		
-		$process = new Process($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+
+		$process = &Factory::newInstance('Process');
 		$process->getProcess($pid);
 		$result['wf_procname'] = $process->name;
 		$result['wf_version'] = $process->version;
 		$result['wf_description'] = $process->description;
-		
-		$activ_manager = new ActivityManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+
+		$activ_manager = &Factory::newInstance('ActivityManager');
 		$result['wf_activities'] = $activ_manager->get_process_activities($pid);
-		
-		$this->disconnect_all();
-		
-		return $result; 
+
+		$this->disconnect_all();
+
+		return $result;
 	}
 
@@ -148,5 +144,5 @@
 		$itemsPerPage = isset($preferences['ui_items_per_page']) ? $preferences['ui_items_per_page'] : 15;
 		$lightVersion = ((isset($preferences['use_light_interface']) ? $preferences['use_light_interface'] : 0) == 1);
-		$paging = new Paging($itemsPerPage, $_POST);
+		$paging = Factory::newInstance('Paging', $itemsPerPage, $_POST);
 
 		/* define the sorting */
@@ -263,5 +259,5 @@
 				else
 					if ($row['wf_user'] != '')
-						$row['wf_user_fullname'] = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($row['wf_user']);
+						$row['wf_user_fullname'] = Factory::getInstance('WorkflowLDAP')->getName($row['wf_user']);
 
 				/* unset unneeded information */
@@ -495,8 +491,8 @@
 		}
 
-		$instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$instance = &Factory::newInstance('Instance');
 		$instance->getInstance($instanceID);
 
-		$process = new Process($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$process = &Factory::newInstance('Process');
 		$process->getProcess($instance->pId);
 
@@ -508,7 +504,7 @@
 			'wf_instance_id' => $instance->instanceId,
 			'wf_priority' => $instance->priority,
-			'wf_owner' => $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($instance->owner),
+			'wf_owner' => Factory::getInstance('WorkflowLDAP')->getName($instance->owner),
 			'wf_next_activity' => $instance->nextActivity,
-			'wf_next_user' => $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($instance->nextUser),
+			'wf_next_user' => Factory::getInstance('WorkflowLDAP')->getName($instance->nextUser),
 			'wf_name' => $instance->name,
 			'wf_category' => $instance->category,
@@ -526,5 +522,5 @@
     		$result['wf_ended'] = "";
 
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		foreach ($instance->workitems as $line)
 		{
@@ -657,5 +653,5 @@
 		$cod_process = array();
 
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		$viewActivitiesID = array();
 		foreach ($result['data'] as $row)
@@ -726,5 +722,5 @@
 			/* paginate the result */
 			$itemsPerPage = isset($_SESSION['phpgw_info']['workflow']['user']['preferences']['ui_items_per_page']) ? $_SESSION['phpgw_info']['workflow']['user']['preferences']['ui_items_per_page'] : 15;
-			$paging = new Paging($itemsPerPage, $_POST);
+			$paging = Factory::newInstance('Paging', $itemsPerPage, $_POST);
 			$output['instances'] = $paging->restrictItems($output['instances']);
 			$output['paging_links'] = $paging->commonLinks();
@@ -740,5 +736,5 @@
 	/**
 	 * Aplicacoes externas do usuario
-	 * @return array 
+	 * @return array
 	 * @access public
 	 */
@@ -746,5 +742,5 @@
 	{
 		$webserver_url = $_SESSION['phpgw_info']['workflow']['server']['webserver_url'];
-		$templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
+		$templateServer = &Factory::getInstance('TemplateServer');
 
 		/* load the sites that the user can access */
@@ -1070,5 +1066,5 @@
 	function callVoipConnect($params)
 	{
-		$cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = Factory::newInstance('CachedLDAP');
 		$cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP);
 
Index: sandbox/workflow/trunk/inc/class.Logger.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.Logger.inc.php	(revision 900)
+++ sandbox/workflow/trunk/inc/class.Logger.inc.php	(revision 2372)
@@ -80,5 +80,5 @@
 	{
 
-		$this->db =& $GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID;
+		$this->db =& Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID;
 
 		if(!empty($curProcessName)){
Index: sandbox/workflow/trunk/inc/class.bo_adminjobs.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_adminjobs.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_adminjobs.inc.php	(revision 2372)
@@ -11,6 +11,4 @@
 
 require_once 'class.bo_ajaxinterface.inc.php';
-require_once 'class.so_adminjobs.inc.php';
-require_once 'nano/JSON.php';
 
 /**
@@ -36,5 +34,5 @@
 	{
 		parent::bo_ajaxinterface();
-		$this->so = new so_adminjobs();
+		$this->so = &Factory::getInstance('so_adminjobs');
 	}
 
@@ -100,5 +98,5 @@
 		/* paginate the result */
 		$logEntriesPerPage = 30;
-		$paging = &$GLOBALS['workflow']['factory']->newInstance('Paging', $logEntriesPerPage, $params);
+		$paging =& Factory::newInstance('Paging', $logEntriesPerPage, $params);
 		$logs = $paging->restrictItems($logs);
 
Index: sandbox/workflow/trunk/inc/class.so_external_applications.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.so_external_applications.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.so_external_applications.inc.php	(revision 2372)
@@ -130,5 +130,5 @@
 		$this->isAdmin = $_SESSION['phpgw_info']['workflow']['user_is_admin'];
 		$this->acl = &$GLOBALS['ajax']->acl;
-		$this->db = &$GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID;
+		$this->db =& Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID;
 		$this->EXTERNAL_APPLICATION_PATH = $_SESSION['phpgw_info']['workflow']['server']['files_dir'] . '/workflow//workflow/external_applications';
 	}
Index: sandbox/workflow/trunk/inc/class.bo_adminsource.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_adminsource.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_adminsource.inc.php	(revision 2372)
@@ -11,9 +11,4 @@
 
 require_once('class.bo_ajaxinterface.inc.php');
-
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'RoleManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Process.php');
 
 /**
@@ -80,5 +75,5 @@
 		$fileSizeUnit[] = 'Mb';
 		$fileSizeUnit[] = 'Gb';
-		
+
 		$unitSelect = 0;
 		while ($value > 1024.0)
@@ -87,26 +82,26 @@
 			$unitSelect++;
 		}
-	
+
 		$output = round($value, 1);
 		$output .= " " . $fileSizeUnit[$unitSelect];
-	
+
 		return $output;
 	}
-	
+
 	/**
 	* Get process toolbar data
-	* @param  array $p process process data 
-	* @return array
-	* @access public 
-	*/	
-	function get_toolbar_data($p) 
-	{
-		
-		$process_manager = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$proc_info       = $process_manager->get_process($p['proc_id']); 
-		
+	* @param  array $p process process data
+	* @return array
+	* @access public
+	*/
+	function get_toolbar_data($p)
+	{
+
+		$process_manager = &Factory::newInstance('ProcessManager');
+		$proc_info       = $process_manager->get_process($p['proc_id']);
+
 		$web_server_url  = $_SESSION['phpgw_info']['workflow']['server']['webserver_url'];
-		$img_default_dir = $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink('');
-		
+		$img_default_dir = Factory::getInstance('TemplateServer')->generateImageLink('');
+
 		if ($proc_info['wf_is_valid'] == 'y')
 		{
@@ -119,5 +114,5 @@
 			$alt_validity = tra('invalid');
 		}
-	
+
 		// if process is active show stop button. Else show start button, but only if it is valid. If it's not valid, don't show any activation or stop button.
 		if ($proc_info['wf_is_active'] == 'y')
@@ -138,5 +133,5 @@
 			$start_stop_img  = '';
 		}
-	
+
 		/* load other processes link */
 		$proc_ids = $GLOBALS['ajax']->acl->get_granted_processes($_SESSION['phpgw_info']['workflow']['account_id']);
@@ -145,10 +140,10 @@
 		else
 			$where = ' wf_p_id = -1 ';
-	
+
 		$processesInfo = &$process_manager->list_processes(0, -1, 'wf_name__asc', '', $where);
 		$otherProcesses = array();
 		foreach ($processesInfo['data'] as $pi)
 			$otherProcesses[] = array("name" => $pi['wf_name'] . " (v" . $pi['wf_version'] . ")", "link" => $web_server_url . "/index.php?menuaction=workflow.ui_adminsource.form&p_id=" . $pi['wf_p_id'], "pid" => $pi['wf_p_id']);
-	
+
 		$toolbar_data = array (
 			'proc_name'					=> $proc_info['wf_name'],
@@ -177,18 +172,18 @@
 			'other_processes'			=> $otherProcesses
 		);
-			
+
 		return $toolbar_data;
 		}
-		
-		
+
+
 	/**
 	* Get process model files
-	* @param  array $p process process data 
-	* @return array
-	* @access public 
+	* @param  array $p process process data
+	* @return array
+	* @access public
 	*/
 	function get_model_files($p)
 	{
-		switch($p['type']) 
+		switch($p['type'])
 		{
 			case 'include'  : $path = PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'js' . SEP . 'adminsource' . SEP . 'inc';
@@ -203,9 +198,9 @@
 		$files          = array();
 
-		if ($handle = opendir($path)) 
-		{
-			while (false !== ($file_name = readdir($handle))) 
-			{	
-				if (!is_dir($path.SEP.$file_name)) 
+		if ($handle = opendir($path))
+		{
+			while (false !== ($file_name = readdir($handle)))
+			{
+				if (!is_dir($path.SEP.$file_name))
 				{
 					$files[] = array('file_name'     => $file_name);
@@ -217,21 +212,21 @@
 		array_multisort($col_file_name,SORT_ASC,$files);
 
-		return $files; 
+		return $files;
 	}
 
 	/**
 	* Get process php files
-	* @param array $p process data 
-	* @return array
-	* @access public 
+	* @param array $p process data
+	* @return array
+	* @access public
 	*/
 	function get_php_files($p)
 	{
-		$process_manager    = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$process_manager    = &Factory::newInstance('ProcessManager');
 		$proc_info          = $process_manager->get_process($p['proc_id']);
-		$activity_manager   = new ActivityManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$activity_manager   = &Factory::newInstance('ActivityManager');
 		$process_activities = $activity_manager->list_activities($p['proc_id'], 0, -1, 'wf_name__asc', '','',false);
 		$path = GALAXIA_PROCESSES . SEP . $proc_info['wf_normalized_name'] . SEP . 'code' . SEP .'activities' . SEP;
-		
+
 		$files = array();
 
@@ -242,10 +237,10 @@
 		foreach ($process_activities['data'] as $process_activity)
 		{
-			
+
 			$file_name   = $process_activity['wf_normalized_name'].'.php';
 			$activity_id = $process_activity['wf_activity_id'];
 			$tamanho     = filesize($path.$file_name);
 			$modificado  = date('d/m/Y H:i:s', filemtime($path.$file_name) );
-			
+
 			$files[] = array('file_name'     => $file_name,
 							 'activity_id'   => $activity_id,
@@ -258,11 +253,11 @@
 							 'tipo_codigo'   => 'atividade'
 			);
-			
+
 			$col_file_name[]  = $file_name;
 			$col_tamanho[]    = $tamanho;
 			$col_modificado[] = $modificado;
 		}
-		
-		if (isset($p['sort'])) 
+
+		if (isset($p['sort']))
 		{
 			$order_by = ($p['order_by'] == 1) ? SORT_ASC : SORT_DESC;
@@ -279,13 +274,13 @@
 			}
 		}
-		
-		return $files; 
-	}
-	
-	/**
-	* Delete process file 
+
+		return $files;
+	}
+
+	/**
+	* Delete process file
 	* @param array $p process data
 	* @return array
-	* @access public 
+	* @access public
 	*/
 	function delete_file($p)
@@ -293,12 +288,12 @@
 		if ((strpos($p['file_name'],'/') !== false) || (strpos($p['file_name'],'/') !== false))
 			return 'Não foi possível executar a operação solicitada';
-		$process_manager = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$proc_info = $process_manager->get_process($p['proc_id']); 
+		$process_manager = &Factory::newInstance('ProcessManager');
+		$proc_info = $process_manager->get_process($p['proc_id']);
 		$file_name = $p['file_name'];
-		$proc_name = $proc_info['wf_normalized_name']; 
+		$proc_name = $proc_info['wf_normalized_name'];
 		$type      = $p['type'];
 		if (strpos($file_name,'/')) return 'Nome de arquivo inválido.';
 		if (!strlen($proc_name)) return 'ID de Processo inválido.';
-		
+
     switch($type)
     {
@@ -315,17 +310,17 @@
 				$path = GALAXIA_PROCESSES . '/' . $proc_info['wf_normalized_name'] . '/resources/' . $file_name;
             break;
-			
+
     }
-   
-	   	if ($type == 'resource') 
+
+	   	if ($type == 'resource')
 		{
 			$complete_path = $path;
-		} 
-		else 
+		}
+		else
 		{
 			$complete_path = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'code' . SEP . $path;
 		}
-	
-		if (file_exists($complete_path)) 
+
+		if (file_exists($complete_path))
 		{
 			if (unlink($complete_path))
@@ -342,17 +337,17 @@
 			return 'O arquivo '.$file_name.' não existe.';
 		}
-	}	
-	/**
-	* Create process new file 
+	}
+	/**
+	* Create process new file
 	* @param array $p process
 	* @return array
-	* @access public 
+	* @access public
 	*/
 	function create_file($p)
 	{
-		$process_manager = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$proc_info = $process_manager->get_process($p['proc_id']); 
+		$process_manager = &Factory::newInstance('ProcessManager');
+		$proc_info = $process_manager->get_process($p['proc_id']);
 		$file_name = $p['file_name'];
-		$proc_name = $proc_info['wf_normalized_name']; 
+		$proc_name = $proc_info['wf_normalized_name'];
 		$type      = $p['type'];
 
@@ -386,7 +381,7 @@
 		}
 
-		if (file_exists($complete_path)) 
-		{
-			if (!$p['rewrite']) 
+		if (file_exists($complete_path))
+		{
+			if (!$p['rewrite'])
 			{
 				return FILE_ALREADY_EXISTS;
@@ -396,5 +391,5 @@
 		}
 
-		if ($fp = fopen($complete_path, 'w')) 
+		if ($fp = fopen($complete_path, 'w'))
 		{
 			$basepath = PHPGW_SERVER_ROOT.SEP.'workflow'.SEP.'js'.SEP.'adminsource';
@@ -409,5 +404,5 @@
 			if ($type == 'template' || $type == 'include')
 			{
-				if (file_exists($basepath.SEP.$p['modelo'])) 
+				if (file_exists($basepath.SEP.$p['modelo']))
 				{
 					fwrite($fp,file_get_contents($basepath.SEP.$p['modelo']));
@@ -423,15 +418,15 @@
 		}
 	}
-	
+
 	/**
 	* Get process include files
 	* @param  array $p process
 	* @return array
-	* @access public 
+	* @access public
 	*/
 	function get_include_files($p)
 	{
-		$process_manager    = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$proc_info          = $process_manager->get_process($p['proc_id']); 
+		$process_manager    = &Factory::newInstance('ProcessManager');
+		$proc_info          = $process_manager->get_process($p['proc_id']);
 		$path = GALAXIA_PROCESSES . SEP . $proc_info['wf_normalized_name'] . SEP . 'code';
 
@@ -442,9 +437,9 @@
 		$files          = array();
 
-		if ($handle = opendir($path)) 
-		{
-			while (false !== ($file_name = readdir($handle))) 
-			{	
-				if (!is_dir($path.SEP.$file_name)) 
+		if ($handle = opendir($path))
+		{
+			while (false !== ($file_name = readdir($handle)))
+			{
+				if (!is_dir($path.SEP.$file_name))
 				{
 					$tamanho     = filesize($path.SEP.$file_name);
@@ -467,5 +462,5 @@
 
 
-		if (isset($p['sort'])) 
+		if (isset($p['sort']))
 		{
 			$order_by = ($p['order_by'] == 1) ? SORT_ASC : SORT_DESC;
@@ -483,17 +478,17 @@
 		}
 
-		return $files; 
-	}
-
-	/**
-	* Get process template files 
-	* @param array $p process data 
-	* @return array
-	* @access public 
+		return $files;
+	}
+
+	/**
+	* Get process template files
+	* @param array $p process data
+	* @return array
+	* @access public
 	*/
 	function get_template_files($p)
 	{
-		$process_manager    = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$proc_info          = $process_manager->get_process($p['proc_id']); 
+		$process_manager    = &Factory::newInstance('ProcessManager');
+		$proc_info          = $process_manager->get_process($p['proc_id']);
 		$path = GALAXIA_PROCESSES . SEP . $proc_info['wf_normalized_name'] . SEP . 'code' . SEP .'templates';
 
@@ -502,9 +497,9 @@
 		$col_modificado = array();
 
-		if ($handle = opendir($path)) 
-		{
-			while (false !== ($file_name = readdir($handle))) 
-			{	
-				if (!is_dir($path.SEP.$file_name)) 
+		if ($handle = opendir($path))
+		{
+			while (false !== ($file_name = readdir($handle)))
+			{
+				if (!is_dir($path.SEP.$file_name))
 				{
 					$tamanho     = filesize($path.SEP.$file_name);
@@ -541,19 +536,19 @@
 
         }
-    }	
-
-		return $files; 
-	}
-
-	/**
-	* Upload process resource  
-	* 
+    }
+
+		return $files;
+	}
+
+	/**
+	* Upload process resource
+	*
 	* @param array $p process
 	* @return array
-	* @access public 
+	* @access public
 	*/
 	function upload_resource($p)
 	{
-		$process_manager = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$process_manager = &Factory::newInstance('ProcessManager');
 		$proc_info = $process_manager->get_process($p['proc_id']);
 		$file_name = basename($_FILES['resource_file']['name']);
@@ -587,5 +582,5 @@
 		if (strpos($_REQUEST['file_name'],'/') !== false)
 			return 'Não foi possível executar a operação solicitada';
-		$process_manager    = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$process_manager    = &Factory::newInstance('ProcessManager');
 		$proc_info          = $process_manager->get_process($_REQUEST['proc_id']);
 
@@ -617,5 +612,5 @@
 			$completePath = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'code' . SEP . $path;
 
-		$GLOBALS['workflow']['factory']->getInstance('ResourcesRedirector')->show($completePath, 'application/force-download');
+		Factory::getInstance('ResourcesRedirector')->show($completePath, 'application/force-download');
 		exit;
 	}
@@ -630,5 +625,5 @@
 	function get_resource_files($p)
 	{
-		$process_manager    = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$process_manager    = &Factory::newInstance('ProcessManager');
 		$proc_info          = $process_manager->get_process($p['proc_id']);
 
Index: sandbox/workflow/trunk/inc/class.bo_orgchart.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_orgchart.inc.php	(revision 2042)
+++ sandbox/workflow/trunk/inc/class.bo_orgchart.inc.php	(revision 2372)
@@ -10,5 +10,4 @@
 \**************************************************************************/
 
-require_once('class.so_orgchart.inc.php');
 require_once('class.bo_ajaxinterface.inc.php');
 /**
@@ -47,5 +46,5 @@
 	{
 		parent::bo_ajaxinterface();
-		$this->so = new so_orgchart();
+		$this->so = &Factory::getInstance('so_orgchart');
 	}
 
Index: sandbox/workflow/trunk/inc/class.workflow_instancemanager.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_instancemanager.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.workflow_instancemanager.inc.php	(revision 2372)
@@ -17,5 +17,5 @@
 		function workflow_instancemanager()
 		{
-			parent::InstanceManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::InstanceManager(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/nano/NanoGuardian.class.php
===================================================================
--- sandbox/workflow/trunk/inc/nano/NanoGuardian.class.php	(revision 795)
+++ sandbox/workflow/trunk/inc/nano/NanoGuardian.class.php	(revision 2372)
@@ -32,5 +32,5 @@
     public function __construct()
     {
-        $this->_mObjNanoSanitizer = new NanoSanitizer(new DummyLogger);
+        $this->_mObjNanoSanitizer = &Factory::newInstance('NanoSanitizer', new DummyLogger);
     }
 
Index: sandbox/workflow/trunk/inc/nano/NanoJsonConverter.class.php
===================================================================
--- sandbox/workflow/trunk/inc/nano/NanoJsonConverter.class.php	(revision 795)
+++ sandbox/workflow/trunk/inc/nano/NanoJsonConverter.class.php	(revision 2372)
@@ -118,6 +118,6 @@
         // initialize JSON object
         $this->_mObjJson = ( strtolower($return_type) != 'object' )
-                                ? new Services_JSON( SERVICES_JSON_LOOSE_TYPE )
-                                : new Services_JSON();
+                                ? Factory::getInstance('Services_JSON', SERVICES_JSON_LOOSE_TYPE )
+                                : Factory::getInstance('Services_JSON');
     }
 
Index: sandbox/workflow/trunk/inc/nano/NanoController.class.php
===================================================================
--- sandbox/workflow/trunk/inc/nano/NanoController.class.php	(revision 795)
+++ sandbox/workflow/trunk/inc/nano/NanoController.class.php	(revision 2372)
@@ -59,6 +59,6 @@
     function __construct()
     {
-        $this->_mObjJsonConverter = new NanoJsonConverter();
-        $this->_mObjJson          = new Services_JSON();
+        $this->_mObjJsonConverter = &Factory::newInstance('NanoJsonConverter');
+        $this->_mObjJson          = &Factory::newInstance('Services_JSON');
     }
 
@@ -130,5 +130,5 @@
     public function iterateOverVirtualRequests()
     {
-        $this->_mObjNanoRequest = new NanoRequest( $this->_mStrClassPath, $this->_mStrClassSuffix, $this->_mStrClassPreffix );
+        $this->_mObjNanoRequest = &Factory::newInstance('NanoRequest', $this->_mStrClassPath, $this->_mStrClassSuffix, $this->_mStrClassPreffix );
         $return_data            = array();
 
Index: sandbox/workflow/trunk/inc/class.bo_monitors.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_monitors.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_monitors.inc.php	(revision 2372)
@@ -12,14 +12,10 @@
 require_once('class.bo_ajaxinterface.inc.php');
 
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'GUI' . SEP . 'GUI.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'InstanceManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'RoleManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessMonitor' . SEP . 'ProcessMonitor.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Instance.php');
-require_once('class.workflow_acl.inc.php');
-require_once('class.bo_adminaccess.inc.php');
-require_once('class.powergraphic.inc.php');
+
+/**
+ * DO NOT remove this line. Ever. Somehow, monitors interface will stop working..
+ */
+require_once(PHPGW_API_INC . SEP . 'common_functions.inc.php');
+
 
 /**
@@ -134,12 +130,12 @@
 	{
 		parent::bo_ajaxinterface();
-		$GLOBALS['ajax']->gui   = new GUI($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$GLOBALS['ajax']->gui   = &Factory::newInstance('GUI');
 		$this->userID 			= $_SESSION['phpgw_info']['workflow']['account_id'];
 		$this->isWorkflowAdmin  = $GLOBALS['ajax']->acl->checkWorkflowAdmin($this->userID);
-		$this->processManager   = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$this->activityManager  = new ActivityManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$this->instanceManager  = new InstanceManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$this->roleManager 		= new RoleManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
-		$this->processMonitor   = new ProcessMonitor($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$this->processManager   = &Factory::newInstance('ProcessManager');
+		$this->activityManager  = &Factory::newInstance('ActivityManager');
+		$this->instanceManager  = &Factory::newInstance('InstanceManager');
+		$this->roleManager 		= &Factory::newInstance('RoleManager');
+		$this->processMonitor   = &Factory::newInstance('ProcessMonitor');
 	}
 
@@ -169,8 +165,7 @@
 	private function convertFiltersToSQL($filters)
 	{
-		require_once 'nano/JSON.php';
 
 		/* desserializa os dados */
-		$JSON = new Services_JSON();
+		$JSON = &Factory::newInstance('Services_JSON');
 		/* desserializa a array principal, depois desserializa cada elemento desta array e, por fim, converte os elementos (que estão em forma de objeto) para array associativa */
 		$filters = array_map('get_object_vars', array_map(array($JSON, 'decode'), $JSON->decode($filters)));
@@ -335,8 +330,8 @@
 	   	$filters[] = '(gia.wf_user IS NOT NULL)';
 
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		if (!$completeData)
 		{
-			$paging = $GLOBALS['workflow']['factory']->newInstance('Paging', 500, $_POST);
+			$paging = Factory::newInstance('Paging', 500, $_POST);
 			$tmp = $this->processMonitor->monitor_list_instances($paging->nextItem, $paging->itemsPerPage, $order, '', implode(' AND ', $filters));
 			$output['data'] = $paging->restrictItems(array_values($tmp['data']), $tmp['cant']);
@@ -353,5 +348,5 @@
 		$activityMapping = array();
 		$instanceCount = count($output['data']);
-		$cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
+		$cachedLDAP = &Factory::getInstance('CachedLDAP');
 		for ($i = 0; $i < $instanceCount; $i++)
 		{
@@ -476,8 +471,8 @@
 		/* load the data */
 		$filters[] = '(gp.wf_p_id = ' . $params['pid'] . ')';
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		if (!$completeData)
 		{
-			$paging = $GLOBALS['workflow']['factory']->newInstance('Paging', 500, $_POST);
+			$paging = Factory::newInstance('Paging', 500, $_POST);
 			$tmp = $this->processMonitor->monitor_list_completed_instances($paging->nextItem, $paging->itemsPerPage, $order, '', implode(' AND ', $filters));
 			$output['data'] = $paging->restrictItems(array_values($tmp['data']), $tmp['cant']);
@@ -491,5 +486,5 @@
 		}
 
-		$cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
+		$cachedLDAP = &Factory::getInstance('CachedLDAP');
 		$userMapping = array();
 		$instanceCount = count($output['data']);
@@ -627,5 +622,5 @@
 			}
 			else
-				$output['fullname'] = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($user);
+				$output['fullname'] = Factory::getInstance('WorkflowLDAP')->getName($user);
 
 		$this->instanceManager->set_instance_user($params['iid'], $params['aid'], $user);
@@ -648,5 +643,5 @@
 		if ($params['ns'] == 'aborted')
 		{
-			$realInstance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			$realInstance = &Factory::newInstance('Instance');
 			$realInstance->getInstance($params['iid']);
 			if (!empty($realInstance->instanceId))
@@ -684,5 +679,5 @@
 
 		/* use next user or * for the new instance */
-		$realInstance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$realInstance = &Factory::newInstance('Instance');
 		$realInstance->getInstance($params['iid'], false, false);
 		$user = $realInstance->getNextUser($params['aid']);
@@ -751,5 +746,5 @@
 
 		$maximumDisplaySize = 100;
-		$instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$instance = &Factory::newInstance('Instance');
 		$instance->getInstance($params['iid']);
 
@@ -783,5 +778,5 @@
 			return "Você não tem permissão para executar este procedimento!";
 
-		$instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$instance = &Factory::newInstance('Instance');
 		$instance->getInstance($params['iid']);
 		$output = $params;
@@ -804,5 +799,5 @@
 		$maximumDisplaySize = 100;
 
-		$instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$instance = &Factory::newInstance('Instance');
 		$instance->getInstance($params['iid']);
 		$instance->set($params['name'], $params['value']);
@@ -835,5 +830,5 @@
 			return "Você não tem permissão para executar este procedimento!";
 
-		$instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$instance = &Factory::newInstance('Instance');
 		$instance->getInstance($params['iid']);
 		$instance->clear($params['name']);
@@ -858,5 +853,5 @@
 		$output = array();
 		$urlPrefix = 'workflow/inc/class.powergraphic.inc.php?';
-		$powergraphic = new powergraphic;
+		$powergraphic = &Factory::getInstance('powergraphic');
 		$powergraphic->graphic_1 = $params['pid'];
 		$powergraphic->skin = 1;
@@ -904,5 +899,5 @@
 		/* prepare the data */
 		$aux2 = array();
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		foreach ($aux as $user => $count)
 			$aux2[] = array(
@@ -984,5 +979,5 @@
 
 		/* load LDAP info and sort the result */
-		$foundUsers = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getNames($users);
+		$foundUsers = Factory::getInstance('WorkflowLDAP')->getNames($users);
 		usort($foundUsers, create_function('$a,$b', 'return strcasecmp($a[\'name\'],$b[\'name\']);'));
 
@@ -991,5 +986,5 @@
 		if (count($users) > count($foundUsers))
 		{
-			$cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
+			$cachedLDAP = &Factory::getInstance('CachedLDAP');
 			$foundUsersID = array_map(create_function('$a', 'return $a[\'id\'];'), $foundUsers);
 			$missingUsers = array_diff($users, $foundUsersID);
@@ -1242,5 +1237,5 @@
 			return $output;
 
-		$BOUserInterface = &$GLOBALS['workflow']['factory']->getInstance('bo_userinterface');
+		$BOUserInterface = &Factory::getInstance('bo_userinterface');
 
 		/* initialize some variables */
@@ -1344,5 +1339,5 @@
 
 		/* load the recipient e-mail */
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		foreach ($output as $key => $value)
 		{
@@ -1396,13 +1391,23 @@
 
 		/* prepare the environment to load some configuration values from other module */
-		$GLOBALS['phpgw']->db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
-		$GLOBALS['phpgw']->common = CreateObject('phpgwapi.common');
-		$GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');
+		$GLOBALS['phpgw']->db =& Factory::getInstance('WorkflowObjects')->getDBExpresso();
+		$GLOBALS['phpgw']->common = Factory::getInstance('common');
+		$GLOBALS['phpgw']->session = Factory::getInstance('sessions');
 		function lang($a){return $a;};
 
 		/* get the required configuration */
-		$BOEmailAdmin = $GLOBALS['workflow']['factory']->newForeignInstance('emailadmin', 'bo');
+		$BOEmailAdmin = Factory::getInstance('bo');
 		$profileList = $BOEmailAdmin->getProfileList();
 		$profile = $BOEmailAdmin->getProfile($profileList[0]['profileID']);
+
+		/**
+		 * XXX - XXX
+		 * It's weird.. There are two almost identical PHPMailer classes.
+		 * The class registered in our factory is under 'EGW_INC_ROOT'.
+		 * The class used here has the same name and it's under another
+		 * directory. For now, let's just include it in the old-fashion
+		 * way, but if someone, someday try to use both classes in the
+		 * same access, it could cause us troubles.
+		 */
 
 		/* configure the PHPMailer class to send the e-mails */
@@ -1494,6 +1499,6 @@
 	{
 		$output = array();
-		$cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
-		$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+		$cachedLDAP = &Factory::getInstance('CachedLDAP');
+		$ldap = &Factory::getInstance('WorkflowLDAP');
 		foreach ($userIDs as $userID)
 		{
@@ -1542,5 +1547,5 @@
 	   	$filters[] = '(gia.wf_user IS NOT NULL)';
 
-		$cachedLDAP = &$GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
+		$cachedLDAP = &Factory::newInstance('CachedLDAP');
 		$cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP);
 		$output = array();
@@ -1559,5 +1564,5 @@
 		}
 
-		$validUsers = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getNames(array_keys($userIDs));
+		$validUsers = Factory::getInstance('WorkflowLDAP')->getNames(array_keys($userIDs));
 		array_walk($validUsers, create_function('&$a', '$a = $a[\'id\'];'));
 
Index: sandbox/workflow/trunk/inc/class.ui_phpeditor.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_phpeditor.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_phpeditor.inc.php	(revision 2372)
@@ -11,5 +11,4 @@
 
 require_once dirname(__FILE__) . SEP . 'engine' . SEP . 'config.ajax.inc.php';
-require_once GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php';
 require_once dirname(__FILE__) . SEP . 'class.ui_ajaxinterface.inc.php';
 /**
@@ -45,5 +44,5 @@
 	function ui_phpeditor()
 	{
-		$this->bo = CreateObject('workflow.bo_editor');
+		$this->bo = Factory::getInstance('bo_editor');
 		$this->loadVariables();
 	}
@@ -62,6 +61,6 @@
 	function form()
 	{
-		$smarty = $GLOBALS['workflow']['factory']->getInstance('workflow_smarty', false);
-		$processManager = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+		$smarty = Factory::getInstance('workflow_smarty', false);
+		$processManager = &Factory::newInstance('ProcessManager');
 		$proccessInfo = $processManager->get_process($_GET['proc_id']);
 
Index: sandbox/workflow/trunk/inc/class.ResourcesRedirector.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ResourcesRedirector.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ResourcesRedirector.inc.php	(revision 2372)
@@ -54,5 +54,5 @@
 		if (!isset($_SESSION['workflow']['ResourcesRedirector'][$this->pid]))
 		{
-			$result = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID->query('SELECT wf_normalized_name FROM egw_wf_processes WHERE wf_p_id = ?', array($this->pid));
+			$result = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID->query('SELECT wf_normalized_name FROM egw_wf_processes WHERE wf_p_id = ?', array($this->pid));
 			if ($result->numRows() != 1)
 				return;
@@ -94,5 +94,5 @@
 				{
 					/* em último caso, tenta buscar a informação em banco de dados */
-					$result = $GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir'));
+					$result = Factory::getInstance('WorkflowObjects')->getDBExpresso()->Link_ID->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir'));
 					if (empty($result))
 						return;
Index: sandbox/workflow/trunk/inc/hook_sidebox_menu.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/hook_sidebox_menu.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/hook_sidebox_menu.inc.php	(revision 2372)
@@ -14,8 +14,9 @@
  */
 
+require_once 'common.inc.php';
 require_once 'engine/config.egw.inc.php';
 
 {
-	$workflowACL = CreateObject('workflow.workflow_acl');
+	$workflowACL = Factory::getInstance('workflow_acl');
 	$userID = $GLOBALS['phpgw_info']['user']['account_id'];
 	$apptitle = $GLOBALS['phpgw_info']['apps'][$appname]['title'];
Index: sandbox/workflow/trunk/inc/class.workflow_wfsecurity.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.workflow_wfsecurity.inc.php	(revision 1712)
+++ sandbox/workflow/trunk/inc/class.workflow_wfsecurity.inc.php	(revision 2372)
@@ -18,5 +18,5 @@
 		function workflow_wfsecurity()
 		{
-			parent::WfSecurity($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			parent::WfSecurity(Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID);
 		}
 	}
Index: sandbox/workflow/trunk/inc/class.ui_agent_mail_smtp.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_agent_mail_smtp.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_agent_mail_smtp.inc.php	(revision 2372)
@@ -29,5 +29,5 @@
 		parent::ui_agent();
 		$this->agent_type = 'mail_smtp';
-		$this->bo_agent = CreateObject('workflow.bo_agent_mail_smtp');
+		$this->bo_agent = Factory::getInstance('bo_agent_mail_smtp');
 	}
 
Index: sandbox/workflow/trunk/inc/class.ui_orgchart.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_orgchart.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_orgchart.inc.php	(revision 2372)
@@ -1,5 +1,5 @@
 <?php
 
-	/**************************************************************************\
+/**************************************************************************\
 * eGroupWare                                                 *
 * http://www.egroupware.org                                                *
@@ -12,5 +12,5 @@
 
 require_once(dirname(__FILE__) . SEP . 'class.ui_ajaxinterface.inc.php');
-require_once(dirname(__FILE__) . SEP . 'class.workflow_acl.inc.php');
+
 /**
  * @package Workflow
@@ -47,5 +47,5 @@
 	function draw($tab_index = "")
 	{
-		$this->workflow_acl = CreateObject('workflow.workflow_acl');
+		$this->workflow_acl = Factory::getInstance('workflow_acl');
 
 		$isAdmin = $this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']);
@@ -63,5 +63,5 @@
 
 		$GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$smarty = Factory::getInstance('workflow_smarty');
 
 		$this->set_wf_session();
@@ -104,10 +104,8 @@
 			die();
 
-		require_once(dirname(__FILE__) . SEP . 'engine' . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'GraphViz.php');
-
-		$config_values = CreateObject('phpgwapi.config','workflow');
+		$config_values = Factory::getInstance('config', 'workflow');
 		$config_values->read_repository();
-		$conf_db = $config_values->config_data;	
-		$db = CreateObject('phpgwapi.db');
+		$conf_db = $config_values->config_data;
+		$db = Factory::getInstance('db');
 		$db->connect(
 			$conf_db['database_name'],
@@ -122,5 +120,5 @@
 		$attributes['ranksep'] = '1.5 equally';
 		$attributes['rankdir'] = 'LR';
-		$graph = new Process_GraphViz(true, $attributes);
+		$graph = &Factory::getInstance('Process_GraphViz', true, $attributes);
 
 
@@ -153,5 +151,5 @@
 				return false;
 
-			$ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
+			$ldap = &Factory::getInstance('WorkflowLDAP');
 			for ($i = 0; $i < count($output); $i++)
 			{
Index: sandbox/workflow/trunk/inc/class.bo_editor.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_editor.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_editor.inc.php	(revision 2372)
@@ -11,6 +11,4 @@
 
 require_once('class.bo_ajaxinterface.inc.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
 /**
  * @package Workflow
@@ -234,5 +232,5 @@
 		if ($p['tipo_codigo'] != 'include')
 		{
-			$activity_manager   = new ActivityManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
+			$activity_manager   = &Factory::newInstance('ActivityManager');
 
 			if ($this->check_process($p['proc_id'], &$activity_manager, &$error_str) == 'n')
Index: sandbox/workflow/trunk/inc/class.ui_monitors.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_monitors.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_monitors.inc.php	(revision 2372)
@@ -12,5 +12,4 @@
 
 require_once(dirname(__FILE__) . SEP . 'class.ui_ajaxinterface.inc.php');
-require_once(dirname(__FILE__) . SEP . 'class.workflow_acl.inc.php');
 /**
  * @package Workflow
@@ -37,5 +36,5 @@
 	{
 		$this->set_wf_session();
-		$this->workflow_acl = new workflow_acl();
+		$this->workflow_acl = Factory::getInstance('workflow_acl');
 
 		if (!($this->workflow_acl->checkUserGroupAccessToType('MON', $_SESSION['phpgw_info']['workflow']['account_id']) || ($this->workflow_acl->checkWorkflowAdmin($_SESSION['phpgw_info']['workflow']['account_id']))))
@@ -58,5 +57,5 @@
 		$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('%1 monitoring');
 		$GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$smarty = Factory::getInstance('workflow_smarty');
 
 		$javaScripts = $this->get_common_js();
Index: sandbox/workflow/trunk/inc/class.ui_adminaccess.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.ui_adminaccess.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.ui_adminaccess.inc.php	(revision 2372)
@@ -41,5 +41,5 @@
 	function ui_adminaccess()
 	{
-		if (!$GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
+		if (!Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
 		{
 			$GLOBALS['phpgw']->common->phpgw_header();
@@ -63,5 +63,5 @@
 		$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Access Control List');
 		$GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
-		$smarty = CreateObject('workflow.workflow_smarty');
+		$smarty = Factory::getInstance('workflow_smarty');
 
 		$javaScripts = $this->get_common_js();
Index: sandbox/workflow/trunk/inc/class.bo_external_applications.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.bo_external_applications.inc.php	(revision 795)
+++ sandbox/workflow/trunk/inc/class.bo_external_applications.inc.php	(revision 2372)
@@ -11,5 +11,4 @@
 \**************************************************************************/
 
-require_once('class.so_external_applications.inc.php');
 require_once('class.bo_ajaxinterface.inc.php');
 /**
@@ -34,5 +33,5 @@
 	{
 		parent::bo_ajaxinterface();
-		$this->so = new so_external_applications();
+		$this->so = &Factory::getInstance('so_external_applications');
 	}
 
Index: sandbox/workflow/trunk/inc/class.process_factory.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.process_factory.inc.php	(revision 795)
+++ 	(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/trunk/inc/class.factory.inc.php
===================================================================
--- sandbox/workflow/trunk/inc/class.factory.inc.php	(revision 795)
+++ 	(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;
-		}
-	}
-}
-?>
Index: sandbox/workflow/trunk/index.php
===================================================================
--- sandbox/workflow/trunk/index.php	(revision 2193)
+++ sandbox/workflow/trunk/index.php	(revision 2372)
@@ -21,6 +21,5 @@
 			require_once dirname(__FILE__) . '/inc/nano/JSON.php';
 			require_once dirname(__FILE__) . '/inc/nano/NanoJsonConverter.class.php';
-			require_once dirname(__FILE__) . '/inc/nano/NanoController.class.php';
-			$nanoController = new NanoController();
+			$nanoController = &Factory::newInstance('NanoController');
 			$nanoController->throwErrorOnAllVirtualRequests('__NANOAJAX_SESSION_EXPIRED__');
 			exit;
