9 |
*/ |
*/ |
10 |
|
|
11 |
/** |
/** |
12 |
|
* Cvs-Log: |
13 |
|
* |
14 |
* $Id$ |
* $Id$ |
15 |
* |
* |
16 |
* $Log$ |
* $Log$ |
17 |
|
* Revision 1.25 2003/11/17 18:01:03 jonen |
18 |
|
* bugfix: php cannot use perl-syntax!! ;-) |
19 |
|
* |
20 |
|
* Revision 1.23 2003/07/14 10:02:32 jonen |
21 |
|
* removed debug dumper |
22 |
|
* |
23 |
|
* Revision 1.22 2003/06/06 04:25:45 joko |
24 |
|
* fix: query args get encapsulated once more |
25 |
|
* |
26 |
|
* Revision 1.21 2003/05/10 18:14:50 jonen |
27 |
|
* + implements 'create' of item (query mapping part) |
28 |
|
* |
29 |
|
* Revision 1.20 2003/04/19 16:07:15 jonen |
30 |
|
* + added '_query[list_meta]' at 'queryData' needed for meta query args |
31 |
|
* (e.g. at UserManagment) |
32 |
|
* |
33 |
|
* Revision 1.19 2003/04/18 15:40:51 joko |
34 |
|
* NEW: tree data handling |
35 |
|
* introduced new adapter: DataSource::Adapter::Free |
36 |
|
* enhanced datasource_handler_buildoptions: now handles a) case 'tree' b) _query[filter] |
37 |
|
* |
38 |
|
* Revision 1.18 2003/04/11 00:55:49 joko |
39 |
|
* updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete' |
40 |
|
* |
41 |
|
* Revision 1.17 2003/04/09 02:07:33 joko |
42 |
|
* CHANGE: renamed key 'classname' through 'nodename' |
43 |
|
* |
44 |
|
* Revision 1.16 2003/04/08 17:55:20 joko |
45 |
|
* CHANGE: renamed property 'datasource' to 'transport' |
46 |
|
* NEW: new case 'method' in 'function datasource_handler_buildoptions' |
47 |
|
* minor fixes: updated logging/debugging messages |
48 |
|
* |
49 |
|
* Revision 1.15 2003/04/06 04:46:33 joko |
50 |
|
* renamed linking function |
51 |
|
* mozilla fixes |
52 |
|
* |
53 |
|
* Revision 1.14 2003/04/04 21:19:21 joko |
54 |
|
* modified exception handling (enhanced, purged redundant code) |
55 |
|
* |
56 |
|
* Revision 1.13 2003/04/04 02:37:14 jonen |
57 |
|
* _query[action] == write |
58 |
|
* |
59 |
|
* Revision 1.12 2003/03/29 08:00:48 joko |
60 |
|
* modified ErrorBoxing |
61 |
|
* |
62 |
|
* Revision 1.11 2003/03/28 06:45:26 joko |
63 |
|
* VERBOSE mode |
64 |
|
* |
65 |
|
* Revision 1.10 2003/03/28 03:01:02 joko |
66 |
|
* more fancy debugging-output |
67 |
|
* |
68 |
|
* Revision 1.9 2003/03/27 16:24:26 jonen |
69 |
|
* + mugled namespace |
70 |
|
* + added enhanced 'queryData' |
71 |
|
* |
72 |
|
* Revision 1.8 2003/03/20 07:22:14 jonen |
73 |
|
* + modified case 'object' to 'objects' |
74 |
|
* (cause its loads all *objects* of a given classname) |
75 |
|
* |
76 |
|
* Revision 1.7 2003/03/11 01:43:00 joko |
77 |
|
* + fixed metadata for phpDocumentor |
78 |
|
* |
79 |
|
* Revision 1.6 2003/03/11 01:22:25 joko |
80 |
|
* + fixed metadata for phpDocumentor |
81 |
|
* |
82 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
83 |
|
* + fixed metadata for phpDocumentor |
84 |
|
* |
85 |
* Revision 1.4 2003/03/10 23:25:03 joko |
* Revision 1.4 2003/03/10 23:25:03 joko |
86 |
* + fixed metadata for phpDocumentor |
* + fixed metadata for phpDocumentor |
87 |
* |
* |
118 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
119 |
* + initial commit |
* + initial commit |
120 |
* |
* |
|
* |
|
121 |
*/ |
*/ |
122 |
|
|
123 |
/** |
/** |
195 |
* --- snipped into here from above --- |
* --- snipped into here from above --- |
196 |
* </pre> |
* </pre> |
197 |
* |
* |
198 |
* |
* <p> |
199 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
200 |
* |
* |
201 |
* Data::Driver::Proxy instantiates "handlers" below itself |
* Data::Driver::Proxy instantiates "handlers" below itself |
216 |
* </pre> |
* </pre> |
217 |
* |
* |
218 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
219 |
|
* </p> |
220 |
* |
* |
221 |
* |
* |
222 |
|
* <p> |
223 |
* <b>How to use?</b> |
* <b>How to use?</b> |
224 |
* |
* |
225 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
226 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
227 |
* |
* |
228 |
|
* <pre> |
229 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
230 |
* |
* |
231 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
247 |
* $source = ne w GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
248 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
249 |
* </code> |
* </code> |
250 |
|
* </pre> |
251 |
|
* </p> |
252 |
|
* |
253 |
* |
* |
254 |
* @link http://www.netfrag.org/~joko/ |
* @link http://www.netfrag.org/~joko/ |
255 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
268 |
* @name DataSource::Generic |
* @name DataSource::Generic |
269 |
* |
* |
270 |
* @todo this: |
* @todo this: |
271 |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
272 |
|
* o implement another Data::Driver::Proxy container |
273 |
* |
* |
274 |
* <ul> |
* <pre> |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
|
|
* o implement another Data::Driver::Proxy container |
|
|
* </ul> |
|
|
* |
|
275 |
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
276 |
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
277 |
* |
* |
287 |
* 2. here: DataSource - scope: |
* 2. here: DataSource - scope: |
288 |
* x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
* x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
289 |
* o clean implementation using a DesignPattern::AdapterProxy |
* o clean implementation using a DesignPattern::AdapterProxy |
290 |
|
* </pre> |
291 |
* |
* |
292 |
* |
* |
293 |
*/ |
*/ |
313 |
* other presets. |
* other presets. |
314 |
* |
* |
315 |
* See '_buildLocator' which acts as a dispatcher |
* See '_buildLocator' which acts as a dispatcher |
316 |
* depending on $_options[datasource]. |
* depending on $_options[transport]. |
317 |
* (main dispatching level) |
* (main dispatching level) |
318 |
* |
* |
319 |
* The structure of a full blown locator looks like this: |
* The structure of a full blown locator looks like this: |
402 |
function DataSource_Generic( &$locator, $query ) { |
function DataSource_Generic( &$locator, $query ) { |
403 |
|
|
404 |
// copy parameter from query to locator |
// copy parameter from query to locator |
405 |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_'); |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_'); |
406 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[transport]; |
407 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[transport]; |
408 |
|
|
409 |
/** |
/** |
410 |
* <!-- Autodia --> |
* <!-- Autodia --> |
414 |
*/ |
*/ |
415 |
|
|
416 |
// build master locator |
// build master locator |
417 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) ); |
418 |
//exit; |
//exit; |
419 |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
420 |
|
|
451 |
// pre-flight: check locator metadata |
// pre-flight: check locator metadata |
452 |
//$locator->build(); |
//$locator->build(); |
453 |
if (!$this->_locator->check()) { |
if (!$this->_locator->check()) { |
454 |
user_error("locator-check failed."); |
user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) ); |
455 |
exit; |
//exit; |
456 |
//return; |
return; |
457 |
} |
} |
458 |
|
|
459 |
//exit; |
//exit; |
512 |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
513 |
|
|
514 |
switch ($locator->_adapter_type) { |
switch ($locator->_adapter_type) { |
515 |
|
|
516 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
517 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
518 |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource'); |
|
519 |
|
|
520 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
521 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
522 |
// Exporter::export_symbol(from, to) |
// Exporter::export_symbol(from, to) |
523 |
$this->set_adapter_options($this); |
$this->set_adapter_options($this); |
524 |
|
break; |
525 |
|
|
526 |
|
// NEW [2003-04-17]: Freedom for the adapter! |
527 |
|
// phpHtmlLib didn't have a tree widget, but PEAR does. |
528 |
|
// So: Free us from the phpHtmlLib-adapter in this case. |
529 |
|
case 'free': |
530 |
|
$this->set_adapter_module('DataSource::Adapter::Free'); |
531 |
|
$this->set_adapter_options($this); |
532 |
break; |
break; |
533 |
|
|
534 |
default: |
default: |
535 |
user_error("DataSource::GenericDataSource: no Adapter could be selected!"); |
user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'"); |
536 |
break; |
break; |
537 |
} |
} |
538 |
|
|
727 |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
728 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
729 |
case 'data': |
case 'data': |
730 |
//$command = 'queryData'; |
$command = 'queryData'; |
731 |
$command = 'getObjects'; // FIXME!!! |
|
732 |
|
//$command = 'getObjects'; // FIXME!!! |
733 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
734 |
|
/* |
735 |
$args = array(); |
$args = array(); |
736 |
switch ($this->_query[vartype]) { |
switch ($this->_query[vartype]) { |
737 |
case 'object': |
case 'objects': |
738 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
739 |
$msg = "_query[vartype] == 'object' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
740 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
741 |
} |
} |
742 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
743 |
break; |
break; |
744 |
} |
} |
745 |
break; |
*/ |
746 |
|
$query_args = array(); |
747 |
|
|
748 |
|
$msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: "; |
749 |
|
switch ($this->_query[abstract_type]) { |
750 |
|
case 'item': |
751 |
|
if (!$this->_query[nodename] && $this->_query[action] != 'create') { |
752 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
753 |
|
user_error($msg_prefix . $msg); |
754 |
|
} elseif($this->_query[action] == 'create' && $this->_query[parent]) { |
755 |
|
if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; } |
756 |
|
if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; } |
757 |
|
$query_args[nodename] = $this->_query[ident]; |
758 |
|
$query_args[parent][guid] = $this->_query[parent][guid]; |
759 |
|
$query_args[parent][nodename] = $this->_query[parent][nodename]; |
760 |
|
} else { |
761 |
|
$query_args[guid] = $this->_query[ident]; |
762 |
|
$query_args[nodename] = $this->_query[nodename]; |
763 |
|
// 2003-11-17 NEW: use expand flag for real obj expand at backend |
764 |
|
if ($this->_query[expand]) {$query_args[expand] = 1; } |
765 |
|
} |
766 |
|
break; |
767 |
|
case 'list': |
768 |
|
if (!$this->_query[nodename]) { |
769 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
770 |
|
user_error($msg_prefix . $msg); |
771 |
|
} |
772 |
|
//array_push($query_args, $this->_query[nodename]); |
773 |
|
$query_args[nodename] = $this->_query[nodename]; |
774 |
|
if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; } |
775 |
|
break; |
776 |
|
case 'tree': |
777 |
|
/* |
778 |
|
if (!$this->_query[nodename]) { |
779 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
780 |
|
user_error($msg_prefix . $msg); |
781 |
|
} |
782 |
|
*/ |
783 |
|
$query_args[guid] = $this->_query[ident]; |
784 |
|
//$query_args[nodename] = $this->_query[nodename]; |
785 |
|
break; |
786 |
|
default: |
787 |
|
$msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'."; |
788 |
|
user_error($msg_prefix . $msg); |
789 |
|
break; |
790 |
|
} |
791 |
|
|
792 |
|
// filter??? |
793 |
|
//print "Filter: " . Dumper($this->_query[filter]) . "<br>"; |
794 |
|
if ($this->_query[filter]) { |
795 |
|
$query_args[filter] = $this->_query[filter]; |
796 |
|
} |
797 |
|
|
798 |
|
// dispatch action |
799 |
|
//print "Action: " . $this->_query[action] . "<br>"; |
800 |
|
if ($this->_query[action] == 'write') { |
801 |
|
$query_args[action] = $this->_query[action]; |
802 |
|
$query_args[data] = $this->_query[data]; |
803 |
|
} elseif ($this->_query[action] == 'delete') { |
804 |
|
$query_args[action] = $this->_query[action]; |
805 |
|
} elseif ($this->_query[action] == 'create') { |
806 |
|
$query_args[action] = $this->_query[action]; |
807 |
|
} |
808 |
|
|
809 |
|
$args = array( |
810 |
|
'data_type' => $this->_query[abstract_type], |
811 |
|
'query_args' => $query_args |
812 |
|
); |
813 |
|
break; |
814 |
|
|
815 |
|
// querySchema |
816 |
case 'schema': |
case 'schema': |
817 |
|
//print "Testing schema:" . "<br>"; |
818 |
$command = 'querySchema'; |
$command = 'querySchema'; |
819 |
|
$args = array( $this->_query[filter] ); |
820 |
break; |
break; |
821 |
|
|
822 |
|
// remoteMethod |
823 |
|
case 'method': |
824 |
|
$command = $this->_query[method]; |
825 |
|
//$args = $this->_query[args]; |
826 |
|
// FIX |
827 |
|
$args = array( $this->_query[args] ); |
828 |
|
break; |
829 |
|
|
830 |
} |
} |
831 |
|
|
832 |
|
|
833 |
|
// FIXME: bad behaviour? |
834 |
|
if (!is_array($args)) { $args = array( $args ); } |
835 |
|
|
836 |
|
//print Dumper($args); |
837 |
|
|
838 |
/* |
/* |
839 |
$this->_query[rpc_command] = $command; |
$this->_query[rpc_command] = $command; |
866 |
|
|
867 |
} |
} |
868 |
|
|
869 |
|
|
870 |
|
|
871 |
function &fetch_result() { |
function &fetch_result() { |
872 |
|
|
873 |
|
//print Dumper($this); |
874 |
|
|
875 |
$this->datasource_handler_buildoptions(); |
$this->datasource_handler_buildoptions(); |
876 |
|
|
877 |
$method = $this->_locator->_call[_method]; |
$call = $this->_locator->get_call(); |
878 |
$args = $this->_locator->_call[_arguments]; |
|
879 |
|
//print Dumper($call); |
880 |
|
//return; |
881 |
|
|
882 |
// pre-flight checks |
// pre-flight checks |
883 |
if (!$method) { |
if (!$call[method]) { |
884 |
$msg = "Remote command could not be resolved, please pass in or check configuration."; |
$msg = "Remote method is empty, please pass in proper metadata or check configuration."; |
885 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
886 |
return; |
return; |
887 |
} |
} |
888 |
|
|
890 |
|
|
891 |
// do remote call here and get result |
// do remote call here and get result |
892 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
893 |
$this->datasource_handler_call($method, $args); |
$this->datasource_handler_call($call[method], $call[args]); |
894 |
|
|
895 |
|
|
896 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
901 |
$this->_result_count = sizeof($this->_result); |
$this->_result_count = sizeof($this->_result); |
902 |
|
|
903 |
// trace |
// trace |
904 |
if ($this->_debug[notice]) { |
//if (constants::get('VERBOSE') && $this->_debug[notice]) { |
905 |
|
if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) { |
906 |
//print "_result = " . Dumper($this->_result); |
//print "_result = " . Dumper($this->_result); |
907 |
print "DataSource::Generic->_result_count = " . $this->_result_count . "<br/>"; |
//print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>"; |
908 |
|
$this->draw_status_box(); |
909 |
} |
} |
910 |
|
|
911 |
return $this->_result; |
return $this->_result; |
912 |
|
|
913 |
} |
} |
914 |
|
|
915 |
|
function draw_status_box() { |
916 |
|
|
917 |
|
static $boxcount; |
918 |
|
|
919 |
|
$boxcount++; |
920 |
|
|
921 |
|
$box = container(); |
922 |
|
|
923 |
|
// box style |
924 |
|
$style = container( |
925 |
|
html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'), |
926 |
|
html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }') |
927 |
|
); |
928 |
|
$box->add( $style ); |
929 |
|
|
930 |
|
// box content |
931 |
|
$statusbox = html_div('box_dsg'); |
932 |
|
$statusbox->add( html_b("DataSource::Generic"), html_br() ); |
933 |
|
$locatorbox = html_div('box_dsg'); |
934 |
|
$locatorbox->set_id("locatorbox_$boxcount"); |
935 |
|
$locatorbox->add( Dumper($this->_locator) ); |
936 |
|
|
937 |
|
// FIXME: ie/mozilla? |
938 |
|
//$locatorbox->set_style('display:none;'); |
939 |
|
//$locatorbox->set_style('visibility:hidden;'); |
940 |
|
// already duplicate inside Tracer!!! |
941 |
|
$locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;'); |
942 |
|
|
943 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() ); |
944 |
|
$call = $this->_locator->get_call(); |
945 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() ); |
946 |
|
if (sizeof($call[args])) { |
947 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() ); |
948 |
|
} |
949 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() ); |
950 |
|
$box->add( $statusbox ); |
951 |
|
|
952 |
|
//print $box->render(); |
953 |
|
trace( $box ); |
954 |
|
|
955 |
|
} |
956 |
|
|
957 |
|
|
958 |
function &query_data() { |
function &query_data() { |
959 |
//print "query!<br/>"; |
//print "query!<br/>"; |
969 |
function &get_result() { |
function &get_result() { |
970 |
return $this->_result; |
return $this->_result; |
971 |
} |
} |
972 |
|
|
973 |
|
function get_result_count() { |
974 |
|
return $this->_result_count; |
975 |
|
} |
976 |
|
|
977 |
} |
} |
978 |
|
|