3 namespace Hub\Handler\Node\Answer\Request\NodeList;
5 // Import application-specific stuff
6 use Hub\Factory\Node\NodeObjectFactory;
7 use Hub\Network\Receive\Receivable;
9 // Import framework stuff
10 use CoreFramework\Criteria\Storing\StoreableCriteria;
11 use CoreFramework\Generic\UnsupportedOperationException;
12 use CoreFramework\Registry\Registerable;
15 * A NodeMessageRequestNodeListAnswer handler
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->setHandlerName('message_request_node_list_answer');
49 // Init message data array
50 $this->messageDataElements = array(
51 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
52 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
53 BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
56 // Init message-data->configuration translation array
57 $this->messageToConfig = array(
59 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
63 // Init search data array
64 $this->searchData = array(
65 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
70 * Creates an instance of this class
72 * @return $handlerInstance An instance of a HandleableMessage class
74 public final static function createNodeMessageRequestNodeListAnswerHandler () {
76 $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
78 // Return the prepared instance
79 return $handlerInstance;
83 * Handles data array of the message
85 * @param $messageData An array with message data to handle
86 * @param $packageInstance An instance of a Receivable class
88 * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
90 public function handleMessageData (array $messageData, Receivable $packageInstance) {
92 $nodeInstance = NodeObjectFactory::createNodeInstance();
94 // Has this node attempted to announce itself?
95 if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
97 * This node has never announced itself, so it doesn't expect
98 * request-node-list answer messages.
100 throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
103 // Register the announcing node with this node
104 $this->registerNodeByMessageData($messageData);
106 // Handle the answer status element
107 $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
111 * Adds all required elements from given array into data set instance
113 * @param $dataSetInstance An instance of a StoreableCriteria class
114 * @param $messageData An array with all message data
117 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
119 parent::addArrayToDataSet($dataSetInstance, $messageData);
122 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData=' . print_r($messageData, TRUE));
125 foreach ($this->messageDataElements as $key) {
127 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
130 assert(isset($messageData[$key]));
133 * Add it, but remove any 'my-' prefixes as they are not used in
136 $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
141 * Initializes configuration data from given message data array
143 * @param $messageData An array with all message data
145 * @throws UnsupportedOperationException If this method is called
147 protected function initMessageConfigurationData (array $messageData) {
148 // Please don't call this method
149 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
153 * Removes configuration data with given message data array from global
156 * @param $messageData An array with all message data
158 * @throws UnsupportedOperationException If this method is called
160 protected function removeMessageConfigurationData (array $messageData) {
161 // Please don't call this method
162 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);