3 * A general answer-status handler. So called "answer-status handler" are
4 * classes which handles a message field 'answer-status' which is, alongside
5 * many other node-relevant data, the main part of the answer message. These
6 * answer messages, by the way, are never sent unrequested. This, however,
7 * sounds logical because the answer is a reply from a node that has responded
10 * The answer-status field gives information back to the requesting node if the
11 * receiving node could handle the message properly (all verfication steps are
12 * passed, message type was understood, correct receiver, et cetera) and how
13 * it handles it. Some messages may be rejected, e.g. when the requesting node
14 * is blacklisted or its behavour has changed.
16 * @author Roland Haeder <webmaster@ship-simu.org>
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.ship-simu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class BaseAnserStatusHandler extends BaseHandler {
37 * Last exception instance from database layer or NULL (default)
39 private $lastException = NULL;
42 * Protected constructor
44 * @param $className Name of the class
47 protected function __construct ($className) {
48 // Call parent constructor
49 parent::__construct($className);
53 * Getter for last exception
55 * @return $lastException Last thrown exception
57 protected final function getLastException () {
58 return $this->lastException;
62 * Adds all required elements from given array into data set instance
64 * @param $dataSetInstance An instance of a StoreableCriteria class
65 * @param $messageData An array with all message data
68 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
69 // Add some generic data all messageData arrays provide
70 $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]);
71 $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_MESSAGE_TYPE , $messageData[NetworkPackage::MESSAGE_ARRAY_TYPE]);
75 * Prepares the next message
77 * @param $messageData An array with all message data
78 * @param $packageInstance An instance of a Deliverable instance
81 protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
83 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send next message ...');
85 // Get a helper instance based on this handler's name
86 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
88 // Load descriptor XML
89 $helperInstance->loadDescriptorXml();
92 * Set missing (temporary) configuration data, mostly it needs to be
93 * copied from message data array.
95 $this->initMessageConfigurationData($messageData);
97 // Compile any configuration variables
98 $helperInstance->getTemplateInstance()->compileConfigInVariables();
101 $nodeInstance = Registry::getRegistry()->getInstance('node');
103 // Deliver the package
104 $helperInstance->sendPackage($nodeInstance);
107 * Remove temporary configuration
109 $this->removeMessageConfigurationData($messageData);
112 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Next message has been prepared.');