/[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.13 by jonen, Fri Apr 4 02:37:14 2003 UTC revision 1.25 by jonen, Mon Nov 17 18:01:03 2003 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12   * <b>Cvs-Log:</b>   * Cvs-Log:
13   *   *
  * <pre>  
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
17     * Revision 1.25  2003/11/17 18:01:03  jonen
18     * bugfix: php cannot use perl-syntax!! ;-)
19     *
20     * Revision 1.23  2003/07/14 10:02:32  jonen
21     * removed debug dumper
22     *
23     * Revision 1.22  2003/06/06 04:25:45  joko
24     * fix: query args get encapsulated once more
25     *
26     * Revision 1.21  2003/05/10 18:14:50  jonen
27     * + implements 'create' of item (query mapping part)
28     *
29     * Revision 1.20  2003/04/19 16:07:15  jonen
30     * + added '_query[list_meta]' at 'queryData' needed for meta query args
31     *    (e.g. at UserManagment)
32     *
33     * Revision 1.19  2003/04/18 15:40:51  joko
34     * NEW: tree data handling
35     *   introduced new adapter: DataSource::Adapter::Free
36     *   enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]
37     *
38     * Revision 1.18  2003/04/11 00:55:49  joko
39     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
40     *
41     * Revision 1.17  2003/04/09 02:07:33  joko
42     * CHANGE: renamed key 'classname' through 'nodename'
43     *
44     * Revision 1.16  2003/04/08 17:55:20  joko
45     * CHANGE: renamed property 'datasource' to 'transport'
46     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
47     * minor fixes: updated logging/debugging messages
48     *
49     * Revision 1.15  2003/04/06 04:46:33  joko
50     * renamed linking function
51     * mozilla fixes
52     *
53     * Revision 1.14  2003/04/04 21:19:21  joko
54     * modified exception handling (enhanced, purged redundant code)
55     *
56   * Revision 1.13  2003/04/04 02:37:14  jonen   * Revision 1.13  2003/04/04 02:37:14  jonen
57   * _query[action] == write   * _query[action] == write
58   *   *
# Line 79  Line 117 
117   *   *
118   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
119   * + initial commit   * + initial commit
  * </pre>  
120   *   *
121   */   */
122    
# Line 276  class DataSource_Generic extends DesignP Line 313  class DataSource_Generic extends DesignP
313      * other presets.      * other presets.
314      *      *
315      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
316      * depending on $_options[datasource].      * depending on $_options[transport].
317      * (main dispatching level)      * (main dispatching level)
318      *      *
319      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 365  class DataSource_Generic extends DesignP Line 402  class DataSource_Generic extends DesignP
402          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
403    
404                  // copy parameter from query to locator                  // copy parameter from query to locator
405                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
406                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
407                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
408                                    
409        /**        /**
410         * <!-- Autodia -->         * <!-- Autodia -->
# Line 377  class DataSource_Generic extends DesignP Line 414  class DataSource_Generic extends DesignP
414         */         */
415    
416                  // build master locator                  // build master locator
417                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
418                  //exit;                  //exit;
419                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
420                                    
# Line 414  class DataSource_Generic extends DesignP Line 451  class DataSource_Generic extends DesignP
451      // pre-flight: check locator metadata      // pre-flight: check locator metadata
452        //$locator->build();        //$locator->build();
453        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
454          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
455          exit;          //exit;
456           //return;           return;
457        }        }
458    
459  //exit;  //exit;
# Line 475  class DataSource_Generic extends DesignP Line 512  class DataSource_Generic extends DesignP
512          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
513                    
514          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
515    
516            case 'phpHtmlLib':            case 'phpHtmlLib':
517              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
   
