/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Generic.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DataSource/Generic.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by joko, Sun Mar 9 15:50:36 2003 UTC revision 1.16 by joko, Tue Apr 8 17:55:20 2003 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12     * <b>Cvs-Log:</b>
13     *
14     * <pre>
15   * $Id$   * $Id$
16   *   *
17   * $Log$   * $Log$
18     * Revision 1.16  2003/04/08 17:55:20  joko
19     * CHANGE: renamed property 'datasource' to 'transport'
20     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
21     * minor fixes: updated logging/debugging messages
22     *
23     * Revision 1.15  2003/04/06 04:46:33  joko
24     * renamed linking function
25     * mozilla fixes
26     *
27     * Revision 1.14  2003/04/04 21:19:21  joko
28     * modified exception handling (enhanced, purged redundant code)
29     *
30     * Revision 1.13  2003/04/04 02:37:14  jonen
31     * _query[action] == write
32     *
33     * Revision 1.12  2003/03/29 08:00:48  joko
34     * modified ErrorBoxing
35     *
36     * Revision 1.11  2003/03/28 06:45:26  joko
37     * VERBOSE mode
38     *
39     * Revision 1.10  2003/03/28 03:01:02  joko
40     * more fancy debugging-output
41     *
42     * Revision 1.9  2003/03/27 16:24:26  jonen
43     * + mugled namespace
44     * + added enhanced 'queryData'
45     *
46     * Revision 1.8  2003/03/20 07:22:14  jonen
47     * + modified case 'object' to 'objects'
48     *   (cause its loads all *objects* of a given classname)
49     *
50     * Revision 1.7  2003/03/11 01:43:00  joko
51     * + fixed metadata for phpDocumentor
52     *
53     * Revision 1.6  2003/03/11 01:22:25  joko
54     * + fixed metadata for phpDocumentor
55     *
56     * Revision 1.5  2003/03/11 00:12:49  joko
57     * + fixed metadata for phpDocumentor
58     *
59     * Revision 1.4  2003/03/10 23:25:03  joko
60     * + fixed metadata for phpDocumentor
61     *
62   * Revision 1.3  2003/03/09 15:50:36  joko   * Revision 1.3  2003/03/09 15:50:36  joko
63   * + additional metadata for Autodia   * + additional metadata for Autodia
64   *   *
# Line 44  Line 91 
91   *   *
92   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
93   * + initial commit   * + initial commit
94   *   * </pre>
95   *   *
96   */   */
97    
# Line 123  loadModule('DesignPattern::AdapterProxy' Line 170  loadModule('DesignPattern::AdapterProxy'
170   * --- snipped into here from above ---   * --- snipped into here from above ---
171   * </pre>   * </pre>
172   *   *
173   *   * <p>
174   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
175   *   *
176   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 144  loadModule('DesignPattern::AdapterProxy' Line 191  loadModule('DesignPattern::AdapterProxy'
191   * </pre>   * </pre>
192   *   *
193   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
194     * </p>
195   *   *
196   *   *
197     * <p>
198   * <b>How to use?</b>   * <b>How to use?</b>
199   *   *
200   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
201   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
202   *   *
203     * <pre>
204   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
205   *   *
206   *  1. doing rpc-calls....   *  1. doing rpc-calls....
# Line 172  loadModule('DesignPattern::AdapterProxy' Line 222  loadModule('DesignPattern::AdapterProxy'
222   *    $source = ne w GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
223   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
224   *    </code>   *    </code>
225     * </pre>
226     * </p>
227     *
228   *   *
229   * @link http://www.netfrag.org/~joko/   * @link http://www.netfrag.org/~joko/
230   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
# Line 189  loadModule('DesignPattern::AdapterProxy' Line 242  loadModule('DesignPattern::AdapterProxy'
242   * @subpackage DataSource   * @subpackage DataSource
243   * @name DataSource::Generic   * @name DataSource::Generic
244   *   *
245   * @todo   * @todo this:
246   * <ul>   * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
247   *  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>  
248   *   *
249     * <pre>
250  //              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!   *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
251  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!   *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
252  //   *
253  //    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy   *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
254  //    inheritance trees at the same time, which is *not* possible at   *    inheritance trees at the same time, which is *not* possible at
255  //    declare-time. We *do* need some runtime-infrastructure to solve this!   *    declare-time. We *do* need some runtime-infrastructure to solve this!
256  //   *
257  //    TODO: move build- and check-locator stuff from ObjectList to this place!!!   *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
258  //   *
259  //    ABOUT:   *    ABOUT:
260  //      1. otherwhere: WebApp - scope:   *      1. otherwhere: WebApp - scope:
261  //          x handles page vs. block vs. widget; dispatches MVC-View   *          x handles page vs. block vs. widget; dispatches MVC-View
262  //      2. here: DataSource - scope:   *      2. here: DataSource - scope:
263  //          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.))
264  //          o clean implementation using a DesignPattern::AdapterProxy   *          o clean implementation using a DesignPattern::AdapterProxy
265  //   * </pre>
266     *
267  */   *
268     */
269  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
270    
271  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
# Line 236  class DataSource_Generic extends DesignP Line 288  class DataSource_Generic extends DesignP
288      * other presets.      * other presets.
289      *      *
290      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
291      * depending on $_options[datasource].      * depending on $_options[transport].
292      * (main dispatching level)      * (main dispatching level)
293      *      *
294      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 325  class DataSource_Generic extends DesignP Line 377  class DataSource_Generic extends DesignP
377          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
378    
379                  // copy parameter from query to locator                  // copy parameter from query to locator
380                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
381                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
382                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
383                                    
384        /**        /**
385         * <!-- Autodia -->         * <!-- Autodia -->
# Line 337  class DataSource_Generic extends DesignP Line 389  class DataSource_Generic extends DesignP
389         */         */
390    
391                  // build master locator                  // build master locator
392                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
393                  //exit;                  //exit;
394                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
395                                    
# Line 374  class DataSource_Generic extends DesignP Line 426  class DataSource_Generic extends DesignP
426      // pre-flight: check locator metadata      // pre-flight: check locator metadata
427        //$locator->build();        //$locator->build();
428        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
429          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
430          exit;          //exit;
431           //return;           return;
432        }        }
433    
434  //exit;  //exit;
# Line 438  class DataSource_Generic extends DesignP Line 490  class DataSource_Generic extends DesignP
490            case 'phpHtmlLib':            case 'phpHtmlLib':
491              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
492    
493              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
494                            
495              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
496              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
# Line 448  class DataSource_Generic extends DesignP Line 500  class DataSource_Generic extends DesignP
500    
501              break;              break;
502            default:            default:
503              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected!");
504              break;              break;
505          }          }
506    
# Line 643  class DataSource_Generic extends DesignP Line 695  class DataSource_Generic extends DesignP
695        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
696          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
697            case 'data':            case 'data':
698              //$command = 'queryData';              $command = 'queryData';
699              $command = 'getObjects';   // FIXME!!!              
700                //$command = 'getObjects';   // FIXME!!!
701              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
702    /*
703              $args = array();              $args = array();
704              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
705                case 'object':                case 'objects':
706                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
707                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
708                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
709                  }                  }
710                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
711                  break;                  break;
712              }              }
713              break;   */
714                $query_args = array();
715                 switch ($this->_query[abstract_type]) {
716                  case 'list':
717                    if (!$this->_query[classname]) {
718                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
719                      user_error("DataSource::Generic: query_data() - failed: " . $msg);
720                    }
721                    //array_push($query_args, $this->_query[classname]);
722                    $query_args[classname] = $this->_query[classname];
723                    break;
724                  case 'item':
725                    if (!$this->_query[classname]) {
726                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
727                      user_error("DataSource::Generic: query_data() - failed: " . $msg);
728                    }
729                    $query_args[guid] = $this->_query[ident];
730                    $query_args[classname] = $this->_query[classname];
731                    break;              
732                }
733                if($this->_query[action] == 'write') {
734                 $query_args[action] = $this->_query[action];
735                 $query_args[data] = $this->_query[data];
736                }
737                $args = array(
738                              'data_type' => $this->_query[abstract_type],
739                              'query_args' => $query_args
740                              );
741               break;
742    
743              // querySchema
744            case 'schema':            case 'schema':
745                //print "Testing schema:" . "<br>";
746              $command = 'querySchema';              $command = 'querySchema';
747                $args = array( $this->_query[filter] );
748              break;              break;
749                
750              // remoteMethod
751              case 'method':
752                $command = $this->_query[method];
753                $args = $this->_query[args];
754                break;
755    
756          }          }
757                
758          
759            // FIXME: bad behaviour?
760            if (!is_array($args)) { $args = array( $args ); }
761                    
762          /*          /*
763          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 694  class DataSource_Generic extends DesignP Line 790  class DataSource_Generic extends DesignP
790                
791    }    }
792    
793    
794    
795          function &fetch_result() {          function &fetch_result() {
796                
797        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
798    
799        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
800        $args = $this->_locator->_call[_arguments];        //print Dumper($call);
801          
802        // pre-flight checks        // pre-flight checks
803          if (!$method) {          if (!$call[method]) {
804            $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.";
805                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
806            return;            return;
807          }          }
808    
# Line 712  class DataSource_Generic extends DesignP Line 810  class DataSource_Generic extends DesignP
810    
811        // do remote call here and get result        // do remote call here and get result
812        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
813          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
814                    
815                    
816          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
# Line 723  class DataSource_Generic extends DesignP Line 821  class DataSource_Generic extends DesignP
821          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
822    
823        // trace        // trace
824          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
825            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
826            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
827            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>";
828              $this->draw_status_box();
829          }          }
830            
831          return $this->_result;          return $this->_result;
832    
833          }          }
834    
835      function draw_status_box() {
836    
837        static $boxcount;
838        
839        $boxcount++;
840    
841        $box = container();
842    
843        // box style
844        $style = container(
845          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
846          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
847        );
848        $box->add( $style );
849        
850        // box content
851        $statusbox = html_div('box_dsg');
852        $statusbox->add( html_b("DataSource::Generic"), html_br() );
853        $locatorbox = html_div('box_dsg');
854        $locatorbox->set_id("locatorbox_$boxcount");
855        $locatorbox->add( Dumper($this->_locator) );
856        
857        // FIXME: ie/mozilla?
858        //$locatorbox->set_style('display:none;');
859        //$locatorbox->set_style('visibility:hidden;');
860        // already duplicate inside Tracer!!!
861        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
862        
863        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
864        $call = $this->_locator->get_call();
865        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
866        if (sizeof($call[args])) {
867          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
868        }
869        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
870        $box->add( $statusbox );
871    
872        //print $box->render();
873        trace( $box );
874    
875      }
876    
877    
878    function &query_data() {    function &query_data() {
879      //print "query!<br/>";      //print "query!<br/>";
# Line 747  class DataSource_Generic extends DesignP Line 889  class DataSource_Generic extends DesignP
889    function &get_result() {    function &get_result() {
890      return $this->_result;      return $this->_result;
891    }    }
892      
893      function get_result_count() {
894        return $this->_result_count;
895      }
896                    
897  }  }
898    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.16

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed