/[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.21 - (show annotations)
Sat May 10 18:14:50 2003 UTC (21 years, 3 months ago) by jonen
Branch: MAIN
Changes since 1.20: +19 -4 lines
+ implements 'create' of item (query mapping part)

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

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