3 * A Descriptor hub helper class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
10 * @todo Find an interface for hub helper
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class HubDescriptorHelper extends BaseHubHelper {
27 * Protected constructor
31 protected function __construct () {
32 // Call parent constructor
33 parent::__construct(__CLASS__);
37 * Creates the helper class
39 * @param $nodeInstance An instance of a NodeHelper class
40 * @return $helperInstance A prepared instance of this helper
42 public final static function createHubDescriptorHelper (NodeHelper $nodeInstance) {
44 $helperInstance = new HubDescriptorHelper();
46 // Set the node instance
47 $helperInstance->setNodeInstance($nodeInstance);
49 // Return the prepared instance
50 return $helperInstance;
54 * Loads the announcement descriptor for parsing
57 * @todo Rewrite the ->renderXmlContent() call to no arguments
59 public function loadAnnouncementDescriptor () {
61 $this->debugOutput('HELPER: Starting with announcement to upper hubs...');
63 // Get the application instance
64 $appInstance = Registry::getRegistry()->getInstance('app');
66 // Get a XML template instance
67 $templateInstance = ObjectFactory::createObjectByConfiguredName('announcement_template_class', array($appInstance));
69 // Disable language support
70 $templateInstance->enableLanguageSupport(false);
72 // Enable compacting/rewriting of the XML to save bandwidth from XML
73 // comments. This is expensive and should be avoided in general.
74 $templateInstance->enableXmlCompacting();
76 // Set it for later use
77 $this->setTemplateInstance($templateInstance);
79 // Get an XML parser instance
80 $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this->getTemplateInstance()));
82 // Read the XML descriptor
83 $this->getTemplateInstance()->loadAnnouncementTemplate('self_announcement');
85 // Render the XML content
86 $this->getTemplateInstance()->renderXmlContent();
90 * Publishes the node's descriptor XML to all found upper nodes when the
91 * node has not yet published it's descriptor to a bootstrap node. This is
92 * done by getting the raw XML content and inserting all variables into
93 * the code. After this wents fine, the rendered content got "packaged"
94 * for network delivery.
98 public function publishAnnouncementDescriptor () {
99 // Is the node in the approx state? (active)
100 $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive();
102 // Compile the template, this inserts the loaded node data into the gaps.
103 $this->getTemplateInstance()->compileTemplate();
105 // Prepare the compressor for our package, GZIP should be fine but we
106 // keep it open here so you can experiment with the settings and don't
107 // need to touch any code.
108 $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class');
110 // Prepare the decorator compressor (for later flawless and easy updates)
111 $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance));
113 // Now prepare the network package for delivery so only need to do this
114 // once just before the "big announcement loop".
115 $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance));
117 // Enable re-queue support which re-queues the below feeded content
118 // into the delivery method all over again.
119 $packageInstance->enableDataReQueueing();
121 // Next, feed the content in. The network package class is a pipe-through class.
122 $packageInstance->queueRawDataFromTemplate($this->getTemplateInstance());
125 /* DEBUG: */ die(print_r($this->getTemplateInstance(), true));