<?php
/**
- * A general message handler
+ * A general message handler, this class must be abstract to make the template
+ * method pattern working.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseMessageHandler extends BaseHandler {
+abstract class BaseMessageHandler extends BaseHandler {
/**
* Array with search criteria elements
*/
*/
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
*
);
}
+ /**
+ * 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:
// Nothing found, so register it
$wrapperInstance->registerNodeByMessageData($messageData, $this);
}
+
+ // Save last exception
+ $this->lastException = $wrapperInstance->getLastException();
}
/**
// 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();
// 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]