9 |
*/ |
*/ |
10 |
|
|
11 |
/** |
/** |
12 |
|
* <b>Cvs-Log:</b> |
13 |
|
* |
14 |
|
* <pre> |
15 |
* $Id$ |
* $Id$ |
16 |
* |
* |
17 |
* $Log$ |
* $Log$ |
18 |
|
* Revision 1.13 2003/04/04 02:37:14 jonen |
19 |
|
* _query[action] == write |
20 |
|
* |
21 |
|
* Revision 1.12 2003/03/29 08:00:48 joko |
22 |
|
* modified ErrorBoxing |
23 |
|
* |
24 |
|
* Revision 1.11 2003/03/28 06:45:26 joko |
25 |
|
* VERBOSE mode |
26 |
|
* |
27 |
|
* Revision 1.10 2003/03/28 03:01:02 joko |
28 |
|
* more fancy debugging-output |
29 |
|
* |
30 |
|
* Revision 1.9 2003/03/27 16:24:26 jonen |
31 |
|
* + mugled namespace |
32 |
|
* + added enhanced 'queryData' |
33 |
|
* |
34 |
|
* Revision 1.8 2003/03/20 07:22:14 jonen |
35 |
|
* + modified case 'object' to 'objects' |
36 |
|
* (cause its loads all *objects* of a given classname) |
37 |
|
* |
38 |
|
* Revision 1.7 2003/03/11 01:43:00 joko |
39 |
|
* + fixed metadata for phpDocumentor |
40 |
|
* |
41 |
|
* Revision 1.6 2003/03/11 01:22:25 joko |
42 |
|
* + fixed metadata for phpDocumentor |
43 |
|
* |
44 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
45 |
|
* + fixed metadata for phpDocumentor |
46 |
|
* |
47 |
|
* Revision 1.4 2003/03/10 23:25:03 joko |
48 |
|
* + fixed metadata for phpDocumentor |
49 |
|
* |
50 |
* Revision 1.3 2003/03/09 15:50:36 joko |
* Revision 1.3 2003/03/09 15:50:36 joko |
51 |
* + additional metadata for Autodia |
* + additional metadata for Autodia |
52 |
* |
* |
79 |
* |
* |
80 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
81 |
* + initial commit |
* + initial commit |
82 |
* |
* </pre> |
83 |
* |
* |
84 |
*/ |
*/ |
85 |
|
|
158 |
* --- snipped into here from above --- |
* --- snipped into here from above --- |
159 |
* </pre> |
* </pre> |
160 |
* |
* |
161 |
* |
* <p> |
162 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
163 |
* |
* |
164 |
* Data::Driver::Proxy instantiates "handlers" below itself |
* Data::Driver::Proxy instantiates "handlers" below itself |
179 |
* </pre> |
* </pre> |
180 |
* |
* |
181 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
182 |
|
* </p> |
183 |
* |
* |
184 |
* |
* |
185 |
|
* <p> |
186 |
* <b>How to use?</b> |
* <b>How to use?</b> |
187 |
* |
* |
188 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
189 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
190 |
* |
* |
191 |
|
* <pre> |
192 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
193 |
* |
* |
194 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
210 |
* $source = ne w GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
211 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
212 |
* </code> |
* </code> |
213 |
|
* </pre> |
214 |
|
* </p> |
215 |
|
* |
216 |
* |
* |
217 |
* @link http://www.netfrag.org/~joko/ |
* @link http://www.netfrag.org/~joko/ |
218 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
230 |
* @subpackage DataSource |
* @subpackage DataSource |
231 |
* @name DataSource::Generic |
* @name DataSource::Generic |
232 |
* |
* |
233 |
* @todo |
* @todo this: |
234 |
* <ul> |
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
235 |
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
* o implement another Data::Driver::Proxy container |
|
* o implement another Data::Driver::Proxy container |
|
|
* </ul> |
|
236 |
* |
* |
237 |
|
* <pre> |
238 |
// !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
239 |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
240 |
// |
* |
241 |
// THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
* THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
242 |
// inheritance trees at the same time, which is *not* possible at |
* inheritance trees at the same time, which is *not* possible at |
243 |
// declare-time. We *do* need some runtime-infrastructure to solve this! |
* declare-time. We *do* need some runtime-infrastructure to solve this! |
244 |
// |
* |
245 |
// TODO: move build- and check-locator stuff from ObjectList to this place!!! |
* TODO: move build- and check-locator stuff from ObjectList to this place!!! |
246 |
// |
* |
247 |
// ABOUT: |
* ABOUT: |
248 |
// 1. otherwhere: WebApp - scope: |
* 1. otherwhere: WebApp - scope: |
249 |
// x handles page vs. block vs. widget; dispatches MVC-View |
* x handles page vs. block vs. widget; dispatches MVC-View |
250 |
// 2. here: DataSource - scope: |
* 2. here: DataSource - scope: |
251 |
// 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.)) |
252 |
// o clean implementation using a DesignPattern::AdapterProxy |
* o clean implementation using a DesignPattern::AdapterProxy |
253 |
// |
* </pre> |
254 |
|
* |
255 |
*/ |
* |
256 |
|
*/ |
257 |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
258 |
|
|
259 |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
478 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
479 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
480 |
|
|
481 |
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource'); |
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
482 |
|
|
483 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
484 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
683 |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
684 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
685 |
case 'data': |
case 'data': |
686 |
//$command = 'queryData'; |
$command = 'queryData'; |
687 |
$command = 'getObjects'; // FIXME!!! |
|
688 |
|
//$command = 'getObjects'; // FIXME!!! |
689 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
690 |
|
/* |
691 |
$args = array(); |
$args = array(); |
692 |
switch ($this->_query[vartype]) { |
switch ($this->_query[vartype]) { |
693 |
case 'object': |
case 'objects': |
694 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
695 |
$msg = "_query[vartype] == 'object' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
696 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
697 |
} |
} |
698 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
699 |
break; |
break; |
700 |
} |
} |
701 |
break; |
*/ |
702 |
|
$query_args = array(); |
703 |
|
switch ($this->_query[abstract_type]) { |
704 |
|
case 'list': |
705 |
|
if (!$this->_query[classname]) { |
706 |
|
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
707 |
|
user_error("GenericDataSource::query_data() - failed: " . $msg); |
708 |
|
} |
709 |
|
//array_push($query_args, $this->_query[classname]); |
710 |
|
$query_args[classname] = $this->_query[classname]; |
711 |
|
break; |
712 |
|
case 'item': |
713 |
|
if (!$this->_query[classname]) { |
714 |
|
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
715 |
|
user_error("GenericDataSource::query_data() - failed: " . $msg); |
716 |
|
} |
717 |
|
$query_args[guid] = $this->_query[ident]; |
718 |
|
$query_args[classname] = $this->_query[classname]; |
719 |
|
break; |
720 |
|
} |
721 |
|
if($this->_query[action] == 'write') { |
722 |
|
$query_args[action] = $this->_query[action]; |
723 |
|
$query_args[data] = $this->_query[data]; |
724 |
|
} |
725 |
|
$args = array( |
726 |
|
'data_type' => $this->_query[abstract_type], |
727 |
|
'query_args' => $query_args |
728 |
|
); |
729 |
|
break; |
730 |
|
|
731 |
|
// querySchema |
732 |
case 'schema': |
case 'schema': |
733 |
|
//print "Testing schema:" . "<br>"; |
734 |
$command = 'querySchema'; |
$command = 'querySchema'; |
735 |
break; |
break; |
736 |
} |
} |
767 |
|
|
768 |
} |
} |
769 |
|
|
770 |
|
|
771 |
|
|
772 |
function &fetch_result() { |
function &fetch_result() { |
773 |
|
|
774 |
$this->datasource_handler_buildoptions(); |
$this->datasource_handler_buildoptions(); |
775 |
|
|
776 |
$method = $this->_locator->_call[_method]; |
$call = $this->_locator->get_call(); |
777 |
$args = $this->_locator->_call[_arguments]; |
//print Dumper($call); |
778 |
|
|
779 |
// pre-flight checks |
// pre-flight checks |
780 |
if (!$method) { |
if (!$call[method]) { |
781 |
$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."; |
782 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
783 |
return; |
return; |
784 |
} |
} |
787 |
|
|
788 |
// do remote call here and get result |
// do remote call here and get result |
789 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
790 |
$this->datasource_handler_call($method, $args); |
$this->datasource_handler_call($call[method], $call[args]); |
791 |
|
|
792 |
|
|
793 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
798 |
$this->_result_count = sizeof($this->_result); |
$this->_result_count = sizeof($this->_result); |
799 |
|
|
800 |
// trace |
// trace |
801 |
if ($this->_debug[notice]) { |
//if (constants::get('VERBOSE') && $this->_debug[notice]) { |
802 |
|
if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) { |
803 |
//print "_result = " . Dumper($this->_result); |
//print "_result = " . Dumper($this->_result); |
804 |
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>"; |
805 |
|
$this->draw_status_box(); |
806 |
} |
} |
807 |
|
|
808 |
return $this->_result; |
return $this->_result; |
809 |
|
|
810 |
} |
} |
811 |
|
|
812 |
|
function draw_status_box() { |
813 |
|
|
814 |
|
static $boxcount; |
815 |
|
|
816 |
|
$boxcount++; |
817 |
|
|
818 |
|
$box = container(); |
819 |
|
|
820 |
|
// box client code (javascript) |
821 |
|
$code_js = " |
822 |
|
<script language=\"javascript\"> |
823 |
|
function toggle_vis(id) { |
824 |
|
elem = eval('document.all.' + id); |
825 |
|
status = elem.style.getAttribute('display'); |
826 |
|
if (status == 'none') { |
827 |
|
elem.style.setAttribute('display', 'block'); |
828 |
|
} else { |
829 |
|
elem.style.setAttribute('display', 'none'); |
830 |
|
} |
831 |
|
} |
832 |
|
</script> |
833 |
|
"; |
834 |
|
//$script = html_script($code_js); |
835 |
|
//print $script->render(); |
836 |
|
$box->add( $code_js ); |
837 |
|
|
838 |
|
// box style |
839 |
|
$style = container( |
840 |
|
html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'), |
841 |
|
html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }') |
842 |
|
); |
843 |
|
$box->add( $style ); |
844 |
|
|
845 |
|
// box content |
846 |
|
$statusbox = html_div('box_dsg'); |
847 |
|
$statusbox->add( html_b("DataSource::Generic"), html_br() ); |
848 |
|
$locatorbox = html_div('box_dsg'); |
849 |
|
$locatorbox->set_id("locatorbox_$boxcount"); |
850 |
|
$locatorbox->add( Dumper($this->_locator) ); |
851 |
|
//$locatorbox->set_style('visibility:false;'); |
852 |
|
$locatorbox->set_style('display:none;'); |
853 |
|
|
854 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() ); |
855 |
|
$call = $this->_locator->get_call(); |
856 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() ); |
857 |
|
if (sizeof($call[args])) { |
858 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() ); |
859 |
|
} |
860 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() ); |
861 |
|
$box->add( $statusbox ); |
862 |
|
|
863 |
|
print $box->render(); |
864 |
|
|
865 |
|
} |
866 |
|
|
867 |
|
|
868 |
function &query_data() { |
function &query_data() { |
869 |
//print "query!<br/>"; |
//print "query!<br/>"; |
879 |
function &get_result() { |
function &get_result() { |
880 |
return $this->_result; |
return $this->_result; |
881 |
} |
} |
882 |
|
|
883 |
|
function get_result_count() { |
884 |
|
return $this->_result_count; |
885 |
|
} |
886 |
|
|
887 |
} |
} |
888 |
|
|