Class: WBEM::CIMInstanceName

Inherits:
XMLObject show all
Includes:
Comparable
Defined in:
lib/wbem/cim_obj.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from XMLObject

#cmpname, #eql?, #hash, #nilcmp, #toxml

Constructor Details

#initialize(classname, keybindings = {}, host = nil, namespace = nil) ⇒ CIMInstanceName

Returns a new instance of CIMInstanceName.



491
492
493
494
495
496
# File 'lib/wbem/cim_obj.rb', line 491

def initialize(classname, keybindings = {}, host = nil, namespace = nil)
    @classname = classname
    @keybindings = NocaseHash.new(keybindings)
    @host = host
    @namespace = namespace
end

Instance Attribute Details

#classnameObject

This may be treated as a hash to retrieve the keys.“”“ qualifiers removed?



489
490
491
# File 'lib/wbem/cim_obj.rb', line 489

def classname
  @classname
end

#hostObject

This may be treated as a hash to retrieve the keys.“”“ qualifiers removed?



489
490
491
# File 'lib/wbem/cim_obj.rb', line 489

def host
  @host
end

#keybindingsObject

This may be treated as a hash to retrieve the keys.“”“ qualifiers removed?



489
490
491
# File 'lib/wbem/cim_obj.rb', line 489

def keybindings
  @keybindings
end

#namespaceObject

This may be treated as a hash to retrieve the keys.“”“ qualifiers removed?



489
490
491
# File 'lib/wbem/cim_obj.rb', line 489

def namespace
  @namespace
end

Instance Method Details

#<=>(other) ⇒ Object



502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/wbem/cim_obj.rb', line 502

def <=>(other)
    if equal?(other)
        ret_val = 0
    elsif (!other.kind_of?(CIMInstanceName ))
        ret_val =  1
    else
        ## TODO: Allow for the type to be null as long as the values
        ## are the same and non-null?
        ret_val = cmpname(self.classname, other.classname)
        ret_val = nilcmp(self.keybindings, other.keybindings) if (ret_val == 0)
        ret_val = cmpname(self.host, other.host) if (ret_val == 0)
        ret_val = cmpname(self.namespace, other.namespace) if (ret_val == 0)
    end
    ret_val
end

#[](key) ⇒ Object



552
553
554
# File 'lib/wbem/cim_obj.rb', line 552

def [](key) 
    return self.keybindings[key]
end

#[]=(key, value) ⇒ Object



555
556
557
# File 'lib/wbem/cim_obj.rb', line 555

def []=(key, value) 
    return self.keybindings[key] = value
end

#cloneObject



498
499
500
# File 'lib/wbem/cim_obj.rb', line 498

def clone
    CIMInstanceName.new(@classname, @keybindings, @host, @namespace)
end

#delete(key) ⇒ Object



558
559
560
# File 'lib/wbem/cim_obj.rb', line 558

def delete(key) 
    self.keybindings.delete(key)
end

#fetch(key) ⇒ Object

A whole bunch of dictionary methods that map to the equivalent operation on self.keybindings.



549
550
551
# File 'lib/wbem/cim_obj.rb', line 549

def fetch(key) 
    return self.keybindings.fetch(key)
end

#has_key?(key) ⇒ Boolean

Returns:



564
565
566
# File 'lib/wbem/cim_obj.rb', line 564

def has_key?(key)
    return self.keybindings.has_key?(key)
end

#keysObject



567
568
569
# File 'lib/wbem/cim_obj.rb', line 567

def keys
    return self.keybindings.keys()
end

#lengthObject



561
562
563
# File 'lib/wbem/cim_obj.rb', line 561

def length
    return self.keybindings.length 
end

#to_aObject



573
574
575
# File 'lib/wbem/cim_obj.rb', line 573

def to_a
    return self.keybindings.to_a()
end

#to_sObject



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/wbem/cim_obj.rb', line 522

def to_s
    s = ''

    unless self.host.nil?
        s += '//%s/' % self.host
    end
    unless self.namespace.nil?
        s += '%s:' % self.namespace
    end
    s += '%s.' % self.classname

    self.keybindings.to_a.each do |key, value|
        
        s += "#{key}="
        
        if value.kind_of?(Integer)
            s += value.to_s
        else
            s += '"%s"' % value
        end
        s += ","
    end
    return s[0..-2]
end

#tocimxmlObject



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/wbem/cim_obj.rb', line 577

def tocimxml
    # Generate an XML representation of the instance classname and
    # keybindings.
    
    if (self.keybindings.kind_of?(String))
        # Class with single key string property
        instancename_xml = INSTANCENAME.new(self.classname,
                                            KEYVALUE.new(self.keybindings, "string"))

    elsif (self.keybindings.kind_of?(Integer))
    # Class with single key numeric property
        instancename_xml =  INSTANCENAME.new(self.classname,
                                             KEYVALUE.new(self.keybindings.to_s, "numeric"))

    elsif (self.keybindings.kind_of?(NocaseHash))
    # Dictionary of keybindings
        kbs = []
        self.keybindings.to_a.each do |kb|
            # Keybindings can be integers, booleans, strings or
            # value references.                
            if (kb[1].methods.include?("tocimxml"))
                kbs << KEYBINDING.new(kb[0], VALUE_REFERENCE.new(kb[1].tocimxml()))
                next
            end
            
            if (kb[1].kind_of?(Integer) or kb[1].kind_of?(CIMInt))
                _type = "numeric"
                value = kb[1].to_s
            elsif (kb[1] == true or kb[1] == false)
                _type = "boolean"
                if kb[1]
                    value = "TRUE"
                else
                    value = "FALSE"
                end
            elsif (kb[1].kind_of?(String )) # unicode?
                _type = "string"
                value = kb[1]
            else
                raise TypeError, "Invalid keybinding type #{kb[1]}(#{kb[1].class}) for keybinding #{kb[0]}"
            end
            
            kbs << KEYBINDING.new(kb[0], KEYVALUE.new(value, _type))
            
        end
        instancename_xml = INSTANCENAME.new(self.classname, kbs)

    else
        # Value reference
    
        return instancename_xml = INSTANCENAME.new(self.classname, self.keybindings.nil? ? nil : VALUE_REFERENCE.new(self.keybindings.tocimxml()))
    end
    # Instance name plus namespace = LOCALINSTANCEPATH

    if (self.host.nil? && !self.namespace.nil?)
        return LOCALINSTANCEPATH.new(
            LOCALNAMESPACEPATH.new(
                self.namespace.split('/').collect { |ns| NAMESPACE.new(ns)}),
                instancename_xml)
    end

    # Instance name plus host and namespace = INSTANCEPATH
    if (!self.host.nil? && !self.namespace.nil?)
        return INSTANCEPATH.new(
            NAMESPACEPATH.new(
                HOST.new(self.host),
                LOCALNAMESPACEPATH.new(
                    self.namespace.split('/').collect { |ns| NAMESPACE.new(ns)})),
            instancename_xml)
    end

    # Just a regular INSTANCENAME
    return instancename_xml
end

#valuesObject



570
571
572
# File 'lib/wbem/cim_obj.rb', line 570

def values
    return self.keybindings.values()
end