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\Registry\Registerable;
14 * A NodeMessageRequestNodeListAnswer handler
16 * @author Roland Haeder <webmaster@shipsimu.org>
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.shipsimu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
46 $this->setHandlerName('message_request_node_list_answer');
48 // Init message data array
49 $this->messageDataElements = array(
50 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
51 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
52 BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
55 // Init message-data->configuration translation array
56 $this->messageToConfig = array(
58 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
62 // Init search data array
63 $this->searchData = array(
64 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
69 * Creates an instance of this class
71 * @return $handlerInstance An instance of a HandleableMessage class
73 public final static function createNodeMessageRequestNodeListAnswerHandler () {
75 $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
77 // Return the prepared instance
78 return $handlerInstance;
82 * Handles data array of the message
84 * @param $messageData An array with message data to handle
85 * @param $packageInstance An instance of a Receivable class
87 * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
89 public function handleMessageData (array $messageData, Receivable $packageInstance) {
91 $nodeInstance = NodeObjectFactory::createNodeInstance();
93 // Has this node attempted to announce itself?
94 if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
96 * This node has never announced itself, so it doesn't expect
97 * request-node-list answer messages.
99 throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
102 // Register the announcing node with this node
103 $this->registerNodeByMessageData($messageData);
105 // Handle the answer status element
106 $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
110 * Adds all required elements from given array into data set instance
112 * @param $dataSetInstance An instance of a StoreableCriteria class
113 * @param $messageData An array with all message data
116 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
118 parent::addArrayToDataSet($dataSetInstance, $messageData);
121 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
124 foreach ($this->messageDataElements as $key) {
126 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData[' . $key . ']=' . $messageData[$key]);
129 assert(isset($messageData[$key]));
132 * Add it, but remove any 'my-' prefixes as they are not used in
135 $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
140 * Initializes configuration data from given message data array
142 * @param $messageData An array with all message data
144 * @throws UnsupportedOperationException If this method is called
146 protected function initMessageConfigurationData (array $messageData) {
147 // Please don't call this method
148 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
152 * Removes configuration data with given message data array from global
155 * @param $messageData An array with all message data
157 * @throws UnsupportedOperationException If this method is called
159 protected function removeMessageConfigurationData (array $messageData) {
160 // Please don't call this method
161 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);