3 namespace Org\Shipsimu\Hub\Node\Helper\Answer\Announcement;
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 AnnouncementMessageAnswer 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 NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->setPackageTags(array('announcement_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 createNodeAnnouncementMessageAnswerHelper (array $messageData) {
58 $helperInstance = new NodeAnnouncementMessageAnswerHelper();
60 // Set session id of other peer as recipient
61 $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_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 an announcement...');
80 // Get a XML template instance
81 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
83 // Set it for later use
84 $this->setTemplateInstance($templateInstance);
86 // Read the XML descriptor
87 $templateInstance->loadXmlTemplate();
89 // Render the XML content
90 $templateInstance->renderXmlContent();
94 * Send out announcement answer package
96 * @param $nodeInstance An instance of a NodeHelper class
99 public function sendPackage (NodeHelper $nodeInstance) {
100 // Sanity check: Is the node in the approx. state? (active/reachable)
101 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
103 // Compile the template, this inserts the loaded node data into the gaps.
104 $this->getTemplateInstance()->compileTemplate();
106 // Get a singleton network package instance
107 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
109 // Next, feed the content in. The network package class is a pipe-through class.
110 $packageInstance->enqueueRawDataFromTemplate($this);