/[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.8 by jonen, Thu Mar 20 07:22:14 2003 UTC revision 1.17 by joko, Wed Apr 9 02:07:33 2003 UTC
# Line 15  Line 15 
15   * $Id$   * $Id$
16   *   *
17   * $Log$   * $Log$
18     * Revision 1.17  2003/04/09 02:07:33  joko
19     * CHANGE: renamed key 'classname' through 'nodename'
20     *
21     * Revision 1.16  2003/04/08 17:55:20  joko
22     * CHANGE: renamed property 'datasource' to 'transport'
23     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
24     * minor fixes: updated logging/debugging messages
25     *
26     * Revision 1.15  2003/04/06 04:46:33  joko
27     * renamed linking function
28     * mozilla fixes
29     *
30     * Revision 1.14  2003/04/04 21:19:21  joko
31     * modified exception handling (enhanced, purged redundant code)
32     *
33     * Revision 1.13  2003/04/04 02:37:14  jonen
34     * _query[action] == write
35     *
36     * Revision 1.12  2003/03/29 08:00:48  joko
37     * modified ErrorBoxing
38     *
39     * Revision 1.11  2003/03/28 06:45:26  joko
40     * VERBOSE mode
41     *
42     * Revision 1.10  2003/03/28 03:01:02  joko
43     * more fancy debugging-output
44     *
45     * Revision 1.9  2003/03/27 16:24:26  jonen
46     * + mugled namespace
47     * + added enhanced 'queryData'
48     *
49   * Revision 1.8  2003/03/20 07:22:14  jonen   * Revision 1.8  2003/03/20 07:22:14  jonen
50   * + modified case 'object' to 'objects'   * + modified case 'object' to 'objects'
51   *   (cause its loads all *objects* of a given classname)   *   (cause its loads all *objects* of a given classname)
# Line 260  class DataSource_Generic extends DesignP Line 291  class DataSource_Generic extends DesignP
291      * other presets.      * other presets.
292      *      *
293      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
294      * depending on $_options[datasource].      * depending on $_options[transport].
295      * (main dispatching level)      * (main dispatching level)
296      *      *
297      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 349  class DataSource_Generic extends DesignP Line 380  class DataSource_Generic extends DesignP
380          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
381    
382                  // copy parameter from query to locator                  // copy parameter from query to locator
383                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
384                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
385                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
386                                    
387        /**        /**
388         * <!-- Autodia -->         * <!-- Autodia -->
# Line 361  class DataSource_Generic extends DesignP Line 392  class DataSource_Generic extends DesignP
392         */         */
393    
394                  // build master locator                  // build master locator
395                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
396                  //exit;                  //exit;
397                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
398                                    
# Line 398  class DataSource_Generic extends DesignP Line 429  class DataSource_Generic extends DesignP
429      // pre-flight: check locator metadata      // pre-flight: check locator metadata
430        //$locator->build();        //$locator->build();
431        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
432          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
433          exit;          //exit;
434           //return;           return;
435        }        }
436    
437  //exit;  //exit;
# Line 462  class DataSource_Generic extends DesignP Line 493  class DataSource_Generic extends DesignP
493            case 'phpHtmlLib':            case 'phpHtmlLib':
494              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
495    
496              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
497                            
498              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
499              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
# Line 472  class DataSource_Generic extends DesignP Line 503  class DataSource_Generic extends DesignP
503    
504              break;              break;
505            default:            default:
506              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected!");
507              break;              break;
508          }          }
509    
# Line 667  class DataSource_Generic extends DesignP Line 698  class DataSource_Generic extends DesignP
698        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
699          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
700            case 'data':            case 'data':
701              //$command = 'queryData';              $command = 'queryData';
702              $command = 'getObjects';   // FIXME!!!              
703                //$command = 'getObjects';   // FIXME!!!
704              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
705    /*
706              $args = array();              $args = array();
707              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
708                case 'objects':                case 'objects':
709                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
710                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
711                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
712                  }                  }
713                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
714                  break;                  break;
715              }              }
716              break;   */
717                $query_args = array();
718                 switch ($this->_query[abstract_type]) {
719                  case 'list':
720                    if (!$this->_query[nodename]) {
721                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
722                      user_error("DataSource::Generic: query_data() - failed: " . $msg);
723                    }
724                    //array_push($query_args, $this->_query[nodename]);
725                    $query_args[nodename] = $this->_query[nodename];
726                    break;
727                  case 'item':
728                    if (!$this->_query[nodename]) {
729                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
730                      user_error("DataSource::Generic: query_data() - failed: " . $msg);
731                    }
732                    $query_args[guid] = $this->_query[ident];
733                    $query_args[nodename] = $this->_query[nodename];
734                    break;              
735                }
736                if($this->_query[action] == 'write') {
737                 $query_args[action] = $this->_query[action];
738                 $query_args[data] = $this->_query[data];
739                }
740                $args = array(
741                              'data_type' => $this->_query[abstract_type],
742                              'query_args' => $query_args
743                              );
744               break;
745    
746              // querySchema
747            case 'schema':            case 'schema':
748                //print "Testing schema:" . "<br>";
749              $command = 'querySchema';              $command = 'querySchema';
750                $args = array( $this->_query[filter] );
751              break;              break;
752                
753              // remoteMethod
754              case 'method':
755                $command = $this->_query[method];
756                $args = $this->_query[args];
757                break;
758    
759          }          }
760                
761          
762            // FIXME: bad behaviour?
763            if (!is_array($args)) { $args = array( $args ); }
764                    
765          /*          /*
766          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 718  class DataSource_Generic extends DesignP Line 793  class DataSource_Generic extends DesignP
793                
794    }    }
795    
796    
797    
798          function &fetch_result() {          function &fetch_result() {
799                
800        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
801    
802        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
803        $args = $this->_locator->_call[_arguments];        //print Dumper($call);
804          
805        // pre-flight checks        // pre-flight checks
806          if (!$method) {          if (!$call[method]) {
807            $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.";
808                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
809            return;            return;
810          }          }
811    
# Line 736  class DataSource_Generic extends DesignP Line 813  class DataSource_Generic extends DesignP
813    
814        // do remote call here and get result        // do remote call here and get result
815        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
816          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
817                    
818                    
819          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
# Line 747  class DataSource_Generic extends DesignP Line 824  class DataSource_Generic extends DesignP
824          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
825    
826        // trace        // trace
827          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
828            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
829            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
830            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>";
831              $this->draw_status_box();
832          }          }
833            
834          return $this->_result;          return $this->_result;
835    
836          }          }
837    
838      function draw_status_box() {
839    
840        static $boxcount;
841        
842        $boxcount++;
843    
844        $box = container();
845    
846        // box style
847        $style = container(
848          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
849          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
850        );
851        $box->add( $style );
852        
853        // box content
854        $statusbox = html_div('box_dsg');
855        $statusbox->add( html_b("DataSource::Generic"), html_br() );
856        $locatorbox = html_div('box_dsg');
857        $locatorbox->set_id("locatorbox_$boxcount");
858        $locatorbox->add( Dumper($this->_locator) );
859        
860        // FIXME: ie/mozilla?
861        //$locatorbox->set_style('display:none;');
862        //$locatorbox->set_style('visibility:hidden;');
863        // already duplicate inside Tracer!!!
864        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
865        
866        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
867        $call = $this->_locator->get_call();
868        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
869        if (sizeof($call[args])) {
870          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
871        }
872        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
873        $box->add( $statusbox );
874    
875        //print $box->render();
876        trace( $box );
877    
878      }
879    
880    
881    function &query_data() {    function &query_data() {
882      //print "query!<br/>";      //print "query!<br/>";
# Line 771  class DataSource_Generic extends DesignP Line 892  class DataSource_Generic extends DesignP
892    function &get_result() {    function &get_result() {
893      return $this->_result;      return $this->_result;
894    }    }
895      
896      function get_result_count() {
897        return $this->_result_count;
898      }
899                    
900  }  }
901    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.17

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