3 namespace CoreFramework\Handler\Data;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Generic\FrameworkException;
10 * A general data Handler
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 abstract class BaseDataHandler extends BaseHandler {
33 * Last exception instance from database layer or NULL (default)
35 private $lastException = NULL;
38 * Array with search criteria elements
40 protected $searchData = array();
43 * Array with all data XML nodes (which hold the actual data) and their values
45 protected $messageDataElements = array();
48 * Array for translating message data elements (other node's data mostly)
49 * into configuration elements.
51 protected $messageToConfig = array();
54 * Array for copying configuration entries
56 protected $configCopy = array();
59 * Protected constructor
61 * @param $className Name of the class
64 protected function __construct ($className) {
65 // Call parent constructor
66 parent::__construct($className);
69 $dhtInstance = DhtObjectFactory::createDhtInstance('node');
72 $this->setDhtInstance($dhtInstance);
76 * Getter for search data array
78 * @return $searchData Search data array
80 public final function getSearchData () {
81 return $this->searchData;
85 * Getter for last exception
87 * @return $lastException Last thrown exception
89 public final function getLastException () {
90 return $this->lastException;
94 * Setter for last exception
96 * @param $lastException Last thrown exception
99 public final function setLastException (FrameworkException $exceptionInstance = NULL) {
100 $this->lastException = $exceptionInstance;
104 * Prepares a message as answer for given message data for delivery.
106 * @param $messageData An array with all message data
107 * @param $packageInstance An instance of a Deliverable instance
110 protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) {
112 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send an answer message for ' . $this->getHandlerName() . ' ...');
114 // Get a helper instance based on this handler's name
115 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
118 $nodeInstance = NodeObjectFactory::createNodeInstance();
120 // Load descriptor XML
121 $helperInstance->loadDescriptorXml($nodeInstance);
124 * Set missing (temporary) configuration data, mostly it needs to be
125 * copied from message data array.
127 $this->initMessageConfigurationData($messageData);
129 // Compile any configuration variables
130 $helperInstance->getTemplateInstance()->compileConfigInVariables();
132 // Deliver the package
133 $helperInstance->sendPackage($nodeInstance);
136 * Remove temporary configuration
138 $this->removeMessageConfigurationData($messageData);
141 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Answer message has been prepared.');
145 * Prepares the next message
147 * @param $messageData An array with all message data
148 * @param $packageInstance An instance of a Deliverable instance
151 protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
153 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send next message ...');
155 // Get a helper instance based on this handler's name
156 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
159 $nodeInstance = NodeObjectFactory::createNodeInstance();
161 // Load descriptor XML
162 $helperInstance->loadDescriptorXml($nodeInstance);
165 * Set missing (temporary) configuration data, mostly it needs to be
166 * copied from message data array.
168 $this->initMessageConfigurationData($messageData);
170 // Compile any configuration variables
171 $helperInstance->getTemplateInstance()->compileConfigInVariables();
173 // Deliver the package
174 $helperInstance->sendPackage($nodeInstance);
177 * Remove temporary configuration
179 $this->removeMessageConfigurationData($messageData);
182 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Next message has been prepared.');
186 * Initializes configuration data from given message data array
188 * @param $messageData An array with all message data
191 abstract protected function initMessageConfigurationData (array $messageData);
194 * Removes configuration data with given message data array from global
197 * @param $messageData An array with all message data
200 abstract protected function removeMessageConfigurationData (array $messageData);