3 namespace Org\Shipsimu\Hub\Node\Helper\Answer\Request\NodeList;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
7 use Org\Shipsimu\Hub\Helper\Node\NodeHelper;
8 use Org\Shipsimu\Hub\Node\Helper\HelpableNode;
10 // Import framework stuff
11 use Org\Mxchange\CoreFramework\Factory\Template\XmlTemplateEngineFactory;
14 * A RequestNodeListMessageAnswer node helper class
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
21 * @todo Find an interface for hub helper
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 NodeRequestNodeListMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->setPackageTags(array('request_node_list_answer'));
51 * Creates the helper class
53 * @param $messageData An array with all message data
54 * @return $helperInstance A prepared instance of this helper
56 public final static function createNodeRequestNodeListMessageAnswerHelper (array $messageData) {
58 $helperInstance = new NodeRequestNodeListMessageAnswerHelper();
60 // Set session id of other peer as recipient
61 $helperInstance->setRecipientType($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
64 $helperInstance->setMessageData($messageData);
66 // Return the prepared instance
67 return $helperInstance;
71 * Loads the descriptor XML file
73 * @param $nodeInstance An instance of a NodeHelper class
76 public function loadDescriptorXml (NodeHelper $nodeInstance) {
78 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting to answer a request: node-list...');
80 // Get a XML template instance
81 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_answer_template_class');
83 // Set it for later use
84 $this->setTemplateInstance($templateInstance);
86 // Read the XML descriptor
87 $templateInstance->loadXmlTemplate();
89 // "Cache" entries instance for next foreach loop
90 $entriesInstance = $templateInstance->getTemplateInstance();
92 // Is must not be NULL (then it can only be a template instance)
93 assert(!is_null($entriesInstance));
95 // Render the XML content
96 $templateInstance->renderXmlContent();
100 * Send out request-node-list answer package
102 * @param $nodeInstance An instance of a NodeHelper class
105 public function sendPackage (NodeHelper $nodeInstance) {
106 // Sanity check: Is the node in the approx. state? (active/reachable)
107 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
109 // Compile the template, this inserts the loaded node data into the gaps.
110 $this->getTemplateInstance()->compileTemplate();
112 // Get a singleton network package instance
113 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
115 // Next, feed the content in. The network package class is a pipe-through class.
116 $packageInstance->enqueueRawDataFromTemplate($this);