Class: PropertyElement

Inherits:
Element show all
Defined in:
lib/fxmlloader/real_elts.rb

Overview

Element representing a property

Instance Attribute Summary collapse

Attributes inherited from Element

#current, #eventHandlerAttributes, #instancePropertyAttributes, #lineNumber, #loadListener, #parent, #parentLoader, #staticPropertyAttributes, #staticPropertyElements, #value, #valueAdapter, #xmlStreamReader

Instance Method Summary collapse

Methods inherited from Element

#addEventHandler, #applyProperty, #callz, #getProperties, #getValueAdapter, #isBidirectionalBindingExpression, #isBindingExpression, #isTyped, #populateArrayFromString, #populateListFromString, #processEventHandlerAttributes, #processInstancePropertyAttributes, #processPropertyAttribute, #processStartElement, #processValue3, #resolvePrefixedValue, #staticLoad, #updateValue, #warnDeprecatedEscapeSequence

Constructor Details

#initialize(current, xmlStreamReader, loadListener, parentLoader, name, sourceType) ⇒ PropertyElement

Returns a new instance of PropertyElement.



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/fxmlloader/real_elts.rb', line 406

def initialize(current, xmlStreamReader, loadListener, parentLoader, name,  sourceType)

  @name = nil
  @sourceType = nil
  @readOnly = nil
  super(current, xmlStreamReader, loadListener, parentLoader)
  dputs (callz) + "Property Elt"
  dputs callz + name
  dprint callz
  dp sourceType
  if (parent == nil)
    raise LoadException.new("Invalid root element.");
  end

  if (parent.value == nil)
    raise LoadException.new("Parent element does not support property elements.");
  end

  @name = name;
  @sourceType = sourceType;

  if (sourceType == nil)
    # The element represents an instance property
    if (name.start_with?(FXL::EVENT_HANDLER_PREFIX))
      raise LoadException.new("\"" + name + "\" is not a valid element name.");
    end

    parentProperties = parent.getProperties();
    if (parent.isTyped())
      dputs (callz) +"it be typed"
      @readOnly = parent.getValueAdapter().read_only?(name);
    else
      dputs (callz) +"it be chedrk"
      # If the map already defines a value for the property, assume
      # that it is read-only
      @readOnly = parentProperties.has_key?(name);
    end

    if (@readOnly)
      value = parentProperties[name]
      if (value == nil)
        raise LoadException.new("Invalid property.");
      end
      dputs (callz) +"saving property #{name} => #{value}"
      updateValue(value);
    end
    dputs (callz) +"doneish"
  else
    dputs (callz) +"ITS READ OHLY"
    # The element represents a static property
    @readOnly = false;
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



404
405
406
# File 'lib/fxmlloader/real_elts.rb', line 404

def name
  @name
end

#readOnlyObject

Returns the value of attribute readOnly.



404
405
406
# File 'lib/fxmlloader/real_elts.rb', line 404

def readOnly
  @readOnly
end

#sourceTypeObject

Returns the value of attribute sourceType.



404
405
406
# File 'lib/fxmlloader/real_elts.rb', line 404

def sourceType
  @sourceType
end

Instance Method Details

#add(element) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/fxmlloader/real_elts.rb', line 464

def add( element)
  dputs ( callz) +"Adding #{element} to ===> #{name}"
  dprint callz
  dp element
  dp element.class
  dp element.java_class
  if element.class.inspect == "Java::JavaNet::URL"
    # element = element.java_object
  end
  # Coerce the element to the list item type
  if (parent.isTyped())
    listType = parent.getValueAdapter().getGenericType(name);
    dputs callz + "Typed and list type is #{listType}"
    lit = RubyWrapperBeanAdapter.getListItemType(listType)
# FIXME: HACK!
  if element.class.inspect == "Java::JavaNet::URL"
    lit = Java::java.lang.String.java_class
  end

    element = RubyWrapperBeanAdapter.coerce(element, lit);
  end

  # Add the item to the list
  super(element);
end

#isCollectionObject



460
461
462
# File 'lib/fxmlloader/real_elts.rb', line 460

def isCollection()
  return (@readOnly) ? super() : false;
end

#processAttribute(prefix, localName, value) ⇒ Object



509
510
511
512
513
514
515
516
# File 'lib/fxmlloader/real_elts.rb', line 509

def processAttribute( prefix,  localName,  value)
dputs (callz) +"processing #{prefix}, #{localName}, #{value} for #{name}"
  if (!readOnly)
    raise LoadException.new("Attributes are not supported for writable property elements.");
  end

  super(prefix, localName, value);
end

#processCharactersObject



527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/fxmlloader/real_elts.rb', line 527

def processCharacters()
  if (!readOnly)
    text = xmlStreamReader.getText();
    dputs (callz) +"whitlespa"
    #TODO: normal regexes
    text = extraneousWhitespacePattern.matcher(text).replaceAll(" ");

    set(text.strip());
  else
    super();
  end
end

#processEndElementObject



518
519
520
521
522
523
524
525
# File 'lib/fxmlloader/real_elts.rb', line 518

def processEndElement()
  super();
dputs (callz) +"ENDENDLT "
  if (readOnly)
    processInstancePropertyAttributes();
    processEventHandlerAttributes();
  end
end

#set(value) ⇒ Object



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/fxmlloader/real_elts.rb', line 490

def set( value)
  dputs (callz) +"setting prope value #{name} ==> #{value}"
  # Update the value
  updateValue(value);

  if (sourceType == nil)
    # Apply value to parent element's properties
    parent.getProperties[name] = value
  else
    if (parent.value.is_a? Builder)
      # Defer evaluation of the property
      parent.staticPropertyElements.add(self);
    else
      # Apply the static property value
      RubyWrapperBeanAdapter.put3(parent.value, sourceType, name, value);
    end
  end
end