/[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.12 by joko, Sat Mar 29 08:00:48 2003 UTC revision 1.21 by jonen, Sat May 10 18:14:50 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.21  2003/05/10 18:14:50  jonen
18     * + implements 'create' of item (query mapping part)
19     *
20     * Revision 1.20  2003/04/19 16:07:15  jonen
21     * + added '_query[list_meta]' at 'queryData' needed for meta query args
22     *    (e.g. at UserManagment)
23     *
24     * Revision 1.19  2003/04/18 15:40:51  joko
25     * NEW: tree data handling
26     *   introduced new adapter: DataSource::Adapter::Free
27     *   enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]
28     *
29     * Revision 1.18  2003/04/11 00:55:49  joko
30     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
31     *
32     * Revision 1.17  2003/04/09 02:07:33  joko
33     * CHANGE: renamed key 'classname' through 'nodename'
34     *
35     * Revision 1.16  2003/04/08 17:55:20  joko
36     * CHANGE: renamed property 'datasource' to 'transport'
37     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
38     * minor fixes: updated logging/debugging messages
39     *
40     * Revision 1.15  2003/04/06 04:46:33  joko
41     * renamed linking function
42     * mozilla fixes
43     *
44     * Revision 1.14  2003/04/04 21:19:21  joko
45     * modified exception handling (enhanced, purged redundant code)
46     *
47     * Revision 1.13  2003/04/04 02:37:14  jonen
48     * _query[action] == write
49     *
50   * Revision 1.12  2003/03/29 08:00:48  joko   * Revision 1.12  2003/03/29 08:00:48  joko
51   * modified ErrorBoxing   * modified ErrorBoxing
52   *   *
# Line 76  Line 108 
108   *   *
109   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
110   * + initial commit   * + initial commit
  * </pre>  
