3 namespace Hub\Node\Helper\Answer\Announcement;
5 // Import application-specific stuff
6 use Hub\Factory\Network\NetworkPackageFactory;
7 use Hub\Helper\Node\NodeHelper;
9 // Import framework stuff
10 use CoreFramework\Factory\Template\XmlTemplateEngineFactory;
13 * A AnnouncementMessageAnswer node helper class
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
20 * @todo Find an interface for hub helper
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 NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
46 $this->setPackageTags(array('announcement_answer'));
50 * Creates the helper class
52 * @param $messageData An array with all message data
53 * @return $helperInstance A prepared instance of this helper
55 public final static function createNodeAnnouncementMessageAnswerHelper (array $messageData) {
57 $helperInstance = new NodeAnnouncementMessageAnswerHelper();
59 // Set session id of other peer as recipient
60 $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
63 $helperInstance->setMessageData($messageData);
65 // Return the prepared instance
66 return $helperInstance;
70 * Loads the descriptor XML file
72 * @param $nodeInstance An instance of a NodeHelper class
75 public function loadDescriptorXml (NodeHelper $nodeInstance) {
77 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting to answer an announcement...');
79 // Get a XML template instance
80 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
82 // Set it for later use
83 $this->setTemplateInstance($templateInstance);
85 // Read the XML descriptor
86 $templateInstance->loadXmlTemplate();
88 // Render the XML content
89 $templateInstance->renderXmlContent();
93 * Send out announcement answer package
95 * @param $nodeInstance An instance of a NodeHelper class
98 public function sendPackage (NodeHelper $nodeInstance) {
99 // Sanity check: Is the node in the approx. state? (active/reachable)
100 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
102 // Compile the template, this inserts the loaded node data into the gaps.
103 $this->getTemplateInstance()->compileTemplate();
105 // Get a singleton network package instance
106 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
108 // Next, feed the content in. The network package class is a pipe-through class.
109 $packageInstance->enqueueRawDataFromTemplate($this);