*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* 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 BasePool extends BaseHubSystem {
+class BasePool extends BaseHubSystem implements Visitable {
/**
- * A list of instances for this pool
+ * A list of pool entries
*/
- private $instancePool = array();
+ private $poolEntriesInstance = null;
/**
* Protected constructor
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
+
+ // Init the pool entries
+ $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
+ }
+
+ /**
+ * Getter for pool entries instance
+ *
+ * @return $poolEntriesInstance An instance for pool entries (list)
+ */
+ public final function getPoolEntriesInstance () {
+ return $this->poolEntriesInstance;
}
/**
* Adds an instance to a pool segment
*
+ * @param $group Name of the pool group
* @param $poolSegment Name of the pool segment
* @param $instance An instance of a class we should add to the pool
* @return void
*/
- protected final function addInstance($poolName, FrameworkInterface $instance) {
- $this->instancePool[$poolName][] = $instance;
+ protected final function addInstance ($group, $poolName, Visitable $instance) {
+ // Is the pool group there?
+ if (!$this->getPoolEntriesInstance()->isGroupSet($group)) {
+ // Create the missing pool group
+ $this->getPoolEntriesInstance()->addGroup($group);
+ } // END - if
+
+ // Add it to given pool group
+ $this->getPoolEntriesInstance()->addInstance($group, $poolName, $instance);
+ }
+
+ /**
+ * Adds an entry to the pool
+ *
+ * @param $poolEntry The new pool entry we should add
+ * @return void
+ */
+ protected final function addPoolEntry ($poolEntry) {
+ $this->getPoolEntriesInstance()->addEntry('generic', $poolEntry);
+ }
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START');
+
+ // Visit this pool
+ $visitorInstance->visitPool($this);
+
+ // Get a new iterator instance
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
+
+ // Reset the counter
+ $iteratorInstance->rewind();
+
+ // Visit all registered entries
+ while ($iteratorInstance->valid()) {
+ // Get current entry
+ $poolEntry = $iteratorInstance->current();
+
+ // Is this entry visitable?
+ if ($poolEntry instanceof Visitable) {
+ // Visit this entry as well
+ $poolEntry->accept($visitorInstance);
+ } else {
+ // Cannot visit this entry
+ $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.');
+ }
+
+ // Advance to next entry
+ $iteratorInstance->next();
+ } // END - while
+
+ // Debug message
+ //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+ }
+
+ /**
+ * Gets the array from specified list
+ *
+ * @param $list The list identifier we should return
+ * @return $array The requested array
+ */
+ protected final function getArrayFromList ($list) {
+ // Get the array
+ $array = $this->getPoolEntriesInstance()->getArrayFromList($list);
+
+ // Return it
+ return $array;
}
}