]> git.mxchange.org Git - hub.git/blob - application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php
4d5d1219503cd34e09d245d37e2dd98d9aa6d2d1
[hub.git] / application / hub / main / handler / answer-status / class_BaseAnserStatusHandler.php
1 <?php
2 /**
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
8  * on a message.
9  *
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.
15  *
16  * @author              Roland Haeder <webmaster@ship-simu.org>
17  * @version             0.0.0
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
21  *
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.
26  *
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.
31  *
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/>.
34  */
35 class BaseAnserStatusHandler extends BaseHandler {
36         /**
37          * Last exception instance from database layer or NULL (default)
38          */
39         private $lastException = NULL;
40
41         /**
42          * Protected constructor
43          *
44          * @param       $className      Name of the class
45          * @return      void
46          */
47         protected function __construct ($className) {
48                 // Call parent constructor
49                 parent::__construct($className);
50         }
51
52         /**
53          * Getter for last exception
54          *
55          * @return      $lastException  Last thrown exception
56          */
57         protected final function getLastException () {
58                 return $this->lastException;
59         }
60
61         /**
62          * Adds all required elements from given array into data set instance
63          *
64          * @param       $dataSetInstance        An instance of a StoreableCriteria class
65          * @param       $messageData            An array with all message data
66          * @return      void
67          */
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]);
72         }
73
74         /**
75          * Prepares the next message
76          *
77          * @param       $messageData            An array with all message data
78          * @param       $packageInstance        An instance of a Deliverable instance
79          * @return      void
80          */
81         protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
82                 // Debug message
83                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send next message ...');
84
85                 // Get a helper instance based on this handler's name
86                 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
87
88                 // Load descriptor XML
89                 $helperInstance->loadDescriptorXml();
90
91                 /*
92                  * Set missing (temporary) configuration data, mostly it needs to be
93                  * copied from message data array.
94                  */
95                 $this->initMessageConfigurationData($messageData);
96
97                 // Compile any configuration variables
98                 $helperInstance->getTemplateInstance()->compileConfigInVariables();
99
100                 // Get node instance
101                 $nodeInstance = Registry::getRegistry()->getInstance('node');
102
103                 // Deliver the package
104                 $helperInstance->sendPackage($nodeInstance);
105
106                 /*
107                  * Remove temporary configuration
108                  */
109                 $this->removeMessageConfigurationData($messageData);
110
111                 // Debug message
112                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Next message has been prepared.');
113         }
114 }
115
116 // [EOF]
117 ?>