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;
13 * A NodeMessageRequestNodeListAnswer handler
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
45 $this->setHandlerName('message_request_node_list_answer');
47 // Init message data array
48 $this->messageDataElements = array(
49 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
50 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
51 BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
54 // Init message-data->configuration translation array
55 $this->messageToConfig = array(
57 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
61 // Init search data array
62 $this->searchData = array(
63 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
68 * Creates an instance of this class
70 * @return $handlerInstance An instance of a HandleableMessage class
72 public final static function createNodeMessageRequestNodeListAnswerHandler () {
74 $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
76 // Return the prepared instance
77 return $handlerInstance;
81 * Handles data array of the message
83 * @param $messageData An array with message data to handle
84 * @param $packageInstance An instance of a Receivable class
86 * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
88 public function handleMessageData (array $messageData, Receivable $packageInstance) {
90 $nodeInstance = NodeObjectFactory::createNodeInstance();
92 // Has this node attempted to announce itself?
93 if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
95 * This node has never announced itself, so it doesn't expect
96 * request-node-list answer messages.
98 throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
101 // Register the announcing node with this node
102 $this->registerNodeByMessageData($messageData);
104 // Handle the answer status element
105 $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
109 * Adds all required elements from given array into data set instance
111 * @param $dataSetInstance An instance of a StoreableCriteria class
112 * @param $messageData An array with all message data
115 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
117 parent::addArrayToDataSet($dataSetInstance, $messageData);
120 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
123 foreach ($this->messageDataElements as $key) {
125 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData[' . $key . ']=' . $messageData[$key]);
128 assert(isset($messageData[$key]));
131 * Add it, but remove any 'my-' prefixes as they are not used in
134 $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
139 * Initializes configuration data from given message data array
141 * @param $messageData An array with all message data
143 * @throws UnsupportedOperationException If this method is called
145 protected function initMessageConfigurationData (array $messageData) {
146 // Please don't call this method
147 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
151 * Removes configuration data with given message data array from global
154 * @param $messageData An array with all message data
156 * @throws UnsupportedOperationException If this method is called
158 protected function removeMessageConfigurationData (array $messageData) {
159 // Please don't call this method
160 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);