3 * A local query connector class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
10 * @todo Find an interface for: handleAllQueries()
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class LocalQueryConnector extends BaseQueryConnector implements Connectable, Visitable {
27 * The query class instance
29 private $queryInstance = null;
32 * Protected constructor
36 protected function __construct () {
37 // Call parent constructor
38 parent::__construct(__CLASS__);
40 // Init query instance
41 $this->queryInstance = ObjectFactory::createObjectByConfiguredName('local_query_class');
45 * Creates an instance of this query connector class
47 * @param $nodeInstance An instance of a node
48 * @return $connectorInstance An instance of this query connector class
50 public static final function createLocalQueryConnector (NodeHelper $nodeInstance) {
51 // Create the instance
52 $connectorInstance = new LocalQueryConnector();
54 // Set the node instance
55 $connectorInstance->setNodeInstance($nodeInstance);
57 // Get a list instance
58 $listInstance = ObjectFactory::createObjectByConfiguredName('local_query_list_class');
60 // Set it in the connector
61 $connectorInstance->setListInstance($listInstance);
63 // Prepare iterator instance
64 $iteratorInstance = ObjectFactory::createObjectByConfiguredName('query_iterator_class', array($listInstance));
67 $connectorInstance->setIteratorInstance($iteratorInstance);
69 // Finally return the connector
70 return $connectorInstance;
74 * Handles the in the list avaiable query (current) and hands it over to the
75 * query processor instance
78 * @TODO 0% done: Unfinished work here
80 private function handleCurrentQuery () {
81 // Is there a query available?
82 if (!$this->getIteratorInstance()->valid()) {
87 // Get the current query
88 $currentQuery = $this->getIteratorInstance()->current();
90 // Only while construction, else it would output to much!
91 /* DEBUG: */ $this->debugOutput('CONNECTOR: Handling query ' . $currentQuery);
95 * Accepts the visitor to process the visit "request"
97 * @param $visitorInstance An instance of a Visitor class
100 public function accept (Visitor $visitorInstance) {
101 // Visit the query connector
102 $visitorInstance->visitQueryConnector($this);
104 // Visit the query as well
105 $this->queryInstance->accept($visitorInstance);
109 * Handles all pending queries. This method should be called by the
110 * ActiveTaskVisitor class and should use an iterator on all pending
115 public function handlePanding () {
117 if (!$this->getIteratorInstance()->valid()) {
118 // Rewind to the beginning for next loop
119 $this->getIteratorInstance()->rewind();
122 // Try to execute the task
123 $this->handleCurrentQuery();
126 $this->getIteratorInstance()->next();