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\Receive\Receivable;
10 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Request\NodeList\XmlRequestNodeListAnswerTemplateEngine;
11 use Org\Shipsimu\Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
12 use Org\Shipsimu\Hub\Template\Engine\Xml\Request\NodeList\XmlRequestNodeListTemplateEngine;
14 // Import framework stuff
15 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
16 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
17 use Org\Mxchange\CoreFramework\Registry\Registerable;
20 * A NodeMessageRequestNodeListAnswer handler
22 * @author Roland Haeder <webmaster@shipsimu.org>
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
25 * @license GNU GPL 3.0 or any newer version
26 * @link http://www.shipsimu.org
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
41 class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
43 * Protected constructor
47 protected function __construct () {
48 // Call parent constructor
49 parent::__construct(__CLASS__);
52 $this->setHandlerName('message_request_node_list_answer');
54 // Init message data array
55 $this->messageDataElements = array(
56 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
57 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
58 BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
61 // Init message-data->configuration translation array
62 $this->messageToConfig = array(
64 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
68 // Init search data array
69 $this->searchData = array(
70 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
75 * Creates an instance of this class
77 * @return $handlerInstance An instance of a HandleableMessage class
79 public final static function createNodeMessageRequestNodeListAnswerHandler () {
81 $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
83 // Return the prepared instance
84 return $handlerInstance;
88 * Handles data array of the message
90 * @param $messageData An array with message data to handle
91 * @param $packageInstance An instance of a Receivable class
93 * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
95 public function handleMessageData (array $messageData, Receivable $packageInstance) {
97 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
98 $nodeInstance = NodeObjectFactory::createNodeInstance();
100 // Has this node attempted to announce itself?
101 if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
103 * This node has never announced itself, so it doesn't expect
104 * request-node-list answer messages.
106 throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
109 // Register the announcing node with this node
110 $this->registerNodeByMessageData($messageData);
112 // Handle the answer status element
113 $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
117 * Adds all required elements from given array into data set instance
119 * @param $dataSetInstance An instance of a StoreableCriteria class
120 * @param $messageData An array with all message data
123 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
125 parent::addArrayToDataSet($dataSetInstance, $messageData);
128 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData=' . print_r($messageData, TRUE));
131 foreach ($this->messageDataElements as $key) {
133 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
136 assert(isset($messageData[$key]));
139 * Add it, but remove any 'my-' prefixes as they are not used in
142 $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
147 * Initializes configuration data from given message data array
149 * @param $messageData An array with all message data
151 * @throws UnsupportedOperationException If this method is called
153 protected function initMessageConfigurationData (array $messageData) {
154 // Please don't call this method
155 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
159 * Removes configuration data with given message data array from global
162 * @param $messageData An array with all message data
164 * @throws UnsupportedOperationException If this method is called
166 protected function removeMessageConfigurationData (array $messageData) {
167 // Please don't call this method
168 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);