3 namespace Hub\Handler\Node\Answer\Request\NodeList;
5 // Import application-specific stuff
6 use Hub\Factory\Node\NodeObjectFactory;
9 * A NodeMessageRequestNodeListAnswer handler
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
32 * Protected constructor
36 protected function __construct () {
37 // Call parent constructor
38 parent::__construct(__CLASS__);
41 $this->setHandlerName('message_request_node_list_answer');
43 // Init message data array
44 $this->messageDataElements = array(
45 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
46 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
47 BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
50 // Init message-data->configuration translation array
51 $this->messageToConfig = array(
53 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
57 // Init search data array
58 $this->searchData = array(
59 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
64 * Creates an instance of this class
66 * @return $handlerInstance An instance of a HandleableMessage class
68 public final static function createNodeMessageRequestNodeListAnswerHandler () {
70 $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
72 // Return the prepared instance
73 return $handlerInstance;
77 * Handles data array of the message
79 * @param $messageData An array with message data to handle
80 * @param $packageInstance An instance of a Receivable class
82 * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
84 public function handleMessageData (array $messageData, Receivable $packageInstance) {
86 $nodeInstance = NodeObjectFactory::createNodeInstance();
88 // Has this node attempted to announce itself?
89 if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
91 * This node has never announced itself, so it doesn't expect
92 * request-node-list answer messages.
94 throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
97 // Register the announcing node with this node
98 $this->registerNodeByMessageData($messageData);
100 // Handle the answer status element
101 $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
105 * Adds all required elements from given array into data set instance
107 * @param $dataSetInstance An instance of a StoreableCriteria class
108 * @param $messageData An array with all message data
111 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
113 parent::addArrayToDataSet($dataSetInstance, $messageData);
116 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
119 foreach ($this->messageDataElements as $key) {
121 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData[' . $key . ']=' . $messageData[$key]);
124 assert(isset($messageData[$key]));
127 * Add it, but remove any 'my-' prefixes as they are not used in
130 $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
135 * Initializes configuration data from given message data array
137 * @param $messageData An array with all message data
139 * @throws UnsupportedOperationException If this method is called
141 protected function initMessageConfigurationData (array $messageData) {
142 // Please don't call this method
143 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
147 * Removes configuration data with given message data array from global
150 * @param $messageData An array with all message data
152 * @throws UnsupportedOperationException If this method is called
154 protected function removeMessageConfigurationData (array $messageData) {
155 // Please don't call this method
156 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);