X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fhandler%2Fmessage-types%2Fclass_BaseMessageHandler.php;h=4763b03cdf7e14f3a54df533047745cd62e0919e;hb=4c4dbb818c6da362302cd02a601cce0c78413bfb;hp=7b6763eeee2c9b9489855dce300385c0a1b30a60;hpb=ab826e7e2ef101ca11120b1d3869a51cfd1295e9;p=hub.git diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 7b6763eee..4763b03cd 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -1,6 +1,7 @@ * @version 0.0.0 @@ -21,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseMessageHandler extends BaseHandler { +abstract class BaseMessageHandler extends BaseHandler { /** * Array with search criteria elements */ @@ -32,6 +33,17 @@ class BaseMessageHandler extends BaseHandler { */ protected $messageDataElements = array(); + /** + * Array for translating message data elements (other node's data mostly) + * into configuration elements. + */ + protected $messageToConfig = array(); + + /** + * Last exception instance from database layer or NULL (default) + */ + private $lastException = NULL; + /** * Protected constructor * @@ -50,6 +62,34 @@ class BaseMessageHandler extends BaseHandler { ); } + /** + * 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 + * + * @return $statusCode Translated status code from last exception + */ + protected function getTranslatedStatusFromLastException () { + // Default is all fine + $statusCode = self::MESSAGE_STATUS_CODE_OKAY; + + // Is the last exception not NULL? + if ($this->lastException 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!'); + } // END - if + + // Return the status code + return $statusCode; + } + /** * Registers an other node with this node by given message data. The * following data must always be present: @@ -88,7 +128,62 @@ class BaseMessageHandler extends BaseHandler { // Nothing found, so register it $wrapperInstance->registerNodeByMessageData($messageData, $this); } + + // 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) { + // 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); + } + + /** + * 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]