* Pre-fetches field default values from the given registry key instance into this class
*
* @param $registryKey Registry key which holds an object with values
+ * @param $extraKey Extra value instance key used if registryKey is null
* @return void
- * @throws NullPointerException If an instance from registry is null
+ * @throws NullPointerException If recovery of requested value instance failed
*/
- public function prefetchValueInstance ($registryKey) {
+ public function prefetchValueInstance ($registryKey, $extraKey = null) {
// Get the required instance
$this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
// Is the instance valid?
if (is_null($this->valueInstance)) {
- // Throw an exception
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ // Try to create it "from scratch", by first init extra instance
+ $extraInstance = null;
+
+ // Shall we get an extra instance?
+ if (!is_null($extraKey)) {
+ // Get the extra instance.
+ $extraInstance = Registry::getRegistry()->getInstance($extraKey);
+ } // END - if
+
+ // Get the requested instance
+ try {
+ $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($extraInstance));
+
+ } catch (FrameworkException $e) {
+ // Okay, nothing found so throw a null pointer exception here
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ }
} // END - if
}
// Return it
return $fieldValue;
}
+
+ /**
+ * Getter for value instance
+ *
+ * @return $valueInstance Instance of the class holding our values
+ */
+ public final function getValueInstance () {
+ return $this->valueInstance;
+ }
}
// [EOF]