111   *   *
112   */   */
113    
# Line 273  class DataSource_Generic extends DesignP Line 304  class DataSource_Generic extends DesignP
304      * other presets.      * other presets.
305      *      *
306      * See '_buildLocator' which acts as a dispatcher      * See '_buildLocator' which acts as a dispatcher
307      * depending on $_options[datasource].      * depending on $_options[transport].
308      * (main dispatching level)      * (main dispatching level)
309      *      *
310      * The structure of a full blown locator looks like this:      * The structure of a full blown locator looks like this:
# Line 362  class DataSource_Generic extends DesignP Line 393  class DataSource_Generic extends DesignP
393          function DataSource_Generic( &$locator, $query ) {          function DataSource_Generic( &$locator, $query ) {
394    
395                  // copy parameter from query to locator                  // copy parameter from query to locator
396                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_');                  //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
397                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[transport];
398                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[transport];
399                                    
400        /**        /**
401         * <!-- Autodia -->         * <!-- Autodia -->
# Line 374  class DataSource_Generic extends DesignP Line 405  class DataSource_Generic extends DesignP
405         */         */
406    
407                  // build master locator                  // build master locator
408                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
409                  //exit;                  //exit;
410                  //$this->_locator = php::mkComponent('DataSource::Locator');                  //$this->_locator = php::mkComponent('DataSource::Locator');
411                                    
# Line 411  class DataSource_Generic extends DesignP Line 442  class DataSource_Generic extends DesignP
442      // pre-flight: check locator metadata      // pre-flight: check locator metadata
443        //$locator->build();        //$locator->build();
444        if (!$this->_locator->check()) {        if (!$this->_locator->check()) {
445          user_error("locator-check failed.");          user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
446          exit;          //exit;
447           //return;           return;
448        }        }
449    
450  //exit;  //exit;
# Line 472  class DataSource_Generic extends DesignP Line 503  class DataSource_Generic extends DesignP
503          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
504                    
505          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
506    
507            case 'phpHtmlLib':            case 'phpHtmlLib':
508              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
   
509              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
510                            
511              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
512              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
513              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
514              $this->set_adapter_options($this);              $this->set_adapter_options($this);
515                break;
516    
517              // NEW [2003-04-17]: Freedom for the adapter!
518              // phpHtmlLib didn't have a tree widget, but PEAR does.
519              // So: Free us from the phpHtmlLib-adapter in this case.
520              case 'free':
521                $this->set_adapter_module('DataSource::Adapter::Free');
522                $this->set_adapter_options($this);
523              break;              break;
524    
525            default:            default:
526              user_error("DataSource::GenericDataSource: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
527              break;              break;
528          }          }
529    
# Line 681  class DataSource_Generic extends DesignP Line 719  class DataSource_Generic extends DesignP
719          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
720            case 'data':            case 'data':
721              $command = 'queryData';              $command = 'queryData';
722                
723              //$command = 'getObjects';   // FIXME!!!              //$command = 'getObjects';   // FIXME!!!
724              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
725  /*  /*
# Line 689  class DataSource_Generic extends DesignP Line 728  class DataSource_Generic extends DesignP
728                case 'objects':                case 'objects':
729                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
730                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
731                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("DataSource::Generic: query_data() - failed: " . $msg);
732                  }                  }
733                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
734                  break;                  break;
735              }              }
736   */   */
737              $query_args = array();              $query_args = array();
738                
739                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
740               switch ($this->_query[abstract_type]) {               switch ($this->_query[abstract_type]) {
741                  case 'item':
742                    if (!$this->_query[nodename] && $this->_query[action] != 'create') {
743                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
744                      user_error($msg_prefix . $msg);
745                    } elseif($this->_query[action] == 'create' && $this->_query[parent]) {
746                      if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
747                      if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
748                      $query_args[nodename] = $this->_query[ident];
749                      $query_args[parent][guid] = $this->_query[parent][guid];
750                      $query_args[parent][nodename] = $this->_query[parent][nodename];
751                    } else {
752                      $query_args[guid] = $this->_query[ident];
753                      $query_args[nodename] = $this->_query[nodename];
754                    }
755                    break;
756                case 'list':                case 'list':
757                  if (!$this->_query[classname]) {                  if (!$this->_query[nodename]) {
758                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
759                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error($msg_prefix . $msg);
760                  }                  }
761                  //array_push($query_args, $this->_query[classname]);                  //array_push($query_args, $this->_query[nodename]);
762                  $query_args[classname] = $this->_query[classname];                  $query_args[nodename] = $this->_query[nodename];
763                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
764                  break;                  break;
765                case 'item':                case 'tree':
766                  if (!$this->_query[classname]) {                  /*
767                    $msg = "_query[vartype] == 'objects' requires _query[classname]";                  if (!$this->_query[nodename]) {
768                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
769                      user_error($msg_prefix . $msg);
770                  }                  }
771                    */
772                  $query_args[guid] = $this->_query[ident];                  $query_args[guid] = $this->_query[ident];
773                  $query_args[classname] = $this->_query[classname];                  //$query_args[nodename] = $this->_query[nodename];
774                  break;                                break;
775                  default:
776                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
777                    user_error($msg_prefix . $msg);
778                    break;
779                }
780                
781                // filter???
782                print "Filter: " . Dumper($this->_query[filter]) . "<br>";
783                if ($this->_query[filter]) {
784                  $query_args[filter] = $this->_query[filter];
785                }
786                
787                // dispatch action
788                print "Action: " . $this->_query[action] . "<br>";
789                if ($this->_query[action] == 'write') {
790                 $query_args[action] = $this->_query[action];
791                 $query_args[data] = $this->_query[data];
792                } elseif ($this->_query[action] == 'delete') {
793                 $query_args[action] = $this->_query[action];
794                } elseif ($this->_query[action] == 'create') {
795                   $query_args[action] = $this->_query[action];
796              }              }
797                
798              $args = array(              $args = array(
799                            'data_type' => $this->_query[abstract_type],                            'data_type' => $this->_query[abstract_type],
800                            'query_args' => $query_args                            'query_args' => $query_args
# Line 724  class DataSource_Generic extends DesignP Line 805  class DataSource_Generic extends DesignP
805            case 'schema':            case 'schema':
806              //print "Testing schema:" . "<br>";              //print "Testing schema:" . "<br>";
807              $command = 'querySchema';              $command = 'querySchema';
808                $args = array( $this->_query[filter] );
809                break;
810                
811              // remoteMethod
812              case 'method':
813                $command = $this->_query[method];
814                $args = $this->_query[args];
815              break;              break;
816    
817          }          }
818                
819          
820            // FIXME: bad behaviour?
821            if (!is_array($args)) { $args = array( $args ); }
822                    
823          /*          /*
824          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
# Line 762  class DataSource_Generic extends DesignP Line 854  class DataSource_Generic extends DesignP
854    
855    
856          function &fetch_result() {          function &fetch_result() {
857    
858          //print Dumper($this);
859                
860        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
861    
862        $call = $this->_locator->get_call();        $call = $this->_locator->get_call();
863    
864        //print Dumper($call);        //print Dumper($call);
865          //return;
866    
867        // pre-flight checks        // pre-flight checks
868          if (!$call[method]) {          if (!$call[method]) {
869            $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.";
870                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("DataSource::Generic: query_data() - failed: " . $msg);
871            return;            return;
872          }          }
873    
# Line 809  class DataSource_Generic extends DesignP Line 905  class DataSource_Generic extends DesignP
905    
906      $box = container();      $box = container();
907    
     // 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 );  
       
908      // box style      // box style
909      $style = container(      $style = container(
910        html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),        html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
# Line 840  class DataSource_Generic extends DesignP Line 918  class DataSource_Generic extends DesignP
918      $locatorbox = html_div('box_dsg');      $locatorbox = html_div('box_dsg');
919      $locatorbox->set_id("locatorbox_$boxcount");      $locatorbox->set_id("locatorbox_$boxcount");
920      $locatorbox->add( Dumper($this->_locator) );      $locatorbox->add( Dumper($this->_locator) );
     //$locatorbox->set_style('visibility:false;');  
     $locatorbox->set_style('display:none;');  
921            
922      $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() );      // FIXME: ie/mozilla?
923        //$locatorbox->set_style('display:none;');
924        //$locatorbox->set_style('visibility:hidden;');
925        // already duplicate inside Tracer!!!
926        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
927        
928        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
929      $call = $this->_locator->get_call();      $call = $this->_locator->get_call();
930      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );      $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
931      if (sizeof($call[args])) {      if (sizeof($call[args])) {
# Line 852  class DataSource_Generic extends DesignP Line 934  class DataSource_Generic extends DesignP
934      $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() );
935      $box->add( $statusbox );      $box->add( $statusbox );
936    
937      print $box->render();      //print $box->render();
938        trace( $box );
939    
940    }    }
941    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.21

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