/[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.22 - (show annotations)
Fri Jun 6 04:25:45 2003 UTC (21 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.21: +9 -2 lines
fix: query args get encapsulated once more

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

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