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.


436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/fxmlloader/real_elts.rb', line 436

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

  @name = nil
  @sourceType = nil
  @readOnly = nil
  super(current, xmlStreamReader, loadListener, parentLoader)
  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())
      @readOnly = parent.getValueAdapter().read_only?(name);
    else
      # 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
      updateValue(value);
    end
  else
    # The element represents a static property
    @readOnly = false;
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


434
435
436
# File 'lib/fxmlloader/real_elts.rb', line 434

def name
  @name
end

#readOnlyObject

Returns the value of attribute readOnly


434
435
436
# File 'lib/fxmlloader/real_elts.rb', line 434

def readOnly
  @readOnly
end

#sourceTypeObject

Returns the value of attribute sourceType


434
435
436
# File 'lib/fxmlloader/real_elts.rb', line 434

def sourceType
  @sourceType
end

Instance Method Details

#add(element) ⇒ Object


485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/fxmlloader/real_elts.rb', line 485

def add( element)
  @pushd = true
  rp = nil
  # Coerce the element to the list item type
  if (parent.isTyped())
    listType = parent.getValueAdapter().getGenericType(name);
    lit = RubyWrapperBeanAdapter.getListItemType(listType)
    # FIXME: HACK!
    if element.class.inspect == "Java::JavaNet::URL"
      lit = Java::java.lang.String.java_class
      rp = rget(element).match(/build\(FxmlBuilderBuilder, \{"value"=>(.*)\}, Java::JavaNet::URL\) do\n( )*end/)[1]
    end
    element = RubyWrapperBeanAdapter.coerce(element, lit);
  end

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

#isCollectionObject


481
482
483
# File 'lib/fxmlloader/real_elts.rb', line 481

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

#processAttribute(prefix, localName, value) ⇒ Object


523
524
525
526
527
528
529
# File 'lib/fxmlloader/real_elts.rb', line 523

def processAttribute( prefix,  localName,  value)
  if (!readOnly)
    raise LoadException.new("Attributes are not supported for writable property elements.");
  end

  super(prefix, localName, value);
end

#processCharactersObject


542
543
544
545
546
547
548
549
550
551
552
# File 'lib/fxmlloader/real_elts.rb', line 542

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

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

#processEndElementObject


531
532
533
534
535
536
537
538
539
540
# File 'lib/fxmlloader/real_elts.rb', line 531

def processEndElement()
  super();
  if (readOnly)
    processInstancePropertyAttributes();
    processEventHandlerAttributes();
    unless @pushd
      rputs parent.value, "with(get#{@name[0].upcase}#{@name[1..-1]}) do\n#{rget(@value)||@value.inspect}\nend" unless parent.value == @value
    end
  end
end

#set(value) ⇒ Object


504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/fxmlloader/real_elts.rb', line 504

def set( value)
  @pushd = true
  # 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