/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Generic.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/DataSource/Generic.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations)
Fri Mar 28 06:45:26 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.10: +72 -10 lines
VERBOSE mode

1 joko 1.1 <?php
2     /**
3     * This file contains the GenericDataSource child class
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6 joko 1.2 * @package org.netfrag.glib
7     * @name DataSource::Generic
8 joko 1.1 *
9     */
10    
11     /**
12 joko 1.6 * <b>Cvs-Log:</b>
13     *
14     * <pre>
15 joko 1.11 * $Id: Generic.php,v 1.10 2003/03/28 03:01:02 joko Exp $
16 joko 1.2 *
17     * $Log: Generic.php,v $
18 joko 1.11 * Revision 1.10 2003/03/28 03:01:02 joko
19     * more fancy debugging-output
20     *
21 joko 1.10 * Revision 1.9 2003/03/27 16:24:26 jonen
22     * + mugled namespace
23     * + added enhanced 'queryData'
24     *
25 jonen 1.9 * Revision 1.8 2003/03/20 07:22:14 jonen
26     * + modified case 'object' to 'objects'
27     * (cause its loads all *objects* of a given classname)
28     *
29 jonen 1.8 * Revision 1.7 2003/03/11 01:43:00 joko
30     * + fixed metadata for phpDocumentor
31     *
32 joko 1.7 * Revision 1.6 2003/03/11 01:22:25 joko
33     * + fixed metadata for phpDocumentor
34     *
35 joko 1.6 * Revision 1.5 2003/03/11 00:12:49 joko
36     * + fixed metadata for phpDocumentor
37     *
38 joko 1.5 * Revision 1.4 2003/03/10 23:25:03 joko
39     * + fixed metadata for phpDocumentor
40     *
41 joko 1.4 * Revision 1.3 2003/03/09 15:50:36 joko
42     * + additional metadata for Autodia
43     *
44 joko 1.3 * Revision 1.2 2003/03/05 17:28:43 joko
45     * updated docu (phpDocumentor testing....)
46     *
47 joko 1.2 * Revision 1.1 2003/03/05 12:04:00 joko
48     * + initial commit, from GenericDataSource
49 joko 1.1 *
50     * Revision 1.3 2003/03/03 21:24:18 joko
51     * now based on DesignPattern::RemoteProxy
52     *
53     * Revision 1.2 2003/03/02 01:05:13 joko
54     * - purged old code
55     *
56     * Revision 1.1 2003/03/01 21:47:15 joko
57     * renamed from AbstractDataSource.inc
58     *
59     * Revision 1.1 2003/03/01 20:17:15 joko
60     * renamed from GenericDataSource.inc
61     * replaced '_proxy' through '_handler' to better associate the ability to act as a generic dispatcher handler
62     *
63     * Revision 1.3 2003/03/01 15:36:11 joko
64     * + debugging
65     * + renamed some methods regarding new proposal (build_handler_options, fetch_result, etc.)
66     *
67     * Revision 1.2 2003/03/01 04:50:27 joko
68     * encapsulated all output into tracing mode
69     * disabled tracing
70     *
71     * Revision 1.1 2003/03/01 03:10:40 joko
72     * + initial commit
73 joko 1.6 * </pre>
74 joko 1.1 *
75     */
76    
77     /**
78     * This requires the MemoryDataSource base class
79     *
80     */
81    
82     // V1: compile-time-include, stable since years ;-)
83     //include_once($phphtmllib."/widgets/data_source/MemoryDataSource.inc");
84    
85     // V2: runtime-load proposal, more flexible
86     // loadModule('MemoryDataSource', 'inc'); // doesn't work (would do if basepath of module is in libpath)
87     // loadModule($phphtmllib . '::widgets::data_source::MemoryDataSource', 'inc'); // works (by accident)
88     // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource", "inc"); // works (should be stable)
89     // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource.inc", null); // works (should be stable)
90    
91    
92    
93     /**
94     * Have to have PEAR and DB included
95     * the pear dir must be in the
96     * include path.
97     */
98     // require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC?
99     // require_once("DB.php");
100    
101 joko 1.2
102     loadModule('DesignPattern::Proxy');
103     loadModule('DesignPattern::TransparentProxy');
104     loadModule('DesignPattern::RemoteProxy');
105    
106     //class GenericDataSource extends MemoryDataSource {
107     //class GenericDataSource extends DesignPattern_Proxy {
108     //class GenericDataSource extends DesignPattern_RemoteProxy {
109     //class GenericDataSource extends DesignPattern_TransparentProxy {
110    
111     //class GenericDataSource extends MemoryDataSource {
112     //loadModule("DataSource::Proxy::Memory");
113     //class GenericDataSource extends DataSource_Proxy_Memory {
114     //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
115     //class DataSource_GenericDataSource extends DesignPattern_Proxy {
116     //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
117    
118     // now independent!!! new class-inheritance-tree possible now!
119     // solved by having an Adapter *and* a Proxy here!
120     //class GenericDataSource {
121    
122     loadModule('DesignPattern::AdapterProxy');
123    
124    
125    
126 joko 1.1 /**
127     * This GenericDataSource child class is *completely* independent
128     * of a specific storage implementation and intended to be a wrapper
129 joko 1.2 * class on the way from phpHtmlLib to Xyz. <br>
130 joko 1.1 * ("Yyz" gets represented by Data::Storage by now.....)
131     *
132     * GenericDataSource interacts with an intermediate "proxy" object
133 joko 1.2 * (e.g. Data::Driver::Proxy) when doing queries. <br>
134     * <pre>
135 joko 1.1 * Don't mix this up with a persistent database handle which gets
136     * reused each and every time for different queries.
137     * Here *is* a new instance of Data::Driver::Proxy for *each* query.
138 joko 1.2 * </pre>
139 joko 1.1 *
140     * But the point is: Caching! The actual *data* isn't read redundant!
141     *
142 joko 1.2 * <pre>
143     * --- snipped into here from above ---
144     * that may use arbitrary code modules as database handlers.
145     * It's aims are to get together:
146     * o phpHtmlLibs "source-handlers"
147     * o PEAR's database handlers
148     * o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)
149     * --- snipped into here from above ---
150     * </pre>
151     *
152 joko 1.7 * <p>
153 joko 1.1 * !!!!!! refactor this to Data::Driver::Proxy !!!!!! <-----------------
154     *
155     * Data::Driver::Proxy instantiates "handlers" below itself
156     * which act as encapsulated workers to actually do the stuff to do.
157     * It can cache data for "disconnected mode" using the
158     * php PEAR DB abstraction objects.
159     * One worker already implemented is Data::Driver::RPC::Remote, which
160     * talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC.
161     *
162 joko 1.2 * <pre>
163 joko 1.1 * --- refactored here, but: redundant somehow ---
164     * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
165     * talk HTTP and serialize data chunks to and from XML,
166     * but adds some caching to this "process of fetching data from a remote side".
167     * It "proxies" arbitrary data chunks a) inside a native php4 session,
168     * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.
169     * --- refactored here, but: redundant somehow ---
170 joko 1.2 * </pre>
171 joko 1.1 *
172     * !!!!!! refactor this to Data::Driver::Proxy !!!!!! <-----------------
173 joko 1.7 * </p>
174 joko 1.1 *
175     *
176 joko 1.7 * <p>
177 joko 1.2 * <b>How to use?</b>
178 joko 1.1 *
179     * Pass an array holding "locator metadata" to the constructor.
180     * GenericDataSource takes care of the rest.
181     *
182 joko 1.7 * <pre>
183 joko 1.1 * Pass an array to the constructor: (e.g.)
184     *
185     * 1. doing rpc-calls....
186 joko 1.2 * <code>
187 joko 1.1 * $locator = array(
188     * type => 'rpc',
189     * metadata => array( Host => 'localhost', Port => '8765' ),
190     * );
191 joko 1.3 * $source = ne w GenericDataSource($locator);
192 joko 1.1 * $this->set_data_source( &$source );
193 joko 1.2 * </code>
194 joko 1.1 *
195     * 2. [proposal] common datahandles....
196 joko 1.2 * <code>
197 joko 1.1 * $locator = array(
198     * type => 'mysql',
199     * dsn => 'known dsn markup',
200     * );
201 joko 1.3 * $source = ne w GenericDataSource($locator);
202 joko 1.1 * $this->set_data_source( &$source );
203 joko 1.2 * </code>
204 joko 1.7 * </pre>
205     * </p>
206     *
207 joko 1.1 *
208 joko 1.2 * @link http://www.netfrag.org/~joko/
209 joko 1.1 * @author Andreas Motl <andreas.motl@ilo.de>
210 joko 1.2 *
211     * @link http://www.netfrag.org/~jonen/
212 joko 1.1 * @author Sebastian Utz <seut@tunemedia.de>
213 joko 1.2 *
214 joko 1.1 * @copyright (c) 2003 - All Rights reserved.
215 joko 1.2 *
216     * @link http://www.gnu.org/licenses/lgpl.txt
217 joko 1.1 * @license GNU LGPL (GNU Lesser General Public License)
218     *
219     *
220 joko 1.2 * @package org.netfrag.glib
221     * @subpackage DataSource
222     * @name DataSource::Generic
223 joko 1.1 *
224 joko 1.4 * @todo this:
225 joko 1.5 * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
226     * o implement another Data::Driver::Proxy container
227 joko 1.1 *
228 joko 1.5 * <pre>
229 joko 1.4 * !!!!!!!! THIS IS THE PROBLEM !!!!!!!!
230     * !!!!!!!! here is it where we have to break inheritance again !!!!!!!!
231     *
232     * THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
233     * inheritance trees at the same time, which is *not* possible at
234     * declare-time. We *do* need some runtime-infrastructure to solve this!
235     *
236     * TODO: move build- and check-locator stuff from ObjectList to this place!!!
237     *
238     * ABOUT:
239     * 1. otherwhere: WebApp - scope:
240     * x handles page vs. block vs. widget; dispatches MVC-View
241     * 2. here: DataSource - scope:
242     * x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
243     * o clean implementation using a DesignPattern::AdapterProxy
244 joko 1.5 * </pre>
245 joko 1.4 *
246     *
247     */
248 joko 1.1 class DataSource_Generic extends DesignPattern_AdapterProxy {
249    
250     // !!!!!!!! here is it where we have to break inheritance again !!!!!!!!
251     // !!!!!!!! THIS IS THE PROBLEM !!!!!!!!
252    
253    
254    
255     /**
256     * This var holds the locator metadata hash
257     * that is used to feed metadata to a per-query-instance
258     * of an Adapter object.
259     *
260     */
261     //var $_locator = NULL;
262    
263     /**
264     * This var holds the locator metadata hash
265     * which is built from some predefined rules
266     * using metadata from $_options and some
267     * other presets.
268     *
269     * See '_buildLocator' which acts as a dispatcher
270     * depending on $_options[datasource].
271     * (main dispatching level)
272     *
273     * The structure of a full blown locator looks like this:
274     *
275     * $locator = array(
276     * type => '<your type specifying the datasource-type>',
277     * metadata => array(
278     * ... your arbitrary deep metadata structure ...
279     * ),
280     * [dsn => '<your dsn markup>'],
281     * );
282     *
283     * Example 1 - data is inside a rdbms, using a dsn to connect to it:
284     * $locator = array(
285     * type => 'sql',
286     * dsn => 'mysql://username:password@localhost/database',
287     * );
288     *
289     * Example 2 - data is inside an odbms, reachable by doing remote procedure calls (rpc):
290     * $locator = array(
291     * type => 'rpc',
292     * metadata => array(
293     * package => 'Data::Driver::Proxy',
294     * Host => 'localhost',
295     * Port => '8765',
296     * )
297     * );
298     *
299     */
300     var $_locator = NULL;
301    
302    
303     /**
304     * This var holds the module information required to
305     * create instances of a Proxy and an Adapter.
306     * Information might get extracted from a
307     * DataSource::Locator instance.
308     *
309     * --- A skeleton:
310     *
311     * $this->_modules = array(
312     * _proxy => array( _id => '', _module => '', _options = array(), _instance => &$obj),
313     * _adapter => array( _id => '', _module => '', _options = array(), _instance => &$obj),
314     * );
315     *
316     *
317     * --- An example:
318     *
319     * $this->_modules = array(
320     * _proxy => array( _id => 'rpc', _module => 'DesignPattern::RemoteProxy', _instance => &$obj),
321     * _adapter => array( _id => 'phpHtmlLib', _module => 'DataSource::Adapter::phpHtmlLib::DataListSource', _instance => &$obj),
322     * );
323     *
324     *
325     */
326     //var $_modules = NULL;
327    
328    
329     /**
330     * This var holds the query hash
331     * that is used to feed as query to a per-query-instance
332     * of a Data::Driver::Proxy object.
333     *
334     */
335     var $_query = NULL;
336    
337    
338     /**
339     * this holds the query result from the
340     * Data::Driver::Proxy->queryXyz() call
341     *
342     */
343     var $_result = NULL;
344    
345    
346    
347     /**
348     * The constructor is used to pass in the
349     * locator metadata hash.
350     *
351     * @param LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' )
352     * @param Query array - layout: array( type => '', metadata => '', dsn => '' )
353     */
354    
355    
356     function DataSource_Generic( &$locator, $query ) {
357    
358     // copy parameter from query to locator
359     //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');
360     //$this->_locator->_datasource_type = $query[datasource];
361     //$locator[_datasource_type] = $query[datasource];
362    
363 joko 1.3 /**
364     * <!-- Autodia -->
365     * can do: (this is metadata supplied for Autodia, don't delete!)
366     * $this->_locator = new DataSource_Locator()
367     *
368     */
369    
370 joko 1.1 // build master locator
371     $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );
372     //exit;
373     //$this->_locator = php::mkComponent('DataSource::Locator');
374    
375     $this->_locator->check();
376    
377     // trace
378     //print "locator-obj: " . Dumper($this->_locator);
379     //print "locator-data: " . Dumper($locator_data);
380     //exit;
381    
382    
383    
384     /*
385     $this->_modules = array(
386     _proxy => array( _id => $locator->_datasource_type ),
387     _adapter => array( _id => $locator->_adapter_type ),
388     );
389     */
390    
391     //$this->set_locator( $locator );
392     $this->set_query( $query );
393    
394    
395    
396     /*
397     // V1:
398     // pre-flight: establish and check locator metadata
399     $this->_buildLocator();
400     $this->_checkLocator();
401     */
402    
403    
404    
405     // pre-flight: check locator metadata
406     //$locator->build();
407     if (!$this->_locator->check()) {
408     user_error("locator-check failed.");
409     exit;
410     //return;
411     }
412    
413     //exit;
414    
415    
416 joko 1.3 /**
417     * <!-- Autodia -->
418     * can do: (this is metadata supplied for Autodia, don't delete!)
419     * $proxy = new DesignPattern_RemoteProxy()
420     *
421     */
422    
423    
424 joko 1.1 // --- Proxy selector/dispatcher ...
425    
426     switch ($this->_locator->_datasource_type) {
427     case 'rpc':
428     //$locator_data = $this->_locator->get_metadata();
429     //$this->_modules[_proxy][_options] = array( locator => $this->_locator, query => $query );
430     //$this->_modules[_proxy][_module] = 'DataSource::Proxy::XMLRPC';
431    
432     //$this->_modules[_proxy][_module] = 'DesignPattern::RemoteProxy';
433     //$this->_modules[_proxy][_options] = $locator_data;
434    
435     //$this->set_component_name('DesignPattern::RemoteProxy');
436     //$this->set_component_options($locator_data);
437    
438     $this->set_component_name('DesignPattern::RemoteProxy');
439    
440     break;
441     default:
442     user_error("Site::GenericPage: no Proxy could be selected!");
443     break;
444     }
445    
446    
447    
448     /*
449     // V1:
450     // make up dummy args by now
451     $args = array(
452     adapter => 'phpHtmlLib',
453     );
454     */
455    
456     // V2: now propagated from caller!
457    
458     //print Dumper(array( locator => $locator, query => $query ));
459     //exit;
460    
461     //$this->create_adapter($this->module, $this->function, $this->arguments);
462     //$this->set_handler( $this->get_adapter() );
463    
464    
465     // --- Adapter selector/dispatcher ...
466     // ... resolves this._modules.adapter._id to this._modules.adapter._module
467    
468     switch ($locator->_adapter_type) {
469     case 'phpHtmlLib':
470     //$adapter_arguments = $args[title];
471    
472 jonen 1.9 $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
473 joko 1.1
474     // in order to let the Adapter communicate with the Proxy,
475     // instantiate a wrapper method in a third namespace via
476     // Exporter::export_symbol(from, to)
477     $this->set_adapter_options($this);
478    
479    
480     break;
481     default:
482     user_error("DataSource::GenericDataSource: no Adapter could be selected!");
483     break;
484     }
485    
486    
487    
488     // --- module instantiation - Proxy and Adapter
489    
490     //user_error("handle proxy here!");
491     //$this->create_proxy();
492    
493     //print Dumper($this);
494    
495     //print "this: " . Dumper($this);
496    
497     // V1:
498     /*
499     $proxy = php::mkComponent($this->_modules[_proxy][_module], $this->_modules[_proxy][_options]);
500     print "proxy: " . Dumper($proxy);
501     //exit;
502     */
503    
504     // V2:
505     /*
506     $resultHandle = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
507     $result = $resultHandle->getAttributes();
508     return $result;
509     */
510    
511     // V3:
512     // $this->set_handler( $proxy );
513    
514     // V4: use _component_name & _component_options (proposal from GenericPage)
515     // $this->_component_name = ...
516     // $this->create_handler();
517    
518 joko 1.3
519     /**
520     * <!-- Autodia -->
521     * can do: (this is metadata supplied for Autodia, don't delete!)
522     * $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource()
523     *
524     */
525 joko 1.1
526     // V1:
527     //$this->create_adapter($adapter_module, $this->function, $this->arguments);
528    
529     // V2: FIXME - better use V1?
530     $adapter = php::mkComponent($this->get_adapter_module(), $this->get_adapter_options());
531     $this->set_adapter($adapter);
532    
533    
534    
535    
536     }
537    
538     function make_adapter_transparent() {
539    
540     // ... known from Site::Adapter::php::Class:
541    
542     // At this place the Adapter becomes a Proxy.
543     // This functionality currently correlates to the
544     // name of our ancestor, DesignPattern::AdapterProxy.
545     // FIXME: move this code to its namespace!!!
546     // FIXME: rename to set_proxy...
547    
548     // The reason this has to occour here is required
549     // by the TransparentProxy to actually make the
550     // _handler (_proxy) transparent later....
551     //$this->set_proxy( $this->get_adapter() );
552     }
553    
554     /**
555     * Set the metadata information
556     * (a DataSource::Locator) we will use
557     * to build encapsulated instances
558     * of both a Proxy and an Adapter.
559     *
560     * @param LocatorMetadataHash array -
561     *
562     */
563     function set_metadata( &$locator ) {
564     $this->_locator = &$locator;
565     }
566    
567     function &get_metadata() {
568     return $this->_locator;
569     }
570    
571    
572     /**
573     * Set the query metadata hash we will feed *completely*
574     * to an encapsulated Proxy instance.
575     *
576     * @param QueryDeclaration array -
577     *
578     */
579     function set_query( $query ) {
580     $this->_query = $query;
581     }
582    
583     /**
584     * Issue remote/proxy call
585     * Stolen from Application_AbstractBackend::_remote_method (RefactoringProposal?)
586     * Tweaked a bit: proxy package now taken from $this->_handler_name
587     *
588     * Create a new instance of a proxy and store it for later reuse.
589     * Read the locator metadata hash and create
590     * the proxy handler instance using passed-in name.
591     *
592     * @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy)
593     *
594     */
595     function datasource_handler_call() {
596    
597    
598     // 1. read args and build cache key
599    
600     $arg_list = func_get_args();
601     $command = array_shift($arg_list);
602     $cache_key = join("-", array(session_id(), $command, join('_', $arg_list) ));
603     //print "cache_key: $cache_key<br>";
604    
605     // FIXME: what if arg_list still contains more elements after doing this?
606     $query = array_shift($arg_list);
607    
608     // 2. prepare proxy-options (read from locator)
609    
610     //print "this: " . Dumper($this);
611     //exit;
612    
613     // read from locator metadata
614     //$proxy_name = $this->_locator[metadata][package];
615    
616     // V1:
617     //$rpcinfo = array( Host => $this->_locator[metadata][Host], Port => $this->_locator[metadata][Port] );
618    
619     // V2:
620     $rpcinfo = $this->_locator->get_metadata();
621    
622     // FIXME! implement this into Data::Driver::RPC::Remote!
623     //$rpcinfo[to_latin] = 1;
624    
625     // FIXME! patch query
626     if (sizeof($query) == 1) {
627     $query = $query[0];
628     }
629    
630     //print "query: " . Dumper($query);
631    
632     // !!! use DesignPattern::Proxy here !!!
633     // $proxy = new DesignPattern_Proxy($proxy_name, ...)
634     // or:
635     // $proxy = mkObject('DesignPattern::Proxy');
636     // $this->set_handler( $proxy );
637     // or:
638     // $proxy = mkObject('DesignPattern::Proxy');
639     // $proxy->
640     // $this->set_handler( $proxy );
641    
642    
643    
644     //$this->set_component_name( $proxy_name );
645     $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
646     //print Dumper($this);
647     //exit;
648    
649     $this->create_proxy();
650    
651     //print Dumper($this);
652     //exit;
653    
654     /*
655     // -------------------- clone this & modify ----------
656     $proxy = mkObject($proxy_name, $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
657     $this->set_handler( $proxy );
658     //$result = $resultHandle->getAttributes();
659     //return $result;
660     //$this->_result = $resultHandle->getAttributes();
661     //$this->_result = $this->_handler->getAttributes();
662     // -------------------- clone this & modify ----------
663     */
664    
665     }
666    
667    
668     function datasource_handler_buildoptions() {
669    
670     //print Dumper($this->_query);
671     //exit;
672    
673     // make up a command from metadata
674     // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
675     switch ($this->_query[metatype]) {
676     case 'data':
677 jonen 1.9 $command = 'queryData';
678     //$command = 'getObjects'; // FIXME!!!
679 joko 1.1 //$this->_locator->set_option('metadata.command', $command);
680 jonen 1.9 /*
681 joko 1.1 $args = array();
682     switch ($this->_query[vartype]) {
683 jonen 1.8 case 'objects':
684 joko 1.1 if (!$this->_query[classname]) {
685 jonen 1.8 $msg = "_query[vartype] == 'objects' requires _query[classname]";
686 joko 1.1 user_error("GenericDataSource::query_data() - failed: " . $msg);
687     }
688     array_push($args, $this->_query[classname]);
689     break;
690     }
691 jonen 1.9 */
692     $query_args = array();
693     switch ($this->_query[abstract_type]) {
694     case 'list':
695     if (!$this->_query[classname]) {
696     $msg = "_query[vartype] == 'objects' requires _query[classname]";
697     user_error("GenericDataSource::query_data() - failed: " . $msg);
698     }
699     //array_push($query_args, $this->_query[classname]);
700     $query_args[classname] = $this->_query[classname];
701     break;
702     case 'item':
703     if (!$this->_query[classname]) {
704     $msg = "_query[vartype] == 'objects' requires _query[classname]";
705     user_error("GenericDataSource::query_data() - failed: " . $msg);
706     }
707     $query_args[guid] = $this->_query[ident];
708     $query_args[classname] = $this->_query[classname];
709     break;
710     }
711     $args = array(
712     'data_type' => $this->_query[abstract_type],
713     'query_args' => $query_args
714     );
715     break;
716    
717     // querySchema
718 joko 1.1 case 'schema':
719 jonen 1.9 //print "Testing schema:" . "<br>";
720 joko 1.1 $command = 'querySchema';
721     break;
722     }
723    
724    
725     /*
726     $this->_query[rpc_command] = $command;
727     $this->_query[rpc_args] = $command;
728     */
729    
730     // methods!!!
731     $this->_locator->_call[_method] = $command;
732     $this->_locator->_call[_arguments] = $args;
733    
734     //$adapter = $this->get_adapter();
735    
736     // trace
737     /*
738     print Dumper(null, '<b>= = = = = = = = = = = = = = = = = = = = = =</b>');
739     print Dumper('datasource_handler_buildoptions', array(
740     "_locator" => $this->_locator,
741     "_query" => $this->_query,
742     "command" => '<b>' . $command . "</b>",
743     "args" => $args
744     ));
745     */
746    
747     /*
748     $this->_handler_options = array(
749     method => $command,
750     args => $args,
751     );
752     */
753    
754     }
755    
756 joko 1.11
757    
758 joko 1.1 function &fetch_result() {
759    
760     $this->datasource_handler_buildoptions();
761    
762 joko 1.11 $call = $this->_locator->get_call();
763     //print Dumper($call);
764    
765 joko 1.1 // pre-flight checks
766 joko 1.11 if (!$call[method]) {
767     $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
768 joko 1.1 user_error("GenericDataSource::query_data() - failed: " . $msg);
769     return;
770     }
771    
772     //print "fetch_result: this->_handler=" . Dumper($this->_handler);
773    
774     // do remote call here and get result
775     // FIXME: handle synchronous/asynchronous mode here!!!
776 joko 1.11 $this->datasource_handler_call($call[method], $call[args]);
777 joko 1.1
778    
779     // TODO: ... = $this->poll_handler_result and $this->get_handler_result
780     $proxy = $this->get_proxy();
781     $this->_result = $proxy->getResult();
782     //print "result: " . Dumper($this->_result); exit;
783    
784     $this->_result_count = sizeof($this->_result);
785    
786     // trace
787 joko 1.11 //if (constants::get('VERBOSE') && $this->_debug[notice]) {
788     if (constants::get('VERBOSE')) {
789 joko 1.1 //print "_result = " . Dumper($this->_result);
790 joko 1.11 //print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>";
791     $this->draw_status_box();
792 joko 1.1 }
793 joko 1.11
794 joko 1.1 return $this->_result;
795    
796     }
797    
798 joko 1.11 function draw_status_box() {
799    
800     static $boxcount;
801    
802     $boxcount++;
803    
804     // box client code (javascript)
805     $code_js = "
806     <script language=\"javascript\">
807     function toggle_vis(id) {
808     elem = eval('document.all.' + id);
809     status = elem.style.getAttribute('display');
810     if (status == 'none') {
811     elem.style.setAttribute('display', 'block');
812     } else {
813     elem.style.setAttribute('display', 'none');
814     }
815     }
816     </script>
817     ";
818     //$script = html_script($code_js);
819     //print $script->render();
820     print $code_js;
821    
822     // box style
823     $style = container(
824     html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
825     html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
826     );
827     print $style->render();
828    
829     // box content
830     $statusbox = html_div('box_dsg');
831     $statusbox->add( html_b("DataSource::Generic"), html_br() );
832     $locatorbox = html_div('box_dsg');
833     $locatorbox->set_id("locatorbox_$boxcount");
834     $locatorbox->add( Dumper($this->_locator) );
835     //$locatorbox->set_style('visibility:false;');
836     $locatorbox->set_style('display:none;');
837    
838     $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() );
839     $call = $this->_locator->get_call();
840     $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
841     if (sizeof($call[args])) {
842     $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
843     }
844     $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
845     print $statusbox->render();
846    
847     }
848    
849 joko 1.1
850     function &query_data() {
851     //print "query!<br/>";
852     return $this->fetch_result();
853     //$this->handle_result();
854     }
855    
856     function query_schema() {
857     user_error("FIXME: query_schema");
858     // $this->datasource_handler_call( ... );
859     }
860    
861     function &get_result() {
862     return $this->_result;
863 joko 1.11 }
864    
865     function get_result_count() {
866     return $this->_result_count;
867 joko 1.1 }
868    
869     }
870    
871     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed