]> git.mxchange.org Git - hub.git/blob - application/hub/main/connectors/query/local/class_LocalQueryConnector.php
Hub project continued:
[hub.git] / application / hub / main / connectors / query / local / class_LocalQueryConnector.php
1 <?php
2 /**
3  * A local query connector class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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()
11  *
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.
16  *
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.
21  *
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/>.
24  */
25 class LocalQueryConnector extends BaseQueryConnector implements Connectable, Visitable {
26         /**
27          * The query class instance
28          */
29         private $queryInstance = NULL;
30
31         /**
32          * Protected constructor
33          *
34          * @return      void
35          */
36         protected function __construct () {
37                 // Call parent constructor
38                 parent::__construct(__CLASS__);
39
40                 // Init query instance
41                 $this->queryInstance = ObjectFactory::createObjectByConfiguredName('local_query_class');
42         }
43
44         /**
45          * Creates an instance of this query connector class
46          *
47          * @param       $nodeInstance           An instance of a node
48          * @return      $connectorInstance      An instance of this query connector class
49          */
50         public static final function createLocalQueryConnector (NodeHelper $nodeInstance) {
51                 // Create the instance
52                 $connectorInstance = new LocalQueryConnector();
53
54                 // Set the node instance
55                 $connectorInstance->setNodeInstance($nodeInstance);
56
57                 // Get a list instance
58                 $listInstance = ObjectFactory::createObjectByConfiguredName('local_query_list_class');
59
60                 // Set it in the connector
61                 $connectorInstance->setListInstance($listInstance);
62
63                 // Prepare iterator instance
64                 $iteratorInstance = $listInstance->getListIterator();
65
66                 // Set it, too
67                 $connectorInstance->setIteratorInstance($iteratorInstance);
68
69                 // Finally return the connector
70                 return $connectorInstance;
71         }
72
73         /**
74          * Handles the in the list avaiable query (current) and hands it over to the
75          * query processor instance
76          *
77          * @return      void
78          * @TODO        0% done: Unfinished work here
79          */
80         private function handleCurrentQuery () {
81                 // Is there a query available?
82                 if (!$this->getIteratorInstance()->valid()) {
83                         // Simply abort here
84                         return;
85                 } // END - if
86
87                 // Get the current query
88                 $currentQuery = $this->getIteratorInstance()->current();
89
90                 // Only while construction, else it would output to much!
91                 /* DEBUG: */ $this->debugOutput('CONNECTOR: Handling query ' . $currentQuery);
92         }
93
94         /**
95          * Accepts the visitor to process the visit "request"
96          *
97          * @param       $visitorInstance        An instance of a Visitor class
98          * @return      void
99          */
100         public function accept (Visitor $visitorInstance) {
101                 // Visit the query connector
102                 $visitorInstance->visitQueryConnector($this);
103
104                 // Visit the query as well
105                 $this->queryInstance->accept($visitorInstance);
106         }
107
108         /**
109          * Handles all pending queries. This method should be called by the
110          * ActiveTaskVisitor class and should use an iterator on all pending
111          * queries.
112          *
113          * @return      void
114          */
115         public function handlePending () {
116                 // Should we rewind?
117                 if (!$this->getIteratorInstance()->valid()) {
118                         // Rewind to the beginning for next loop
119                         $this->getIteratorInstance()->rewind();
120
121                         // Still not valid?
122                         if ($this->getIteratorInstance()->valid()) {
123                                 /*
124                                  * Then silently abort here because the queue is empty and to
125                                  * save some calls.
126                                  */
127                                 return;
128                         } // END - if
129                 } // END - if
130
131                 // Try to execute the task
132                 $this->handleCurrentQuery();
133
134                 // Go to next entry
135                 $this->getIteratorInstance()->next();
136         }
137 }
138
139 // [EOF]
140 ?>