3 namespace Org\Shipsimu\Hub\Handler\Node\Answer\Request\NodeList;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
7 use Org\Shipsimu\Hub\Handler\Message\BaseMessageHandler;
8 use Org\Shipsimu\Hub\Handler\Message\HandleableMessage;
9 use Org\Shipsimu\Hub\Network\Message\DeliverableMessage;
10 use Org\Shipsimu\Hub\Network\Receive\Receivable;
11 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Request\NodeList\XmlRequestNodeListAnswerTemplateEngine;
12 use Org\Shipsimu\Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
13 use Org\Shipsimu\Hub\Template\Engine\Xml\Request\NodeList\XmlRequestNodeListTemplateEngine;
15 // Import framework stuff
16 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
17 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
18 use Org\Mxchange\CoreFramework\Registry\Registerable;
21 * A NodeMessageRequestNodeListAnswer handler
23 * @author Roland Haeder <webmaster@shipsimu.org>
25 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
26 * @license GNU GPL 3.0 or any newer version
27 * @link http://www.shipsimu.org
29 * This program is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program. If not, see <http://www.gnu.org/licenses/>.
42 class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
44 * Protected constructor
48 protected function __construct () {
49 // Call parent constructor
50 parent::__construct(__CLASS__);
53 $this->setHandlerName('message_request_node_list_answer');
55 // Init message data array
56 $this->messageDataElements = array(
57 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
58 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
59 BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
62 // Init message-data->configuration translation array
63 $this->messageToConfig = array(
65 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
69 // Init search data array
70 $this->searchData = array(
71 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
76 * Creates an instance of this class
78 * @return $handlerInstance An instance of a HandleableMessage class
80 public final static function createNodeMessageRequestNodeListAnswerHandler () {
82 $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
84 // Return the prepared instance
85 return $handlerInstance;
89 * Handles data array of the message
91 * @param $messageInstance An instance of a DeliverableMessage class
92 * @param $packageInstance An instance of a Receivable class
94 * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
96 public function handleMessageData (DeliverableMessage $messageInstance, Receivable $packageInstance) {
98 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
99 $nodeInstance = NodeObjectFactory::createNodeInstance();
101 // Has this node attempted to announce itself?
102 if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
104 * This node has never announced itself, so it doesn't expect
105 * request-node-list answer messages.
107 throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageInstance), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
110 // Register the announcing node with this node
111 $this->registerNodeByMessageInstance($messageInstance);
113 // Handle the answer status element
114 $nodeInstance->handleAnswerStatusByMessageInstance($messageInstance, $packageInstance);
118 * Adds all required elements from given array into data set instance
120 * @param $dataSetInstance An instance of a StoreableCriteria class
121 * @param $messageInstance An instance of a DeliverableMessage class
124 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, DeliverableMessage $messageInstance) {
126 parent::addArrayToDataSet($dataSetInstance, $messageInstance);
129 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageInstance=' . print_r($messageInstance, TRUE));
132 foreach ($this->messageDataElements as $key) {
134 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
137 assert(isset($messageData[$key]));
140 * Add it, but remove any 'my-' prefixes as they are not used in
143 $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
148 * Initializes configuration data from given message data array
150 * @param $messageInstance An instance of a DeliverableMessage class
152 * @throws UnsupportedOperationException If this method is called
154 protected function initMessageConfigurationData (DeliverableMessage $messageInstance) {
155 // Please don't call this method
156 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
160 * Removes configuration data with given message data array from global
163 * @param $messageInstance An instance of a DeliverableMessage class
165 * @throws UnsupportedOperationException If this method is called
167 protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) {
168 // Please don't call this method
169 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);