| 9 |
*/ |
*/ |
| 10 |
|
|
| 11 |
/** |
/** |
| 12 |
|
* Cvs-Log: |
| 13 |
|
* |
| 14 |
* $Id$ |
* $Id$ |
| 15 |
* |
* |
| 16 |
* $Log$ |
* $Log$ |
| 17 |
|
* Revision 1.19 2003/04/18 15:40:51 joko |
| 18 |
|
* NEW: tree data handling |
| 19 |
|
* introduced new adapter: DataSource::Adapter::Free |
| 20 |
|
* enhanced datasource_handler_buildoptions: now handles a) case 'tree' b) _query[filter] |
| 21 |
|
* |
| 22 |
|
* Revision 1.18 2003/04/11 00:55:49 joko |
| 23 |
|
* updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete' |
| 24 |
|
* |
| 25 |
|
* Revision 1.17 2003/04/09 02:07:33 joko |
| 26 |
|
* CHANGE: renamed key 'classname' through 'nodename' |
| 27 |
|
* |
| 28 |
|
* Revision 1.16 2003/04/08 17:55:20 joko |
| 29 |
|
* CHANGE: renamed property 'datasource' to 'transport' |
| 30 |
|
* NEW: new case 'method' in 'function datasource_handler_buildoptions' |
| 31 |
|
* minor fixes: updated logging/debugging messages |
| 32 |
|
* |
| 33 |
|
* Revision 1.15 2003/04/06 04:46:33 joko |
| 34 |
|
* renamed linking function |
| 35 |
|
* mozilla fixes |
| 36 |
|
* |
| 37 |
|
* Revision 1.14 2003/04/04 21:19:21 joko |
| 38 |
|
* modified exception handling (enhanced, purged redundant code) |
| 39 |
|
* |
| 40 |
|
* Revision 1.13 2003/04/04 02:37:14 jonen |
| 41 |
|
* _query[action] == write |
| 42 |
|
* |
| 43 |
|
* Revision 1.12 2003/03/29 08:00:48 joko |
| 44 |
|
* modified ErrorBoxing |
| 45 |
|
* |
| 46 |
|
* Revision 1.11 2003/03/28 06:45:26 joko |
| 47 |
|
* VERBOSE mode |
| 48 |
|
* |
| 49 |
|
* Revision 1.10 2003/03/28 03:01:02 joko |
| 50 |
|
* more fancy debugging-output |
| 51 |
|
* |
| 52 |
|
* Revision 1.9 2003/03/27 16:24:26 jonen |
| 53 |
|
* + mugled namespace |
| 54 |
|
* + added enhanced 'queryData' |
| 55 |
|
* |
| 56 |
|
* Revision 1.8 2003/03/20 07:22:14 jonen |
| 57 |
|
* + modified case 'object' to 'objects' |
| 58 |
|
* (cause its loads all *objects* of a given classname) |
| 59 |
|
* |
| 60 |
|
* Revision 1.7 2003/03/11 01:43:00 joko |
| 61 |
|
* + fixed metadata for phpDocumentor |
| 62 |
|
* |
| 63 |
|
* Revision 1.6 2003/03/11 01:22:25 joko |
| 64 |
|
* + fixed metadata for phpDocumentor |
| 65 |
|
* |
| 66 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
| 67 |
|
* + fixed metadata for phpDocumentor |
| 68 |
|
* |
| 69 |
* Revision 1.4 2003/03/10 23:25:03 joko |
* Revision 1.4 2003/03/10 23:25:03 joko |
| 70 |
* + fixed metadata for phpDocumentor |
* + fixed metadata for phpDocumentor |
| 71 |
* |
* |
| 102 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
| 103 |
* + initial commit |
* + initial commit |
| 104 |
* |
* |
|
* |
|
| 105 |
*/ |
*/ |
| 106 |
|
|
| 107 |
/** |
/** |
| 179 |
* --- snipped into here from above --- |
* --- snipped into here from above --- |
| 180 |
* </pre> |
* </pre> |
| 181 |
* |
* |
| 182 |
* |
* <p> |
| 183 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
| 184 |
* |
* |
| 185 |
* Data::Driver::Proxy instantiates "handlers" below itself |
* Data::Driver::Proxy instantiates "handlers" below itself |
| 200 |
* </pre> |
* </pre> |
| 201 |
* |
* |
| 202 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
| 203 |
|
* </p> |
| 204 |
* |
* |
| 205 |
* |
* |
| 206 |
|
* <p> |
| 207 |
* <b>How to use?</b> |
* <b>How to use?</b> |
| 208 |
* |
* |
| 209 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
| 210 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
| 211 |
* |
* |
| 212 |
|
* <pre> |
| 213 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
| 214 |
* |
* |
| 215 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
| 231 |
* $source = ne w GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
| 232 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
| 233 |
* </code> |
* </code> |
| 234 |
|
* </pre> |
| 235 |
|
* </p> |
| 236 |
|
* |
| 237 |
* |
* |
| 238 |
* @link http://www.netfrag.org/~joko/ |
* @link http://www.netfrag.org/~joko/ |
| 239 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 252 |
* @name DataSource::Generic |
* @name DataSource::Generic |
| 253 |
* |
* |
| 254 |
* @todo this: |
* @todo this: |
| 255 |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
| 256 |
|
* o implement another Data::Driver::Proxy container |
| 257 |
* |
* |
| 258 |
* <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> |
|
|
* |
|
| 259 |
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
| 260 |
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
| 261 |
* |
* |
| 271 |
* 2. here: DataSource - scope: |
* 2. here: DataSource - scope: |
| 272 |
* 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.)) |
| 273 |
* o clean implementation using a DesignPattern::AdapterProxy |
* o clean implementation using a DesignPattern::AdapterProxy |
| 274 |
|
* </pre> |
| 275 |
* |
* |
| 276 |
* |
* |
| 277 |
*/ |
*/ |
| 297 |
* other presets. |
* other presets. |
| 298 |
* |
* |
| 299 |
* See '_buildLocator' which acts as a dispatcher |
* See '_buildLocator' which acts as a dispatcher |
| 300 |
* depending on $_options[datasource]. |
* depending on $_options[transport]. |
| 301 |
* (main dispatching level) |
* (main dispatching level) |
| 302 |
* |
* |
| 303 |
* The structure of a full blown locator looks like this: |
* The structure of a full blown locator looks like this: |
| 386 |
function DataSource_Generic( &$locator, $query ) { |
function DataSource_Generic( &$locator, $query ) { |
| 387 |
|
|
| 388 |
// copy parameter from query to locator |
// copy parameter from query to locator |
| 389 |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_'); |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_'); |
| 390 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[transport]; |
| 391 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[transport]; |
| 392 |
|
|
| 393 |
/** |
/** |
| 394 |
* <!-- Autodia --> |
* <!-- Autodia --> |
| 398 |
*/ |
*/ |
| 399 |
|
|
| 400 |
// build master locator |
// build master locator |
| 401 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) ); |
| 402 |
//exit; |
//exit; |
| 403 |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
| 404 |
|
|
| 435 |
// pre-flight: check locator metadata |
// pre-flight: check locator metadata |
| 436 |
//$locator->build(); |
//$locator->build(); |
| 437 |
if (!$this->_locator->check()) { |
if (!$this->_locator->check()) { |
| 438 |
user_error("locator-check failed."); |
user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) ); |
| 439 |
exit; |
//exit; |
| 440 |
//return; |
return; |
| 441 |
} |
} |
| 442 |
|
|
| 443 |
//exit; |
//exit; |
| 496 |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
| 497 |
|
|
| 498 |
switch ($locator->_adapter_type) { |
switch ($locator->_adapter_type) { |
| 499 |
|
|
| 500 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
| 501 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
| 502 |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource'); |
|
| 503 |
|
|
| 504 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
| 505 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
| 506 |
// Exporter::export_symbol(from, to) |
// Exporter::export_symbol(from, to) |
| 507 |
$this->set_adapter_options($this); |
$this->set_adapter_options($this); |
| 508 |
|
break; |
| 509 |
|
|
| 510 |
|
// NEW [2003-04-17]: Freedom for the adapter! |
| 511 |
|
// phpHtmlLib didn't have a tree widget, but PEAR does. |
| 512 |
|
// So: Free us from the phpHtmlLib-adapter in this case. |
| 513 |
|
case 'free': |
| 514 |
|
$this->set_adapter_module('DataSource::Adapter::Free'); |
| 515 |
|
$this->set_adapter_options($this); |
| 516 |
break; |
break; |
| 517 |
|
|
| 518 |
default: |
default: |
| 519 |
user_error("DataSource::GenericDataSource: no Adapter could be selected!"); |
user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'"); |
| 520 |
break; |
break; |
| 521 |
} |
} |
| 522 |
|
|
| 711 |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
| 712 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
| 713 |
case 'data': |
case 'data': |
| 714 |
//$command = 'queryData'; |
$command = 'queryData'; |
| 715 |
$command = 'getObjects'; // FIXME!!! |
|
| 716 |
|
//$command = 'getObjects'; // FIXME!!! |
| 717 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
| 718 |
|
/* |
| 719 |
$args = array(); |
$args = array(); |
| 720 |
switch ($this->_query[vartype]) { |
switch ($this->_query[vartype]) { |
| 721 |
case 'object': |
case 'objects': |
| 722 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
| 723 |
$msg = "_query[vartype] == 'object' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
| 724 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
| 725 |
} |
} |
| 726 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
| 727 |
break; |
break; |
| 728 |
} |
} |
| 729 |
break; |
*/ |
| 730 |
|
$query_args = array(); |
| 731 |
|
|
| 732 |
|
$msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: "; |
| 733 |
|
switch ($this->_query[abstract_type]) { |
| 734 |
|
case 'item': |
| 735 |
|
if (!$this->_query[nodename]) { |
| 736 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
| 737 |
|
user_error($msg_prefix . $msg); |
| 738 |
|
} |
| 739 |
|
$query_args[guid] = $this->_query[ident]; |
| 740 |
|
$query_args[nodename] = $this->_query[nodename]; |
| 741 |
|
break; |
| 742 |
|
case 'list': |
| 743 |
|
if (!$this->_query[nodename]) { |
| 744 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
| 745 |
|
user_error($msg_prefix . $msg); |
| 746 |
|
} |
| 747 |
|
//array_push($query_args, $this->_query[nodename]); |
| 748 |
|
$query_args[nodename] = $this->_query[nodename]; |
| 749 |
|
break; |
| 750 |
|
case 'tree': |
| 751 |
|
/* |
| 752 |
|
if (!$this->_query[nodename]) { |
| 753 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
| 754 |
|
user_error($msg_prefix . $msg); |
| 755 |
|
} |
| 756 |
|
*/ |
| 757 |
|
$query_args[guid] = $this->_query[ident]; |
| 758 |
|
//$query_args[nodename] = $this->_query[nodename]; |
| 759 |
|
break; |
| 760 |
|
default: |
| 761 |
|
$msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'."; |
| 762 |
|
user_error($msg_prefix . $msg); |
| 763 |
|
break; |
| 764 |
|
} |
| 765 |
|
|
| 766 |
|
// filter??? |
| 767 |
|
if ($this->_query[filter]) { |
| 768 |
|
$query_args[filter] = $this->_query[filter]; |
| 769 |
|
} |
| 770 |
|
|
| 771 |
|
// dispatch action |
| 772 |
|
if ($this->_query[action] == 'write') { |
| 773 |
|
$query_args[action] = $this->_query[action]; |
| 774 |
|
$query_args[data] = $this->_query[data]; |
| 775 |
|
} elseif ($this->_query[action] == 'delete') { |
| 776 |
|
$query_args[action] = $this->_query[action]; |
| 777 |
|
} |
| 778 |
|
|
| 779 |
|
$args = array( |
| 780 |
|
'data_type' => $this->_query[abstract_type], |
| 781 |
|
'query_args' => $query_args |
| 782 |
|
); |
| 783 |
|
break; |
| 784 |
|
|
| 785 |
|
// querySchema |
| 786 |
case 'schema': |
case 'schema': |
| 787 |
|
//print "Testing schema:" . "<br>"; |
| 788 |
$command = 'querySchema'; |
$command = 'querySchema'; |
| 789 |
|
$args = array( $this->_query[filter] ); |
| 790 |
|
break; |
| 791 |
|
|
| 792 |
|
// remoteMethod |
| 793 |
|
case 'method': |
| 794 |
|
$command = $this->_query[method]; |
| 795 |
|
$args = $this->_query[args]; |
| 796 |
break; |
break; |
| 797 |
|
|
| 798 |
} |
} |
| 799 |
|
|
| 800 |
|
|
| 801 |
|
// FIXME: bad behaviour? |
| 802 |
|
if (!is_array($args)) { $args = array( $args ); } |
| 803 |
|
|
| 804 |
/* |
/* |
| 805 |
$this->_query[rpc_command] = $command; |
$this->_query[rpc_command] = $command; |
| 832 |
|
|
| 833 |
} |
} |
| 834 |
|
|
| 835 |
|
|
| 836 |
|
|
| 837 |
function &fetch_result() { |
function &fetch_result() { |
| 838 |
|
|
| 839 |
|
//print Dumper($this); |
| 840 |
|
|
| 841 |
$this->datasource_handler_buildoptions(); |
$this->datasource_handler_buildoptions(); |
| 842 |
|
|
| 843 |
$method = $this->_locator->_call[_method]; |
$call = $this->_locator->get_call(); |
| 844 |
$args = $this->_locator->_call[_arguments]; |
|
| 845 |
|
//print Dumper($call); |
| 846 |
|
//return; |
| 847 |
|
|
| 848 |
// pre-flight checks |
// pre-flight checks |
| 849 |
if (!$method) { |
if (!$call[method]) { |
| 850 |
$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."; |
| 851 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
| 852 |
return; |
return; |
| 853 |
} |
} |
| 854 |
|
|
| 856 |
|
|
| 857 |
// do remote call here and get result |
// do remote call here and get result |
| 858 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
| 859 |
$this->datasource_handler_call($method, $args); |
$this->datasource_handler_call($call[method], $call[args]); |
| 860 |
|
|
| 861 |
|
|
| 862 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
| 867 |
$this->_result_count = sizeof($this->_result); |
$this->_result_count = sizeof($this->_result); |
| 868 |
|
|
| 869 |
// trace |
// trace |
| 870 |
if ($this->_debug[notice]) { |
//if (constants::get('VERBOSE') && $this->_debug[notice]) { |
| 871 |
|
if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) { |
| 872 |
//print "_result = " . Dumper($this->_result); |
//print "_result = " . Dumper($this->_result); |
| 873 |
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>"; |
| 874 |
|
$this->draw_status_box(); |
| 875 |
} |
} |
| 876 |
|
|
| 877 |
return $this->_result; |
return $this->_result; |
| 878 |
|
|
| 879 |
} |
} |
| 880 |
|
|
| 881 |
|
function draw_status_box() { |
| 882 |
|
|
| 883 |
|
static $boxcount; |
| 884 |
|
|
| 885 |
|
$boxcount++; |
| 886 |
|
|
| 887 |
|
$box = container(); |
| 888 |
|
|
| 889 |
|
// box style |
| 890 |
|
$style = container( |
| 891 |
|
html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'), |
| 892 |
|
html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }') |
| 893 |
|
); |
| 894 |
|
$box->add( $style ); |
| 895 |
|
|
| 896 |
|
// box content |
| 897 |
|
$statusbox = html_div('box_dsg'); |
| 898 |
|
$statusbox->add( html_b("DataSource::Generic"), html_br() ); |
| 899 |
|
$locatorbox = html_div('box_dsg'); |
| 900 |
|
$locatorbox->set_id("locatorbox_$boxcount"); |
| 901 |
|
$locatorbox->add( Dumper($this->_locator) ); |
| 902 |
|
|
| 903 |
|
// FIXME: ie/mozilla? |
| 904 |
|
//$locatorbox->set_style('display:none;'); |
| 905 |
|
//$locatorbox->set_style('visibility:hidden;'); |
| 906 |
|
// already duplicate inside Tracer!!! |
| 907 |
|
$locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;'); |
| 908 |
|
|
| 909 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() ); |
| 910 |
|
$call = $this->_locator->get_call(); |
| 911 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() ); |
| 912 |
|
if (sizeof($call[args])) { |
| 913 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() ); |
| 914 |
|
} |
| 915 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() ); |
| 916 |
|
$box->add( $statusbox ); |
| 917 |
|
|
| 918 |
|
//print $box->render(); |
| 919 |
|
trace( $box ); |
| 920 |
|
|
| 921 |
|
} |
| 922 |
|
|
| 923 |
|
|
| 924 |
function &query_data() { |
function &query_data() { |
| 925 |
//print "query!<br/>"; |
//print "query!<br/>"; |
| 935 |
function &get_result() { |
function &get_result() { |
| 936 |
return $this->_result; |
return $this->_result; |
| 937 |
} |
} |
| 938 |
|
|
| 939 |
|
function get_result_count() { |
| 940 |
|
return $this->_result_count; |
| 941 |
|
} |
| 942 |
|
|
| 943 |
} |
} |
| 944 |
|
|