3 namespace CoreFramework\Handler\Data;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
9 * A general data Handler
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 abstract class BaseDataHandler extends BaseHandler {
32 * Last exception instance from database layer or NULL (default)
34 private $lastException = NULL;
37 * Array with search criteria elements
39 protected $searchData = array();
42 * Array with all data XML nodes (which hold the actual data) and their values
44 protected $messageDataElements = array();
47 * Array for translating message data elements (other node's data mostly)
48 * into configuration elements.
50 protected $messageToConfig = array();
53 * Array for copying configuration entries
55 protected $configCopy = array();
58 * Protected constructor
60 * @param $className Name of the class
63 protected function __construct ($className) {
64 // Call parent constructor
65 parent::__construct($className);
68 $dhtInstance = DhtObjectFactory::createDhtInstance('node');
71 $this->setDhtInstance($dhtInstance);
75 * Getter for search data array
77 * @return $searchData Search data array
79 public final function getSearchData () {
80 return $this->searchData;
84 * Getter for last exception
86 * @return $lastException Last thrown exception
88 public final function getLastException () {
89 return $this->lastException;
93 * Setter for last exception
95 * @param $lastException Last thrown exception
98 public final function setLastException (FrameworkException $exceptionInstance = NULL) {
99 $this->lastException = $exceptionInstance;
103 * Prepares a message as answer for given message data for delivery.
105 * @param $messageData An array with all message data
106 * @param $packageInstance An instance of a Deliverable instance
109 protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) {
111 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send an answer message for ' . $this->getHandlerName() . ' ...');
113 // Get a helper instance based on this handler's name
114 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
117 $nodeInstance = NodeObjectFactory::createNodeInstance();
119 // Load descriptor XML
120 $helperInstance->loadDescriptorXml($nodeInstance);
123 * Set missing (temporary) configuration data, mostly it needs to be
124 * copied from message data array.
126 $this->initMessageConfigurationData($messageData);
128 // Compile any configuration variables
129 $helperInstance->getTemplateInstance()->compileConfigInVariables();
131 // Deliver the package
132 $helperInstance->sendPackage($nodeInstance);
135 * Remove temporary configuration
137 $this->removeMessageConfigurationData($messageData);
140 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Answer message has been prepared.');
144 * Prepares the next message
146 * @param $messageData An array with all message data
147 * @param $packageInstance An instance of a Deliverable instance
150 protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
152 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send next message ...');
154 // Get a helper instance based on this handler's name
155 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
158 $nodeInstance = NodeObjectFactory::createNodeInstance();
160 // Load descriptor XML
161 $helperInstance->loadDescriptorXml($nodeInstance);
164 * Set missing (temporary) configuration data, mostly it needs to be
165 * copied from message data array.
167 $this->initMessageConfigurationData($messageData);
169 // Compile any configuration variables
170 $helperInstance->getTemplateInstance()->compileConfigInVariables();
172 // Deliver the package
173 $helperInstance->sendPackage($nodeInstance);
176 * Remove temporary configuration
178 $this->removeMessageConfigurationData($messageData);
181 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Next message has been prepared.');
185 * Initializes configuration data from given message data array
187 * @param $messageData An array with all message data
190 abstract protected function initMessageConfigurationData (array $messageData);
193 * Removes configuration data with given message data array from global
196 * @param $messageData An array with all message data
199 abstract protected function removeMessageConfigurationData (array $messageData);