518              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
519                            
520              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
521              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
522              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
523              $this->set_adapter_options($this);              $this->set_adapter_options($this);
524                break;
525    
526              // NEW [2003-04-17]: Freedom for the adapter!
527              // phpHtmlLib didn't have a tree widget, but PEAR does.
528              // So: Free us from the phpHtmlLib-adapter in this case.
529              case 'free':
530                $this->set_adapter_module('DataSource::Adapter::Free');
531                $this->set_adapter_options($this);
532              break;              break;
533    
534            default:            default:
535              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
536              break;              break;
537          }          }
538    
# Line 693  class DataSource_Generic extends DesignP Line 737  class DataSource_Generic extends DesignP
737                case 'objects':                case 'objects':
738                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
739                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
740                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
741                  }                  }
742                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
743                  break;                  break;
744              }              }
745   */   */
746              $query_args = array();              $query_args = array();
747                
748                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
749               switch ($this->_query[abstract_type]) {               switch ($this->_query[abstract_type]) {
750                  case 'item':
751                    if (!$this->_query[nodename] && $this->_query[action] != 'create') {
752                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
753                      user_error($msg_prefix . $msg);
754                    } elseif($this->_query[action] == 'create' && $this->_query[parent]) {
755                      if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
756                      if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
757                      $query_args[nodename] = $this->_query[ident];
758                      $query_args[parent][guid] = $this->_query[parent][guid];
759                      $query_args[parent][nodename] = $this->_query[parent][nodename];
760                    } else {
761                      $query_args[guid] = $this->_query[ident];
762                      $query_args[nodename] = $this->_query[nodename];
763                      // 2003-11-17 NEW: use expand flag for real obj expand at backend
764                      if ($this->_query[expand]) {$query_args[expand] = 1; }
765                    }
766                    break;
767                case 'list':                case 'list':
768                  if (!$this->_query[classname]) {                  if (!$this->_query[nodename]) {
769                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
770                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error($msg_prefix . $msg);
771                  }                  }
772                  //array_push($query_args, $this->_query[classname]);                  //array_push($query_args, $this->_query[nodename]);
773                  $query_args[classname] = $this->_query[classname];                  $query_args[nodename] = $this->_query[nodename];
774                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
775                  break;                  break;
776                case 'item':                case 'tree':
777                  if (!$this->_query[classname]) {                  /*
778                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                  if (!$this->_query[nodename]) {
779                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
780                      user_error($msg_prefix . $msg);
781                  }                  }
782                    */
783                  $query_args[guid] = $this->_query[ident];                  $query_args[guid] = $this->_query[ident];
784                  $query_args[classname] = $this->_query[classname];                  //$query_args[nodename] = $this->_query[nodename];
785                  break;                                break;
786                  default:
787                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
788                    user_error($msg_prefix . $msg);
789                    break;
790              }              }
791              if($this->_query[action] == 'write') {              
792                // filter???
793                //print "Filter: " . Dumper($this->_query[filter]) . "<br>";
794                if ($this->_query[filter]) {
795                  $query_args[filter] = $this->_query[filter];
796                }
797                
798                // dispatch action
799                //print "Action: " . $this->_query[action] . "<br>";
800                if ($this->_query[action] == 'write') {
801               $query_args[action] = $this->_query[action];               $query_args[action] = $this->_query[action];
802               $query_args[data] = $this->_query[data];               $query_args[data] = $this->_query[data];
803                } elseif ($this->_query[action] == 'delete') {
804                 $query_args[action] = $this->_query[action];
805                } elseif ($this->_query[action] == 'create') {
806                   $query_args[action] = $this->_query[action];
807              }              }
808                
809              $args = array(              $args = array(
810                            'data_type' => $this->_query[abstract_type],                            'data_type' => $this->_query[abstract_type],
811                            'query_args' => $query_args                            'query_args' => $query_args
# Line 732  class DataSource_Generic extends DesignP Line 816  class DataSource_Generic extends DesignP
816            case 'schema':            case 'schema':
817              //print "Testing schema:" . "<br>";              //print "Testing schema:" . "<br>";
818              $command = 'querySchema';              $command = 'querySchema';
819                $args = array( $this->_query[filter] );
820              break;              break;
821                
822              // remoteMethod
823              case 'method':
824                $command = $this->_query[method];
825                //$args = $this->_query[args];
826                // FIX
827                $args = array( $this->_query[args] );
828                break;
829    
830          }          }
831                
832          
833            // FIXME: bad behaviour?
834            if (!is_array($args)) { $args = array( $args ); }
835            
836            //print Dumper($args);
837                    
838          /*          /*
839          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 770  class DataSource_Generic extends DesignP Line 869  class DataSource_Generic extends DesignP
869    
870    
871          function &fetch_result() {          function &fetch_result() {
872    
873          //print Dumper($this);
874                
875        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
876    
877        $call = $this->_locator->get_call();        $call = $this->_locator->get_call();
878    
879        //print Dumper($call);        //print Dumper($call);
880          //return;
881    
882        // pre-flight checks        // pre-flight checks
883          if (!$call[method]) {          if (!$call[method]) {
884            $msg = "Remote method is empty, please pass in proper metadata or check configuration.";            $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
885                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
886            return;            return;
887          }          }
888    
# Line 817  class DataSource_Generic extends DesignP Line 920  class DataSource_Generic extends DesignP
920    
921      $box = container();      $box = container();
922    
     // box client code (javascript)  
     $code_js = "  
     <script language=\"javascript\">  
     function toggle_vis(id) {  
       elem = eval('document.all.' + id);  
       status = elem.style.getAttribute('display');  
       if (status == 'none') {  
         elem.style.setAttribute('display', 'block');  
       } else {  
         elem.style.setAttribute('display', 'none');  
       }  
     }  
     </script>  
     ";  
     //$script = html_script($code_js);  
     //print $script->render();  
     $box->add( $code_js );  
       
923      // box style      // box style
924      $style = container(      $style = container(
925        html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),        html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
# Line 848  class DataSource_Generic extends DesignP Line 933  class DataSource_Generic extends DesignP
933      $locatorbox = html_div('box_dsg');      $locatorbox = html_div('box_dsg');
934      $locatorbox->set_id("locatorbox_$boxcount");      $locatorbox->set_id("locatorbox_$boxcount");
935      $locatorbox->add( Dumper($this->_locator) );      $locatorbox->add( Dumper($this->_locator) );
     //$locatorbox->set_style('visibility:false;');  
     $locatorbox->set_style('display:none;');  
936            
937      $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() );      // FIXME: ie/mozilla?
938        //$locatorbox->set_style('display:none;');
939        //$locatorbox->set_style('visibility:hidden;');
940        // already duplicate inside Tracer!!!
941        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
942        
943        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
944      $call = $this->_locator->get_call();      $call = $this->_locator->get_call();
945      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
946      if (sizeof($call[args])) {      if (sizeof($call[args])) {
# Line 860  class DataSource_Generic extends DesignP Line 949  class DataSource_Generic extends DesignP
949      $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );      $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
950      $box->add( $statusbox );      $box->add( $statusbox );
951    
952      print $box->render();      //print $box->render();
953        trace( $box );
954    
955    }    }
956    

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.25

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