Class: InstanceDeclarationElement

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

Instance Attribute Summary collapse

Attributes inherited from ValueElement

#fx_id

Attributes inherited from Element

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

Instance Method Summary collapse

Methods inherited from ValueElement

#getListValue, #processCharacters, #processEndElement, #processStartElement, #processValue

Methods inherited from Element

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

Constructor Details

#initialize(current, xmlStreamReader, loadListener, parentLoader, type) ⇒ InstanceDeclarationElement

Returns a new instance of InstanceDeclarationElement.



4
5
6
7
8
9
10
# File 'lib/fxmlloader/real_elts.rb', line 4

def initialize(current, xmlStreamReader, loadListener, parentLoader, type)
  super(current, xmlStreamReader, loadListener, parentLoader)
  dputs "new instances! #{type}"
  @type = type;
  @constant = nil;
  @factory = nil;
end

Instance Attribute Details

#constantObject

Returns the value of attribute constant.



2
3
4
# File 'lib/fxmlloader/real_elts.rb', line 2

def constant
  @constant
end

#factoryObject

Returns the value of attribute factory.



2
3
4
# File 'lib/fxmlloader/real_elts.rb', line 2

def factory
  @factory
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/fxmlloader/real_elts.rb', line 2

def type
  @type
end

Instance Method Details

#constructValueObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fxmlloader/real_elts.rb', line 31

def constructValue()
  value = nil
  dputs callz  + "building new object when #{@value.inspect}, #{constant.inspect}, #{factory.inspect}"
  if (@value != nil)
    value = RubyWrapperBeanAdapter.coerce(@value, type);
  elsif (constant != nil)
    value = RubyWrapperBeanAdapter.getConstantValue(type, constant);
  elsif (factory != nil)
    factoryMethod = nil
    begin
      factoryMethod = MethodUtil.getMethod(type, factory, []);
    rescue NoSuchMethodException => exception
      raise LoadException.new(exception);
    end

    begin
      value = MethodUtil.invoke(factoryMethod, nil, []);
    rescue IllegalAccessException => exception
      raise LoadException.new(exception);
    rescue InvocationTargetException => exception
      raise LoadException.new(exception);
    end
  else
    value = (parentLoader.builderFactory == nil) ? nil : parentLoader.builderFactory.getBuilder(type);
    dputs callz + "now using #{value.class}"
    if (value.is_a? Builder or (value.respond_to?(:java_object) && value.java_object.is_a?(Builder)))
      begin
        value.size
      rescue java.lang.UnsupportedOperationException => ex
     dputs "########################## WARNING #############################3"
     value.class.__persistent__ = true # TODO: JRuby warning
      class << value
        def size
          dputs caller
          dputs "size waz called!"
          6
        end
        def [](x)
          get(x)
        end
        def []=(x,y)
          put(x,y)
        end
        def has_key?(x)
          containsKey(x)
        end
        def to_s
          "something interesting...."
        end
        def inspect
          "something equally interesting...."
        end
      end
    end
    end
    if (value == nil)
      begin
        dputs callz + "attemping it (#{type} => #{type.inspect})"
        #TODO: does this work?
        value = type.ruby_class.new
        dputs callz + "got taaatempt"
        dprint callz
        dp value
      rescue InstantiationException => exception
        raise LoadException.new(exception);
      rescue IllegalAccessException => exception
        raise LoadException.new(exception);
      end
    else

      dputs value.size
      dputs callz + "parent loader is #{parentLoader.builderFactory} and got #{value} for #{type} (#{value.inspect} #{type.inspect}, #{parentLoader.builderFactory.inspect})"
    end
  end

  return value;
end

#processAttribute(prefix, localName, value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fxmlloader/real_elts.rb', line 12

def processAttribute( prefix,  localName,  value)
  dputs callz + "Processing #{prefix} for #{localName} on #{type} value: #{value}"
  if (prefix != nil				&& prefix == (FXL::FX_NAMESPACE_PREFIX))
    if (localName == (FXL::FX_VALUE_ATTRIBUTE))
      @value = value;
    elsif (localName == (FXL::FX_CONSTANT_ATTRIBUTE))
      @constant = value;
    elsif (localName == (FXL::FX_FACTORY_ATTRIBUTE))
      @factory = value;
    else
      dputs callz + "SUPER!"
      super(prefix, localName, value);
    end
  else
      dputs callz + "SUPER2!"
    super(prefix, localName, value);
  end
end