/[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.15 - (hide annotations)
Sun Apr 6 04:46:33 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.14: +9 -4 lines
renamed linking function
mozilla fixes

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

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