/[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.17 - (show annotations)
Wed Apr 9 02:07:33 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.16: +13 -8 lines
CHANGE: renamed key 'classname' through 'nodename'

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

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