9 |
*/ |
*/ |
10 |
|
|
11 |
/** |
/** |
12 |
* <b>Cvs-Log:</b> |
* Cvs-Log: |
13 |
* |
* |
|
* <pre> |
|
14 |
* $Id$ |
* $Id$ |
15 |
* |
* |
16 |
* $Log$ |
* $Log$ |
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 |
* Revision 1.9 2003/03/27 16:24:26 jonen |
57 |
* + mugled namespace |
* + mugled namespace |
58 |
* + added enhanced 'queryData' |
* + added enhanced 'queryData' |
105 |
* |
* |
106 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
107 |
* + initial commit |
* + initial commit |
|
* </pre> |
|
108 |
* |
* |
109 |
*/ |
*/ |
110 |
|
|
301 |
* other presets. |
* other presets. |
302 |
* |
* |
303 |
* See '_buildLocator' which acts as a dispatcher |
* See '_buildLocator' which acts as a dispatcher |
304 |
* depending on $_options[datasource]. |
* depending on $_options[transport]. |
305 |
* (main dispatching level) |
* (main dispatching level) |
306 |
* |
* |
307 |
* The structure of a full blown locator looks like this: |
* The structure of a full blown locator looks like this: |
390 |
function DataSource_Generic( &$locator, $query ) { |
function DataSource_Generic( &$locator, $query ) { |
391 |
|
|
392 |
// copy parameter from query to locator |
// copy parameter from query to locator |
393 |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_'); |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_'); |
394 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[transport]; |
395 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[transport]; |
396 |
|
|
397 |
/** |
/** |
398 |
* <!-- Autodia --> |
* <!-- Autodia --> |
402 |
*/ |
*/ |
403 |
|
|
404 |
// build master locator |
// build master locator |
405 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) ); |
406 |
//exit; |
//exit; |
407 |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
408 |
|
|
439 |
// pre-flight: check locator metadata |
// pre-flight: check locator metadata |
440 |
//$locator->build(); |
//$locator->build(); |
441 |
if (!$this->_locator->check()) { |
if (!$this->_locator->check()) { |
442 |
user_error("locator-check failed."); |
user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) ); |
443 |
exit; |
//exit; |
444 |
//return; |
return; |
445 |
} |
} |
446 |
|
|
447 |
//exit; |
//exit; |
500 |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
501 |
|
|
502 |
switch ($locator->_adapter_type) { |
switch ($locator->_adapter_type) { |
503 |
|
|
504 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
505 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
|
|
|
506 |
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
507 |
|
|
508 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
509 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
510 |
// Exporter::export_symbol(from, to) |
// Exporter::export_symbol(from, to) |
511 |
$this->set_adapter_options($this); |
$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; |
break; |
521 |
|
|
522 |
default: |
default: |
523 |
user_error("DataSource::GenericDataSource: no Adapter could be selected!"); |
user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'"); |
524 |
break; |
break; |
525 |
} |
} |
526 |
|
|
716 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
717 |
case 'data': |
case 'data': |
718 |
$command = 'queryData'; |
$command = 'queryData'; |
719 |
|
|
720 |
//$command = 'getObjects'; // FIXME!!! |
//$command = 'getObjects'; // FIXME!!! |
721 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
722 |
/* |
/* |
725 |
case 'objects': |
case 'objects': |
726 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
727 |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
728 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
729 |
} |
} |
730 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
731 |
break; |
break; |
732 |
} |
} |
733 |
*/ |
*/ |
734 |
$query_args = array(); |
$query_args = array(); |
735 |
|
|
736 |
|
$msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: "; |
737 |
switch ($this->_query[abstract_type]) { |
switch ($this->_query[abstract_type]) { |
738 |
|
case 'item': |
739 |
|
if (!$this->_query[nodename]) { |
740 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
741 |
|
user_error($msg_prefix . $msg); |
742 |
|
} |
743 |
|
$query_args[guid] = $this->_query[ident]; |
744 |
|
$query_args[nodename] = $this->_query[nodename]; |
745 |
|
break; |
746 |
case 'list': |
case 'list': |
747 |
if (!$this->_query[classname]) { |
if (!$this->_query[nodename]) { |
748 |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
749 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error($msg_prefix . $msg); |
750 |
} |
} |
751 |
//array_push($query_args, $this->_query[classname]); |
//array_push($query_args, $this->_query[nodename]); |
752 |
$query_args[classname] = $this->_query[classname]; |
$query_args[nodename] = $this->_query[nodename]; |
753 |
|
if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; } |
754 |
break; |
break; |
755 |
case 'item': |
case 'tree': |
756 |
if (!$this->_query[classname]) { |
/* |
757 |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
if (!$this->_query[nodename]) { |
758 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
759 |
|
user_error($msg_prefix . $msg); |
760 |
} |
} |
761 |
|
*/ |
762 |
$query_args[guid] = $this->_query[ident]; |
$query_args[guid] = $this->_query[ident]; |
763 |
$query_args[classname] = $this->_query[classname]; |
//$query_args[nodename] = $this->_query[nodename]; |
764 |
break; |
break; |
765 |
|
default: |
766 |
|
$msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'."; |
767 |
|
user_error($msg_prefix . $msg); |
768 |
|
break; |
769 |
} |
} |
770 |
|
|
771 |
|
// filter??? |
772 |
|
if ($this->_query[filter]) { |
773 |
|
$query_args[filter] = $this->_query[filter]; |
774 |
|
} |
775 |
|
|
776 |
|
// dispatch action |
777 |
|
if ($this->_query[action] == 'write') { |
778 |
|
$query_args[action] = $this->_query[action]; |
779 |
|
$query_args[data] = $this->_query[data]; |
780 |
|
} elseif ($this->_query[action] == 'delete') { |
781 |
|
$query_args[action] = $this->_query[action]; |
782 |
|
} |
783 |
|
|
784 |
$args = array( |
$args = array( |
785 |
'data_type' => $this->_query[abstract_type], |
'data_type' => $this->_query[abstract_type], |
786 |
'query_args' => $query_args |
'query_args' => $query_args |
791 |
case 'schema': |
case 'schema': |
792 |
//print "Testing schema:" . "<br>"; |
//print "Testing schema:" . "<br>"; |
793 |
$command = 'querySchema'; |
$command = 'querySchema'; |
794 |
|
$args = array( $this->_query[filter] ); |
795 |
break; |
break; |
796 |
|
|
797 |
|
// remoteMethod |
798 |
|
case 'method': |
799 |
|
$command = $this->_query[method]; |
800 |
|
$args = $this->_query[args]; |
801 |
|
break; |
802 |
|
|
803 |
} |
} |
804 |
|
|
805 |
|
|
806 |
|
// FIXME: bad behaviour? |
807 |
|
if (!is_array($args)) { $args = array( $args ); } |
808 |
|
|
809 |
/* |
/* |
810 |
$this->_query[rpc_command] = $command; |
$this->_query[rpc_command] = $command; |
837 |
|
|
838 |
} |
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
function &fetch_result() { |
function &fetch_result() { |
843 |
|
|
844 |
|
//print Dumper($this); |
845 |
|
|
846 |
$this->datasource_handler_buildoptions(); |
$this->datasource_handler_buildoptions(); |
847 |
|
|
848 |
$method = $this->_locator->_call[_method]; |
$call = $this->_locator->get_call(); |
849 |
$args = $this->_locator->_call[_arguments]; |
|
850 |
|
//print Dumper($call); |
851 |
|
//return; |
852 |
|
|
853 |
// pre-flight checks |
// pre-flight checks |
854 |
if (!$method) { |
if (!$call[method]) { |
855 |
$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."; |
856 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
857 |
return; |
return; |
858 |
} |
} |
859 |
|
|
861 |
|
|
862 |
// do remote call here and get result |
// do remote call here and get result |
863 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
864 |
$this->datasource_handler_call($method, $args); |
$this->datasource_handler_call($call[method], $call[args]); |
865 |
|
|
866 |
|
|
867 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
872 |
$this->_result_count = sizeof($this->_result); |
$this->_result_count = sizeof($this->_result); |
873 |
|
|
874 |
// trace |
// trace |
875 |
if ($this->_debug[notice]) { |
//if (constants::get('VERBOSE') && $this->_debug[notice]) { |
876 |
|
if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) { |
877 |
//print "_result = " . Dumper($this->_result); |
//print "_result = " . Dumper($this->_result); |
878 |
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>"; |
879 |
|
$this->draw_status_box(); |
880 |
} |
} |
881 |
|
|
882 |
return $this->_result; |
return $this->_result; |
883 |
|
|
884 |
} |
} |
885 |
|
|
886 |
|
function draw_status_box() { |
887 |
|
|
888 |
|
static $boxcount; |
889 |
|
|
890 |
|
$boxcount++; |
891 |
|
|
892 |
|
$box = container(); |
893 |
|
|
894 |
|
// box style |
895 |
|
$style = container( |
896 |
|
html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'), |
897 |
|
html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }') |
898 |
|
); |
899 |
|
$box->add( $style ); |
900 |
|
|
901 |
|
// box content |
902 |
|
$statusbox = html_div('box_dsg'); |
903 |
|
$statusbox->add( html_b("DataSource::Generic"), html_br() ); |
904 |
|
$locatorbox = html_div('box_dsg'); |
905 |
|
$locatorbox->set_id("locatorbox_$boxcount"); |
906 |
|
$locatorbox->add( Dumper($this->_locator) ); |
907 |
|
|
908 |
|
// FIXME: ie/mozilla? |
909 |
|
//$locatorbox->set_style('display:none;'); |
910 |
|
//$locatorbox->set_style('visibility:hidden;'); |
911 |
|
// already duplicate inside Tracer!!! |
912 |
|
$locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;'); |
913 |
|
|
914 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() ); |
915 |
|
$call = $this->_locator->get_call(); |
916 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() ); |
917 |
|
if (sizeof($call[args])) { |
918 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() ); |
919 |
|
} |
920 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() ); |
921 |
|
$box->add( $statusbox ); |
922 |
|
|
923 |
|
//print $box->render(); |
924 |
|
trace( $box ); |
925 |
|
|
926 |
|
} |
927 |
|
|
928 |
|
|
929 |
function &query_data() { |
function &query_data() { |
930 |
//print "query!<br/>"; |
//print "query!<br/>"; |
940 |
function &get_result() { |
function &get_result() { |
941 |
return $this->_result; |
return $this->_result; |
942 |
} |
} |
943 |
|
|
944 |
|
function get_result_count() { |
945 |
|
return $this->_result_count; |
946 |
|
} |
947 |
|
|
948 |
} |
} |
949 |
|
|