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