From 8e90b922c66aa345f5a6547b2535f90f49310857 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 18 Aug 2012 21:08:38 +0000 Subject: [PATCH] Development of 'hub' project continued: - Added helper for receiving node list - Added XML for above helper (unfinished) - Added template engine ("frontend class") for above XML - Added more missing configuration entries --- .gitattributes | 6 + application/hub/config.php | 15 + .../class_PackageRecipientDiscovery.php | 2 +- .../class_AnnouncementAnswerOkayHandler.php | 23 +- .../hub/main/handler/answer-status/class_ | 2 +- .../class_BaseAnserStatusHandler.php | 57 +--- .../main/handler/class_BaseDataHandler.php | 182 ++++++++++++ .../class_BaseMessageHandler.php | 101 +------ .../class_HubAnnouncementHelper.php | 2 +- .../hub/main/helper/hub/requests/.htaccess | 1 + .../class_NodeRequestNodeListHelper.php | 96 ++++++ .../hub/main/package/class_NetworkPackage.php | 4 +- application/hub/main/template/class_ | 2 +- .../hub/main/template/requests/.htaccess | 1 + ...class_XmlRequestNodeListTemplateEngine.php | 280 ++++++++++++++++++ .../hub/templates/xml/requests/.htaccess | 1 + .../xml/requests/node_request_node_list.xml | 26 ++ 17 files changed, 641 insertions(+), 160 deletions(-) create mode 100644 application/hub/main/handler/class_BaseDataHandler.php create mode 100644 application/hub/main/helper/hub/requests/.htaccess create mode 100644 application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php create mode 100644 application/hub/main/template/requests/.htaccess create mode 100644 application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php create mode 100644 application/hub/templates/xml/requests/.htaccess create mode 100644 application/hub/templates/xml/requests/node_request_node_list.xml diff --git a/.gitattributes b/.gitattributes index ad47d6d8d..fbcdc8f46 100644 --- a/.gitattributes +++ b/.gitattributes @@ -313,6 +313,7 @@ application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php svne application/hub/main/handler/chunks/.htaccess -text svneol=unset#text/plain application/hub/main/handler/chunks/class_ChunkHandler.php svneol=native#text/plain application/hub/main/handler/class_ svneol=native#text/plain +application/hub/main/handler/class_BaseDataHandler.php svneol=native#text/plain application/hub/main/handler/class_BaseHandler.php svneol=native#text/plain application/hub/main/handler/message-types/.htaccess -text svneol=unset#text/plain application/hub/main/handler/message-types/anouncement/.htaccess -text svneol=unset#text/plain @@ -353,6 +354,8 @@ application/hub/main/helper/hub/class_ svneol=native#text/plain application/hub/main/helper/hub/class_BaseHubHelper.php svneol=native#text/plain application/hub/main/helper/hub/connection/.htaccess -text svneol=unset#text/plain application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php svneol=native#text/plain +application/hub/main/helper/hub/requests/.htaccess -text svneol=unset#text/plain +application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php svneol=native#text/plain application/hub/main/helper/messages/.htaccess svneol=native#text/plain application/hub/main/helper/messages/class_BaseMessageHelper.php svneol=native#text/plain application/hub/main/helper/messages/crypto/.htaccess svneol=native#text/plain @@ -578,6 +581,7 @@ application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php application/hub/main/template/producer/.htaccess svneol=native#text/plain application/hub/main/template/producer/test_units/.htaccess svneol=native#text/plain application/hub/main/template/producer/test_units/class_XmlCruncherTestUnitTemplateEngine.php svneol=native#text/plain +application/hub/main/template/requests/.htaccess -text svneol=unset#text/plain application/hub/main/template/work_units/.htaccess svneol=native#text/plain application/hub/main/tools/.htaccess -text svneol=unset#text/plain application/hub/main/tools/class_HubTools.php svneol=native#text/plain @@ -613,6 +617,8 @@ application/hub/templates/xml/node/.htaccess -text svneol=unset#text/plain application/hub/templates/xml/node/node_status.xml svneol=native#text/plain application/hub/templates/xml/object_registry/.htaccess -text svneol=unset#text/plain application/hub/templates/xml/object_registry/object_registry.xml svneol=native#text/plain +application/hub/templates/xml/requests/.htaccess -text svneol=unset#text/plain +application/hub/templates/xml/requests/node_request_node_list.xml svneol=native#text/plain application/hub/templates/xml/self_connect/.htaccess -text svneol=unset#text/plain application/hub/templates/xml/self_connect/self_connect.xml svneol=native#text/plain db/.htaccess -text svneol=unset#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 35215b265..169e8ff82 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -222,6 +222,9 @@ $cfg->setConfigEntry('message_type_self_connect_handler_class', 'NodeMessageSelf // CFG: NODE-ANSWER-MESSAGE-ANNOUNCEMENT-HELPER-CLASS $cfg->setConfigEntry('node_answer_message_announcement_helper_class', 'NodeAnnouncementMessageAnswerHelper'); +// CFG: NODE-NEXT-ANNOUNCEMENT-ANSWER-OKAY-HELPER-CLASS +$cfg->setConfigEntry('node_next_announcement_answer_okay_helper_class', 'NodeRequestNodeListHelper'); + // CFG: NEWS-READER-CLASS $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader'); @@ -231,6 +234,9 @@ $cfg->setConfigEntry('node_announcement_template_class', 'XmlAnnouncementTemplat // CFG: NODE-ANNOUNCEMENT-ANSWER-TEMPLATE-CLASS $cfg->setConfigEntry('node_announcement_answer_template_class', 'XmlAnnouncementAnswerTemplateEngine'); +// CFG: NODE-REQUEST-NODE-LIST-TEMPLATE-CLASS +$cfg->setConfigEntry('node_request_node_list_template_class', 'XmlRequestNodeListTemplateEngine'); + // CFG: NODE-MESSAGE-TEMPLATE-EXTENSION $cfg->setConfigEntry('node_message_template_extension', '.xml'); @@ -255,9 +261,15 @@ $cfg->setConfigEntry('node_self_connect_template_class', 'XmlSelfConnectTemplate // CFG: NODE-SELF-CONNECT-TEMPLATE-TYPE $cfg->setConfigEntry('node_self_connect_template_type', 'xml/self_connect'); +// CFG: NODE-REQUEST-NODE-LIST-TEMPLATE-TYPE +$cfg->setConfigEntry('node_request_node_list_template_type', 'xml/requests'); + // CFG: NODE-SELF-CONNECT-STACKER-CLASS $cfg->setConfigEntry('node_self_connect_stacker_class', 'FiLoStacker'); +// CFG: NODE-REQUEST-NODE_LIST-STACKER-CLASS +$cfg->setConfigEntry('node_request_node_list_stacker_class', 'FiLoStacker'); + // CFG: NODE-OBJECT-REGISTRY-TEMPLATE-CLASS $cfg->setConfigEntry('node_object_registry_template_class', 'XmlObjectRegistryTemplateEngine'); @@ -300,6 +312,9 @@ $cfg->setConfigEntry('stacker_announcement_answer_max_size', 20); // CFG: STACKER-SELF-CONNECT-MAX-SIZE $cfg->setConfigEntry('stacker_self_connect_max_size', 10); +// CFG: STACKER-NODE-REQUEST-NODE-LIST-MAX_SIZE +$cfg->setConfigEntry('stacker_node_request_node_list_max_size', 10); + // CFG: STACKER-UNDECLARED-MAX-SIZE $cfg->setConfigEntry('stacker_package_undeclared_max_size', 10000); diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index 3ebcbe30f..4deb44a37 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -62,7 +62,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable // We do some rudimentary checks but this might be a bit ugly switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) { // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes - case NetworkPackage::NETWORK_TARGET_UPPER_HUBS: + case NetworkPackage::NETWORK_TARGET_UPPER_NODES: // Get all bootstrap nodes foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $node) { // Is maximum reached? diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index 461b61b33..c14b6c330 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -32,7 +32,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha parent::__construct(__CLASS__); // Set handler name - $this->setHandlerName('answer_okay'); + $this->setHandlerName('announcement_answer_okay'); } /** @@ -93,6 +93,27 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha // Prepare next message $this->prepareNextMessage($messageData, $packageInstance); } + + /** + * Initializes configuration data from given message data array + * + * @param $messageData An array with all message data + * @return void + */ + protected function initMessageConfigurationData (array $messageData) { + $this->partialStub('messageData=' . print_r($messageData, true)); + } + + /** + * Removes configuration data with given message data array from global + * configuration + * + * @param $messageData An array with all message data + * @return void + */ + protected function removeMessageConfigurationData (array $messageData) { + $this->partialStub('messageData=' . print_r($messageData, true)); + } } // [EOF] diff --git a/application/hub/main/handler/answer-status/class_ b/application/hub/main/handler/answer-status/class_ index 89f501dfb..af4f1d883 100644 --- a/application/hub/main/handler/answer-status/class_ +++ b/application/hub/main/handler/answer-status/class_ @@ -32,7 +32,7 @@ class ???Handler extends BaseAnserStatusHandler implements HandleableAnswerStatu parent::__construct(__CLASS__); // Set handler name - $this->setHandlerName('answer_==='); + $this->setHandlerName('|||_answer_==='); } /** diff --git a/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php b/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php index 4d5d12195..f5d6ff1ab 100644 --- a/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php +++ b/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php @@ -32,12 +32,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseAnserStatusHandler extends BaseHandler { - /** - * Last exception instance from database layer or NULL (default) - */ - private $lastException = NULL; - +abstract class BaseAnserStatusHandler extends BaseDataHandler { /** * Protected constructor * @@ -49,15 +44,6 @@ class BaseAnserStatusHandler extends BaseHandler { parent::__construct($className); } - /** - * Getter for last exception - * - * @return $lastException Last thrown exception - */ - protected final function getLastException () { - return $this->lastException; - } - /** * Adds all required elements from given array into data set instance * @@ -70,47 +56,6 @@ class BaseAnserStatusHandler extends BaseHandler { $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]); $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_MESSAGE_TYPE , $messageData[NetworkPackage::MESSAGE_ARRAY_TYPE]); } - - /** - * Prepares the next message - * - * @param $messageData An array with all message data - * @param $packageInstance An instance of a Deliverable instance - * @return void - */ - protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send next message ...'); - - // Get a helper instance based on this handler's name - $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData)); - - // Load descriptor XML - $helperInstance->loadDescriptorXml(); - - /* - * Set missing (temporary) configuration data, mostly it needs to be - * copied from message data array. - */ - $this->initMessageConfigurationData($messageData); - - // Compile any configuration variables - $helperInstance->getTemplateInstance()->compileConfigInVariables(); - - // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); - - // Deliver the package - $helperInstance->sendPackage($nodeInstance); - - /* - * Remove temporary configuration - */ - $this->removeMessageConfigurationData($messageData); - - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Next message has been prepared.'); - } } // [EOF] diff --git a/application/hub/main/handler/class_BaseDataHandler.php b/application/hub/main/handler/class_BaseDataHandler.php new file mode 100644 index 000000000..8fd0b4163 --- /dev/null +++ b/application/hub/main/handler/class_BaseDataHandler.php @@ -0,0 +1,182 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +abstract class BaseDataHandler extends BaseHandler { + /** + * Last exception instance from database layer or NULL (default) + */ + private $lastException = NULL; + + /** + * Array with search criteria elements + */ + protected $searchData = array(); + + /** + * Array with all data XML nodes (which hold the actual data) and their values + */ + protected $messageDataElements = array(); + + /** + * Array for translating message data elements (other node's data mostly) + * into configuration elements. + */ + protected $messageToConfig = array(); + + /** + * Array for copying configuration entries + */ + protected $configCopy = array(); + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Getter for last exception + * + * @return $lastException Last thrown exception + */ + protected final function getLastException () { + return $this->lastException; + } + + /** + * Setter for last exception + * + * @param $lastException Last thrown exception + * @return void + */ + protected final function setLastException (FrameworkException $exceptionInstance = NULL) { + $this->lastException = $exceptionInstance; + } + + /** + * Prepares a message as answer for given message data for delivery. + * + * @param $messageData An array with all message data + * @param $packageInstance An instance of a Deliverable instance + * @return void + */ + protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send an answer message ...'); + + // Get a helper instance based on this handler's name + $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData)); + + // Load descriptor XML + $helperInstance->loadDescriptorXml(); + + /* + * Set missing (temporary) configuration data, mostly it needs to be + * copied from message data array. + */ + $this->initMessageConfigurationData($messageData); + + // Compile any configuration variables + $helperInstance->getTemplateInstance()->compileConfigInVariables(); + + // Get node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Deliver the package + $helperInstance->sendPackage($nodeInstance); + + /* + * Remove temporary configuration + */ + $this->removeMessageConfigurationData($messageData); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Answer message has been prepared.'); + } + + /** + * Prepares the next message + * + * @param $messageData An array with all message data + * @param $packageInstance An instance of a Deliverable instance + * @return void + */ + protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send next message ...'); + + // Get a helper instance based on this handler's name + $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData)); + + // Load descriptor XML + $helperInstance->loadDescriptorXml(); + + /* + * Set missing (temporary) configuration data, mostly it needs to be + * copied from message data array. + */ + $this->initMessageConfigurationData($messageData); + + // Compile any configuration variables + $helperInstance->getTemplateInstance()->compileConfigInVariables(); + + // Get node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Deliver the package + $helperInstance->sendPackage($nodeInstance); + + /* + * Remove temporary configuration + */ + $this->removeMessageConfigurationData($messageData); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Next message has been prepared.'); + } + + /** + * Initializes configuration data from given message data array + * + * @param $messageData An array with all message data + * @return void + */ + abstract protected function initMessageConfigurationData (array $messageData); + + /** + * Removes configuration data with given message data array from global + * configuration + * + * @param $messageData An array with all message data + * @return void + */ + abstract protected function removeMessageConfigurationData (array $messageData); +} + +// [EOF] +?> diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index b20a8ab3b..adf444521 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -22,33 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -abstract class BaseMessageHandler extends BaseHandler { - /** - * Array with search criteria elements - */ - protected $searchData = array(); - - /** - * Array with all data XML nodes (which hold the actual data) and their values - */ - protected $messageDataElements = array(); - - /** - * Array for translating message data elements (other node's data mostly) - * into configuration elements. - */ - protected $messageToConfig = array(); - - /** - * Array for copying configuration entries - */ - protected $configCopy = array(); - - /** - * Last exception instance from database layer or NULL (default) - */ - private $lastException = NULL; - +abstract class BaseMessageHandler extends BaseDataHandler { /** * Protected constructor * @@ -60,15 +34,6 @@ abstract class BaseMessageHandler extends BaseHandler { parent::__construct($className); } - /** - * Getter for last exception - * - * @return $lastException Last thrown exception - */ - protected final function getLastException () { - return $this->lastException; - } - /** * "Getter" for a translated last exception as a status code * @@ -79,9 +44,9 @@ abstract class BaseMessageHandler extends BaseHandler { $statusCode = self::MESSAGE_STATUS_CODE_OKAY; // Is the last exception not NULL? - if ($this->lastException instanceof FrameworkException) { + if ($this->getLastException() instanceof FrameworkException) { // "Determine" the right status code (may differ from exception to exception) - $this->debugInstance('lastException=' . $this->lastException->__toString() . ',message=' . $this->lastException->getMessage() . ' is not finished!'); + $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!'); } // END - if // Return the status code @@ -132,66 +97,8 @@ abstract class BaseMessageHandler extends BaseHandler { } // Save last exception - $this->lastException = $wrapperInstance->getLastException(); - } - - /** - * Prepares a message as answer for given message data for delivery. - * - * @param $messageData An array with all message data - * @param $packageInstance An instance of a Deliverable instance - * @return void - */ - protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send an answer message ...'); - - // Get a helper instance based on this handler's name - $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData)); - - // Load descriptor XML - $helperInstance->loadDescriptorXml(); - - /* - * Set missing (temporary) configuration data, mostly it needs to be - * copied from message data array. - */ - $this->initMessageConfigurationData($messageData); - - // Compile any configuration variables - $helperInstance->getTemplateInstance()->compileConfigInVariables(); - - // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); - - // Deliver the package - $helperInstance->sendPackage($nodeInstance); - - /* - * Remove temporary configuration - */ - $this->removeMessageConfigurationData($messageData); - - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Answer message has been prepared.'); + $this->setLastException($wrapperInstance->getLastException()); } - - /** - * Initializes configuration data from given message data array - * - * @param $messageData An array with all message data - * @return void - */ - abstract protected function initMessageConfigurationData (array $messageData); - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageData An array with all message data - * @return void - */ - abstract protected function removeMessageConfigurationData (array $messageData); } // [EOF] diff --git a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php index 722a5f43e..a250ed0d0 100644 --- a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php @@ -38,7 +38,7 @@ class HubAnnouncementHelper extends BaseHubHelper implements HelpableHub { parent::__construct(__CLASS__); // Set recipient type - $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER_HUBS); + $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER_NODES); } /** diff --git a/application/hub/main/helper/hub/requests/.htaccess b/application/hub/main/helper/hub/requests/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/helper/hub/requests/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php b/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php new file mode 100644 index 000000000..900352bd3 --- /dev/null +++ b/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php @@ -0,0 +1,96 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * @todo Find an interface for hub helper + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class NodeRequestNodeListHelper extends BaseHubHelper implements HelpableHub { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set recipient type + $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER_NODES); + } + + /** + * Creates the helper class + * + * @return $helperInstance A prepared instance of this helper + */ + public final static function createNodeRequestNodeListHelper () { + // Get new instance + $helperInstance = new NodeRequestNodeListHelper(); + + // Return the prepared instance + return $helperInstance; + } + + /** + * Loads the descriptor XML file + * + * @return void + */ + public function loadDescriptorXml () { + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('HELPER: Attempting to request node list...'); + + // Get a XML template instance + $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_template_class'); + + // Set it for later use + $this->setTemplateInstance($templateInstance); + + // Read the XML descriptor + $this->getTemplateInstance()->loadRequestNodeListTemplate(); + + // Render the XML content + $this->getTemplateInstance()->renderXmlContent(); + } + + /** + * Do the helped attempt by delivering a package to ourselfs + * + * @param $nodeInstance An instance of a NodeHelper class + * @return void + */ + public function sendPackage (NodeHelper $nodeInstance) { + // Sanity check: Is the node in the approx. state? (active) + $nodeInstance->getStateInstance()->validateNodeStateIsActive(); + + // Compile the template, this inserts the loaded node data into the gaps. + $this->getTemplateInstance()->compileTemplate(); + + // Get a singleton network package instance + $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); + + // Next, feed the content in. The network package class is a pipe-through class. + $packageInstance->enqueueRawDataFromTemplate($this); + } +} + +// [EOF] +?> diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 5d4f11bd8..e060c32f9 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -132,9 +132,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R const PACKAGE_RECIPIENT_SEPARATOR = ':'; /** - * Network target (alias): 'upper hubs' + * Network target (alias): 'upper nodes' */ - const NETWORK_TARGET_UPPER_HUBS = 'upper'; + const NETWORK_TARGET_UPPER_NODES = 'upper'; /** * Network target (alias): 'self' diff --git a/application/hub/main/template/class_ b/application/hub/main/template/class_ index 218e240a1..8543d31e7 100644 --- a/application/hub/main/template/class_ +++ b/application/hub/main/template/class_ @@ -115,7 +115,7 @@ class Xml???TemplateEngine extends BaseTemplateEngine implements CompileableTemp * located in '!!!' by default * @return void */ - public function load???Template ($template) { + public function load???Template ($template = '!!!') { // Set template type $this->setTemplateType($this->getConfigInstance()->getConfigEntry('!!!_template_type')); diff --git a/application/hub/main/template/requests/.htaccess b/application/hub/main/template/requests/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/template/requests/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php b/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php new file mode 100644 index 000000000..968a5b928 --- /dev/null +++ b/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php @@ -0,0 +1,280 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * @todo This template engine does not make use of setTemplateType() + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class XmlRequestNodeListTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable { + /** + * Main nodes in the XML tree + */ + private $mainNodes = array( + 'node-request-node-list' + ); + + /** + * Sub nodes in the XML tree + */ + private $subNodes = array( + ); + + /** + * Current main node + */ + private $curr = array(); + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of the class TemplateEngine and prepares it for usage + * + * @return $templateInstance An instance of TemplateEngine + * @throws BasePathIsEmptyException If the provided $templateBasePath is empty + * @throws InvalidBasePathStringException If $templateBasePath is no string + * @throws BasePathIsNoDirectoryException If $templateBasePath is no + * directory or not found + * @throws BasePathReadProtectedException If $templateBasePath is + * read-protected + */ + public static final function createXmlRequestNodeListTemplateEngine () { + // Get a new instance + $templateInstance = new XmlRequestNodeListTemplateEngine(); + + // Get application instance from registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Determine base path + $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/'; + + // Is the base path valid? + if (empty($templateBasePath)) { + // Base path is empty + throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!is_string($templateBasePath)) { + // Is not a string + throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING); + } elseif (!is_dir($templateBasePath)) { + // Is not a path + throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); + } elseif (!is_readable($templateBasePath)) { + // Is not readable + throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH); + } + + // Set the base path + $templateInstance->setTemplateBasePath($templateBasePath); + + // Set template extensions + $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension')); + $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('node_message_template_extension')); + + // Absolute output path for compiled templates + $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')); + + // Init a variable stacker + $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_request_node_list_stacker_class'); + + // Set it + $templateInstance->setStackerInstance($stackerInstance); + + // Return the prepared instance + return $templateInstance; + } + + /** + * Load a specified request_node_list template into the engine + * + * @param $template The request_node_list template we shall load which is + * located in 'node_request_node_list' by default + * @return void + */ + public function loadRequestNodeListTemplate ($template = 'node_request_node_list') { + // Set template type + $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_request_node_list_template_type')); + + // Load the special template + $this->loadTemplate($template); + } + + /** + * Getter for current main node + * + * @return $currMainNode Current main node + */ + public final function getCurrMainNode () { + return $this->curr['main_node']; + } + + /** + * Setter for current main node + * + * @param $element Element name to set as current main node + * @return $currMainNode Current main node + */ + private final function setCurrMainNode ($element) { + $this->curr['main_node'] = (string) $element; + } + + /** + * Getter for main node array + * + * @return $mainNodes Array with valid main node names + */ + public final function getMainNodes () { + return $this->mainNodes; + } + + /** + * Getter for sub node array + * + * @return $subNodes Array with valid sub node names + */ + public final function getSubNodes () { + return $this->subNodes; + } + + /** + * Handles the start element of an XML resource + * + * @param $resource XML parser resource (currently ignored) + * @param $element The element we shall handle + * @param $attributes All attributes + * @return void + * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found + */ + public function startElement ($resource, $element, array $attributes) { + // Initial method name which will never be called... + $methodName = 'initNodeRequestNodeList'; + + // Make the element name lower-case + $element = strtolower($element); + + // Is the element a main node? + //* DEBUG: */ echo "START: >".$element."<
\n"; + if (in_array($element, $this->getMainNodes())) { + // Okay, main node found! + $methodName = 'start' . $this->convertToClassName($element); + + // Set it + $this->setCurrMainNode($element); + } elseif (in_array($element, $this->getSubNodes())) { + // Sub node found + $methodName = 'start' . $this->convertToClassName($element); + } else { + // Invalid node name found + throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN); + } + + // Call method + call_user_func_array(array($this, $methodName), $attributes); + } + + /** + * Ends the main or sub node by sending out the gathered data + * + * @param $resource An XML resource pointer (currently ignored) + * @param $nodeName Name of the node we want to finish + * @return void + * @throws XmlNodeMismatchException If current main node mismatches the closing one + */ + public function endElement ($resource, $nodeName) { + // Make all lower-case + $nodeName = strtolower($nodeName); + + // Does this match with current main node? + //* DEBUG: */ echo "END: >".$nodeName."<
\n"; + if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) { + // Did not match! + throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH); + } // END - if + + // Construct method name + $methodName = 'finish' . $this->convertToClassName($nodeName); + + // Call the corresponding method + //* DEBUG: */ echo "call: ".$methodName."
\n"; + call_user_func_array(array($this, $methodName), array()); + } + + /** + * Currently not used + * + * @param $resource XML parser resource (currently ignored) + * @param $characters Characters to handle + * @return void + * @todo Find something useful with this! + */ + public function characterHandler ($resource, $characters) { + // Trim all spaces away + $characters = trim($characters); + + // Is this string empty? + if (empty($characters)) { + // Then skip it silently + return false; + } // END - if + + // Get current XML node name as an array index + $nodeName = $this->getStackerInstance()->getNamed('node_request_node_list'); + + $this->partialStub('TODO: Do something with the gathered data.'); + } + + /** + * Getter for cache file (FQFN) + * + * @return $fqfn Full-qualified file name of the menu cache + */ + public function getNodeRequestNodeListCacheFqfn () { + $this->partialStub('Please implement this method.'); + } + + /** + * Starts the node-request-node-list + * + * @return void + */ + private function startNodeRequestNodeList () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('node_request_node_list', 'node-request-node-list'); + } + + /** + * Finishes the node-request-node-list + * + * @return void + */ + private function finishNodeRequestNodeList () { + // Pop the last entry + $this->getStackerInstance()->popNamed('node_request_node_list'); + } +} + +// [EOF] +?> diff --git a/application/hub/templates/xml/requests/.htaccess b/application/hub/templates/xml/requests/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/templates/xml/requests/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/templates/xml/requests/node_request_node_list.xml b/application/hub/templates/xml/requests/node_request_node_list.xml new file mode 100644 index 000000000..f219b4926 --- /dev/null +++ b/application/hub/templates/xml/requests/node_request_node_list.xml @@ -0,0 +1,26 @@ + + + + -- 2.39.5