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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Sat Mar 29 08:00:48 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.11: +12 -5 lines
modified ErrorBoxing

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

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