xotcl.wu-wien.ac.at
Begin main content
Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]

::xotcl::Class[i] ::xo::parameter

Class Hierarchy of ::xo::parameter

  • ::xotcl::Object[i]
    Meta-class:
    ::xotcl::Class[i]
    Methods for instances:
    __api_make_doc, __api_make_forward_doc, __timediff, abstract, ad_doc, ad_forward, ad_proc, appendC, arrayC, asHTML, autonameC, check, classC, cleanupC, configureC, containsC, copyC, db_0or1rowC, db_1rowC, debug, defaultmethodC, destroyC, destroy_on_cleanup, ds, evalC, existsC, extractConfigureArg, filterC, filterguardC, filtersearch, forward, hasclass, incrC, infoC, init, instvarC, invarC, isclass, ismetaclass, ismixin, isobject, istype, lappendC, log, method, mixinC, mixinguardC, moveC, msg, noinitC, objectparameter, parametercmdC, proc, procsearch, qn, requireNamespaceC, residualargsC, self, serialize, setC, set_instance_vars_defaults, show-object, substC, traceC, unknown, unsetC, uplevelC, upvarC, volatileC, vwait
    Methods to be applied on the class (in addition to the methods provided by the meta-class):
    getExitHandler, setExitHandler, unsetExitHandler
    • ::xo::parameter[i]
      Meta-class:
      ::xotcl::Class[i]
      Methods for instances:
      clear_per_package_instance_value, get, initialize_loaded_object, per_package_id_name, set_per_package_instance_value
      Methods to be applied on the class (in addition to the methods provided by the meta-class):
      get, get_from_package_key, get_package_class_from_package_key, get_package_id_from_package_key, get_package_key_from_id, get_parameter_object, initialize_parameters

Class Relations

  • superclass: ::xotcl::Object[i]
::xotcl::Class create ::xo::parameter \
     -superclass ::xotcl::Object

Methods

  • proc get

    ::2389804 proc get {-package_id -parameter:required -default {-retry true}} {
        if {![info exists package_id]} {
          # try to get the package id; 
          # if everything fails, use kernel_id (to be compatible with trad. parameter::get)
          set package_id [expr {[info command ::xo::cc] ne "" ? 
    		    [::xo::cc package_id] : 
    		    [ns_conn isconnected] ? [ad_conn package_id] : [ad_acs_kernel_id]}]
        }
        set parameter_obj [my get_parameter_object -parameter_name $parameter -package_id $package_id -retry $retry]
        if {$parameter_obj ne ""} {
          set value [$parameter_obj get -package_id $package_id]
          if {$value eq "" && [$parameter_obj set __success] == 0} {return $default}
          return $value
        } else {
          return $default
        } 
      }
    
  • proc get_from_package_key

    ::2389804 proc get_from_package_key {-package_key:required -parameter:required -default} {
        set parameter_obj [my get_parameter_object -package_key $package_key -parameter_name $parameter]
        if {$parameter_obj eq ""} {
          if {[info exists default]} {return $default}
          error "No parameter '$parameter' for package_key '$package_key' defined"
        }
        set package_id [my get_package_id_from_package_key -package_key $package_key]
        set value [$parameter_obj get -package_id $package_id]
        if {$value eq "" && [$parameter_obj set __success] == 0} {return $default}
        return $value
      }
    
  • proc get_package_class_from_package_key

    ::2389804 proc get_package_class_from_package_key -package_key:required {
        # Look up the parameter class from a package_key.
        # TODO: should be done from object_type of package_id, 
        # but first, we have to store it there).  
        # We simply iterate here of the classes of packages (only a few exist).
        set r ""
        while {1} {
          set r [ns_cache eval xotcl_object_type_cache package_class-$package_key {
            foreach p [::xo::PackageMgr info instances] {
              if {[$p set package_key] eq $package_key} { return $p }
            }
            break; # don't cache
          }]
          break
        }
        return $r
      }
    
  • proc get_package_id_from_package_key

    ::2389804 proc get_package_id_from_package_key -package_key:required {
        return [ns_cache eval xotcl_object_type_cache package_id-$package_key {
          db_string [my qn get_package_id]  [::xo::db::sql select -vars package_id -from apm_packages  -where "package_key = :package_key" -limit 1]
        }]
      }
    
  • proc get_package_key_from_id

    ::2389804 proc get_package_key_from_id -package_id:required {
        return [ns_cache eval xotcl_object_type_cache package_key-$package_id {
          db_string [my qn get_package_key]  "select package_key from apm_packages where package_id = $package_id"
        }]
      }
    
  • proc get_parameter_object

    ::2389804 proc get_parameter_object {-parameter_name:required -package_id -package_key {-retry true}} {
        ::xo::PackageMgr instvar package_class
        if {![info exists package_key]} {
          set package_key [my get_package_key_from_id -package_id $package_id]
        }
        while {$package_key ne ""} {
          set key Parameter_id($package_key,$parameter_name)
          if {[my exists $key]} {
            return [my set $key]
          }
          # 
          # We did not find the parameter object for the current package
          # key. Loop up the parameter class (TODO: should be done from
          # object_type of package_id, but first, we have to store it
          # there).  We simply iterate here of the classes of packages
          # (only a few exist).
          # 
          #my log "--p looking for $parameter_name in superclass of package_key=$package_key"
          set success 0
          set pkg_class [my get_package_class_from_package_key -package_key $package_key]
          if {$pkg_class ne ""} {
            set sc [$pkg_class info superclass]
            if {[$sc exists package_key]} {
              set package_key [$sc package_key]
              set success 1
            }
          }
          if {!$success} break
        }
        if {$retry} {
          #
          # The parameter object was not found. Maybe this is a new 
          # parameter, not known in this thread. We try to load it
          #
          set r [::xo::db::apm_parameter instantiate_objects  -sql [::xo::db::apm_parameter instance_select_query  -where_clause {
                                 and parameter_name = :parameter_name
                                 and package_key = :package_key
                               }]  -object_class ::xo::db::apm_parameter  -as_ordered_composite false -named_objects true -destroy_on_cleanup false]
          #
          # Check for "retry" to avoid potential recursive loops
          #
          if {$r ne ""} {
            #
            # seems as if this parameter was newly defined
            #
            if {![info exists package_id]} {set package_id ""}
            return [my get_parameter_object  -retry false  -parameter_name $parameter_name  -package_id $package_id  -package_key $package_key]
          }
        }
        #
        # if everything fails, return empty
        #
        return ""
      }
    
  • proc initialize_parameters

    ::2389804 proc initialize_parameters {} {
        # Get those parameter values, which are different from the default and
        # remember theses per package_id.
        db_foreach [my qn get_non_default_values] {
          select p.parameter_id, p.package_key, v.package_id, p.parameter_name, 
                 p.default_value, v.attr_value 
          from apm_parameters p, apm_parameter_values v 
          where p.parameter_id = v.parameter_id 
          and coalesce(attr_value,'') <> coalesce(p.default_value,'')
        } {
    #      ns_log notice "--p $parameter_id $package_key $package_id $parameter_name <$attr_value>"
          $parameter_id set_per_package_instance_value $package_id $attr_value
        }
      }
    
  • instproc clear_per_package_instance_value

    ::2389804 instproc clear_per_package_instance_value {package_id value} {
        set array [my per_package_id_name $package_id]
        if {[nsv_exists $array [my parameter_name]]} {
          nsv_unset $array [my parameter_name]
        }
      }
    
  • instproc get

    ::2389804 instproc get -package_id:required {
        set key [my parameter_name]
        set nsv_array_name [my per_package_id_name $package_id]
        if {[nsv_exists $nsv_array_name $key]} {
          #my log "--parameter get <$key> from $nsv_array_name --> '[nsv_get $nsv_array_name $key]'"
          my set __success 1
          return [nsv_get $nsv_array_name $key]
        }
        # We could as well store per-package-key values,
        # but most probably, this is not needed if we use
        # the parameter default (which is per package-key).
        # With additional  per-package-key values, we could implement
        # a very simple "reset to default" for package-key values.
        #
        #     foreach cls $package_class_hierarchy {
        #       set nsv_array_name [my per_package_class_name $cls]
        #       if {[nsv_exists $nsv_array_name $key]} {
        #         #my log "--parameter get <$key> from $nsv_array_name --> '[nsv_get $nsv_array_name $key]'"
        #         return [nsv_get $nsv_array_name $key]
        #       }
        #     }
        #
        #my log "--parameter get <$key> from default of [my package_key] --> '[my default_value]'"
        my set __success 0
        return [my default_value]
      }
    
  • instproc initialize_loaded_object

    ::2389804 instproc initialize_loaded_object {} {
        my instvar package_key parameter_name
        [self class] set Parameter_id($package_key,$parameter_name) [self]
      }
    
  • instproc per_package_id_name

    ::2389804 instproc per_package_id_name package_id {
        return "CFG-$package_id"
      }
    
  • instproc set_per_package_instance_value

    ::2389804 instproc set_per_package_instance_value {package_id value} {
        set array [my per_package_id_name $package_id]
        nsv_set $array [my parameter_name] $value
      }
    

Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]