jrubyfx-fxmlloader 0.2-java → 0.3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,36 +23,18 @@
23
23
  # * questions.
24
24
  # */
25
25
 
26
- #package com.sun.javafx.fxml.expression;
27
- #
28
- #import java.util.ArrayList;
29
- #import java.util.Iterator;
30
- #import java.util.List;
31
- #
32
- #import javafx.beans.InvalidationListener;
33
- #import javafx.beans.property.ReadOnlyProperty;
34
- #import javafx.beans.value.ChangeListener;
35
- #import javafx.beans.value.ObservableValue;
36
- #import javafx.beans.value.ObservableValueBase;
37
- #import javafx.collections.ListChangeListener;
38
- #import javafx.collections.MapChangeListener;
39
- #import javafx.collections.ObservableList;
40
- #import javafx.collections.ObservableMap;
41
- #
42
- #import com.sun.javafx.fxml.BeanAdapter;
43
26
 
44
27
  #/**
45
28
  # * Class representing an observable expression value.
46
29
  # */
47
30
  class RRExpressionValue < Java::javafx.beans.value.ObservableValueBase
48
31
  #// Monitors a namespace for changes along a key path
49
-
32
+
50
33
 
51
34
 
52
35
  def initialize(namespace, expression, type)
53
36
  super()
54
- dputs "Initializing with #{namespace}, #{expression}, #{type}"
55
- if (namespace == nil)
37
+ if (namespace == nil)
56
38
  raise "NullPointerException.new();"
57
39
  end
58
40
 
@@ -60,7 +42,7 @@ class RRExpressionValue < Java::javafx.beans.value.ObservableValueBase
60
42
  raise "NullPointerException.new();"
61
43
  end
62
44
 
63
- if (type == nil)
45
+ if (type == nil)
64
46
  raise "NullPointerException.new();"
65
47
  end
66
48
 
@@ -71,21 +53,20 @@ class RRExpressionValue < Java::javafx.beans.value.ObservableValueBase
71
53
  @type = type;
72
54
 
73
55
  arguments = expression.getArguments();
74
- @argumentMonitors = ArrayList.new(arguments.size());
56
+ @argumentMonitors = java.util.ArrayList.new(arguments.size());
75
57
 
76
58
  for argument in arguments
77
59
  @argumentMonitors.add(KeyPathMonitor.new(self, argument.iterator()));
78
60
  end
79
61
  end
80
62
 
81
-
63
+
82
64
  def getValue()
83
- dputs "gettng 8ev for #{self} on #{@expression}"
84
65
  return RubyWrapperBeanAdapter.coerce(@expression.evaluate(@namespace), @type);
85
66
  end
86
67
 
87
- def addListener( listener)
88
- if (@listenerCount == 0)
68
+ def addListener( listener)
69
+ if (@listenerCount == 0)
89
70
  monitorArguments();
90
71
  end
91
72
 
@@ -93,90 +74,152 @@ class RRExpressionValue < Java::javafx.beans.value.ObservableValueBase
93
74
  @listenerCount += 1
94
75
  end
95
76
 
96
- def removeListener( listener)
77
+ def removeListener( listener)
97
78
  super(listener);
98
79
  @listenerCount-=1
99
80
 
100
- if (@listenerCount == 0)
81
+ if (@listenerCount == 0)
101
82
  unmonitorArguments();
102
83
  end
103
84
  end
104
85
 
105
- def monitorArguments()
86
+ def monitorArguments()
106
87
  for argumentMonitor in @argumentMonitors
107
88
  argumentMonitor.monitor(@namespace);
108
89
  end
109
90
  end
110
91
 
111
- def unmonitorArguments()
92
+ def unmonitorArguments()
112
93
  for argumentMonitor in @argumentMonitors
113
94
  argumentMonitor.unmonitor();
114
95
  end
115
96
  end
116
97
  end
117
98
 
118
-
119
- class KeyPathMonitor
99
+
100
+ class KeyPathMonitor
120
101
  @key = nil;
121
102
  @next = nil
122
103
 
123
104
  @namespace = nil;
124
105
 
125
-
126
106
 
127
- def initialize(this, keyPathIterator)
107
+ class ListChangeImpl
108
+ include ListChangeListener
109
+
110
+ def initialize(this)
111
+ @this = this
112
+ end
113
+
114
+ def onChanged(change)
115
+ @this.list_changed(change)
116
+ end
117
+ end
118
+
119
+
120
+ class MapChangeImpl
121
+ include MapChangeListener
122
+
123
+ def initialize(this)
124
+ @this = this
125
+ end
126
+
127
+ def onChanged(change)
128
+ @this.map_changed(change)
129
+ end
130
+ end
131
+
132
+
133
+
134
+ class ChangeListenerImpl
135
+ include ChangeListener
136
+
137
+ def initialize(this)
138
+ @this = this
139
+ end
140
+
141
+ def changed(ov, old, new)
142
+ @this.normal_changed(ov, old, new)
143
+ end
144
+ end
145
+
146
+ def initialize(this, keyPathIterator)
128
147
  @key = keyPathIterator.next();
129
148
  @this = this
130
-
131
-
132
- @listChangeListener = ListChangeListener.impl do |name, change|
133
- while (@change.next())
134
- index = @key.to_i
135
-
136
- if (index >= change.getFrom() && index < change.getTo())
137
- @this.fireValueChangedEvent();
138
- remonitor();
139
- end
140
- end
149
+
150
+
151
+ @listChangeListener = ListChangeImpl.new(self)
152
+
153
+
154
+ @mapChangeListener = MapChangeImpl.new(self)
155
+
156
+
157
+ @propertyChangeListener = ChangeListenerImpl.new(self)
158
+
159
+ if (keyPathIterator.hasNext())
160
+ @next = KeyPathMonitor.new(this, keyPathIterator);
161
+ else
162
+ @next = nil;
141
163
  end
142
-
164
+ end
143
165
 
144
- @mapChangeListener = MapChangeListener.impl do |name, change|
145
- if (@key == (change.getKey()))
166
+ def list_changed(change)
167
+ while (change.next())
168
+ index = @key.to_i
169
+
170
+ if (index >= change.getFrom() && index < change.getTo())
146
171
  @this.fireValueChangedEvent();
147
172
  remonitor();
148
173
  end
149
174
  end
150
-
175
+ end
151
176
 
152
- @propertyChangeListener = ChangeListener.impl do |name, observable, oldValue, newValue|
153
- dputs "Normal property changed #{name}, #{observable}, #{oldValue}, #{newValue} for #{@key}"
154
- if (@key == (observable.getName()))
155
- dputs "FIRE!"
156
-
157
- @this.fireValueChangedEvent();
158
- remonitor();
159
- end
177
+ def map_changed(change)
178
+ if (@key == (change.getKey()))
179
+ @this.fireValueChangedEvent();
180
+ remonitor();
160
181
  end
182
+ end
161
183
 
162
- if (keyPathIterator.hasNext())
163
- @next = KeyPathMonitor.new(this, keyPathIterator);
164
- else
165
- @next = nil;
184
+ def normal_changed(observable, oldValue, newValue)
185
+ if (@key == (observable.getName()))
186
+
187
+ @this.fireValueChangedEvent();
188
+ remonitor();
166
189
  end
167
190
  end
168
191
 
169
- def monitor(namespace)
170
- if (namespace.is_a? ObservableList)
171
- namespace.java_send :addListener, [Java::javafx.collections.ListChangeListener.java_class],@listChangeListener
172
- elsif (namespace.is_a? ObservableMap)
173
- namespace.java_send :addListener, [Java::javafx.collections.MapChangeListener.java_class], @mapChangeListener
174
- else
192
+ def monitor(namespace)
193
+ if (namespace.is_a? ObservableList)
194
+ old_verbose = $VERBOSE
195
+ begin
196
+ $VERBOSE = nil
197
+ namespace.addListener @listChangeListener
198
+ ensure
199
+ # always re-set to old value, even if block raises an exception
200
+ $VERBOSE = old_verbose
201
+ end
202
+ elsif (namespace.is_a? ObservableMap)
203
+ old_verbose = $VERBOSE
204
+ begin
205
+ $VERBOSE = nil
206
+ namespace.addListener @mapChangeListener
207
+ ensure
208
+ # always re-set to old value, even if block raises an exception
209
+ $VERBOSE = old_verbose
210
+ end
211
+ else
175
212
  namespaceAdapter = RubyWrapperBeanAdapter.for(namespace);
176
213
  propertyModel = namespaceAdapter.getPropertyModel(@key).to_java
177
- dputs "properyt model is now #{propertyModel}"
178
- if (propertyModel != nil)
179
- propertyModel.java_send :addListener, [Java::javafx.beans.value.ChangeListener.java_class], @propertyChangeListener
214
+ if (propertyModel != nil)
215
+ old_verbose = $VERBOSE
216
+ begin
217
+ $VERBOSE = nil
218
+ propertyModel.addListener @propertyChangeListener
219
+ ensure
220
+ # always re-set to old value, even if block raises an exception
221
+ $VERBOSE = old_verbose
222
+ end
180
223
  end
181
224
 
182
225
  @namespace = namespaceAdapter;
@@ -184,60 +227,64 @@ class KeyPathMonitor
184
227
 
185
228
  @namespace = namespace;
186
229
 
187
- if (@next != nil)
230
+ if (@next != nil)
188
231
  value = Expression.get(@namespace, @key)
189
- if (value != nil)
232
+ if (value != nil)
190
233
  @next.monitor(value);
191
234
  end
192
235
  end
193
236
  end
194
237
 
195
- def unmonitor()
196
- if (@namespace.is_a? ObservableList)
197
- @namespace.java_send :removeListener, [Java::javafx.collections.ListChangeListener.java_class], @listChangeListener
198
- elsif (@namespace.is_a? ObservableMap)
199
- @namespace.java_send :removeListener, [Java::javafx.collections.MapChangeListener.java_class], @mapChangeListener
200
- elsif (@namespace != nil)
238
+ def unmonitor()
239
+ if (@namespace.is_a? ObservableList)
240
+ old_verbose = $VERBOSE
241
+ begin
242
+ $VERBOSE = nil
243
+ @namespace.removeListener @listChangeListener
244
+ ensure
245
+ # always re-set to old value, even if block raises an exception
246
+ $VERBOSE = old_verbose
247
+ end
248
+ elsif (@namespace.is_a? ObservableMap)
249
+ old_verbose = $VERBOSE
250
+ begin
251
+ $VERBOSE = nil
252
+ @namespace.removeListener @mapChangeListener
253
+ ensure
254
+ # always re-set to old value, even if block raises an exception
255
+ $VERBOSE = old_verbose
256
+ end
257
+ elsif (@namespace != nil)
201
258
  namespaceAdapter = @namespace;
202
259
  propertyModel = namespaceAdapter.getPropertyModel(@key);
203
260
 
204
- if (propertyModel != nil)
205
- propertyModel.java_send :removeListener, [Java::javafx.beans.value.ChangeListener.java_class], @propertyChangeListener
261
+ if (propertyModel != nil)
262
+ old_verbose = $VERBOSE
263
+ begin
264
+ $VERBOSE = nil
265
+ propertyModel.removeListener @propertyChangeListener
266
+ ensure
267
+ # always re-set to old value, even if block raises an exception
268
+ $VERBOSE = old_verbose
269
+ end
206
270
  end
207
271
  end
208
272
 
209
273
  @namespace = nil;
210
274
 
211
- if (@next != nil)
275
+ if (@next != nil)
212
276
  @next.unmonitor();
213
277
  end
214
278
  end
215
279
 
216
- def remonitor()
217
- if (@next != nil)
280
+ def remonitor()
281
+ if (@next != nil)
218
282
  @next.unmonitor();
219
283
  value = Expression.get(@namespace, @key);
220
- if (value != nil)
284
+ if (value != nil)
221
285
  @next.monitor(value);
222
286
  end
223
287
  end
224
288
  end
225
289
  end
226
290
 
227
- #class JRExpressionTargetMapping < ChangeListener
228
- #
229
- # def initialize(paramExpression, paramObject, paramList)
230
- #
231
- # @source = paramExpression;
232
- # @target = paramObject;
233
- # @path = paramList;
234
- # end
235
- #
236
- # def changed(ov, ol, ne)
237
- #
238
- # if (@source.isDefined())
239
- # Expression.set(@target, @path, @source.getValue());
240
- # end
241
- # end
242
- #end
243
-
@@ -1,16 +1,67 @@
1
+ class OBJFXBuilderWrapper < Java::java.util.AbstractMap
2
+ include Java::javafx.util.Builder
3
+ def initialize(safeobj, type)
4
+ super()
5
+ @type = type
6
+ @obj = safeobj
7
+ end
8
+
9
+ def wrapped_class
10
+ @type
11
+ end
12
+
13
+ def on_put(&on_put)
14
+ @on_put = on_put
15
+ end
16
+
17
+ def build
18
+ @obj.build.tap{|x| rmorph self, x}
19
+ end
20
+
21
+ def containsKey(o)
22
+ @obj.containsKey(o)
23
+ end
24
+
25
+ def get(o)
26
+ @obj.get(o)
27
+ end
28
+
29
+ def put(k, v)
30
+ @on_put.call(k, v) if @on_put
31
+ @obj.put(k, v)
32
+ end
33
+
34
+ def [](o)
35
+ get(o)
36
+ end
37
+ def []=(k, v)
38
+ put(k, v)
39
+ end
40
+
41
+ def entrySet
42
+ java.util.HashMap.new({}).entrySet
43
+ end
44
+
45
+ def ==(rhs)
46
+ self.equal? rhs # do pointer comparison
47
+ end
48
+
49
+ def inspect
50
+ "#<ObjectBuilderWrapper:#{self.object_id.to_s 16} type=#{@type}, child=#{@obj.class.inspect}>"
51
+ end
52
+ end
53
+
1
54
  class InstanceDeclarationElement < ValueElement
2
55
  attr_accessor :type, :constant, :factory
3
56
 
4
57
  def initialize(current, xmlStreamReader, loadListener, parentLoader, type)
5
58
  super(current, xmlStreamReader, loadListener, parentLoader)
6
- dputs "new instances! #{type}"
7
59
  @type = type;
8
60
  @constant = nil;
9
61
  @factory = nil;
10
62
  end
11
63
 
12
64
  def processAttribute( prefix, localName, value)
13
- dputs callz + "Processing #{prefix} for #{localName} on #{type} value: #{value}"
14
65
  if (prefix != nil && prefix == (FXL::FX_NAMESPACE_PREFIX))
15
66
  if (localName == (FXL::FX_VALUE_ATTRIBUTE))
16
67
  @value = value;
@@ -19,18 +70,15 @@ class InstanceDeclarationElement < ValueElement
19
70
  elsif (localName == (FXL::FX_FACTORY_ATTRIBUTE))
20
71
  @factory = value;
21
72
  else
22
- dputs callz + "SUPER!"
23
73
  super(prefix, localName, value);
24
74
  end
25
75
  else
26
- dputs callz + "SUPER2!"
27
76
  super(prefix, localName, value);
28
77
  end
29
78
  end
30
79
 
31
80
  def constructValue()
32
81
  value = nil
33
- dputs callz + "building new object when #{@value.inspect}, #{constant.inspect}, #{factory.inspect}"
34
82
  if (@value != nil)
35
83
  value = RubyWrapperBeanAdapter.coerce(@value, type);
36
84
  elsif (constant != nil)
@@ -52,57 +100,36 @@ class InstanceDeclarationElement < ValueElement
52
100
  end
53
101
  else
54
102
  value = (parentLoader.builderFactory == nil) ? nil : parentLoader.builderFactory.getBuilder(type);
55
- dputs callz + "now using #{value.class}"
56
103
  if (value.is_a? Builder or (value.respond_to?(:java_object) && value.java_object.is_a?(Builder)))
57
104
  begin
58
105
  value.size
59
106
  rescue java.lang.UnsupportedOperationException => ex
60
- dputs "########################## WARNING #############################3"
61
- value.class.__persistent__ = true # TODO: JRuby warning
62
- class << value
63
- def size
64
- dputs caller
65
- dputs "size waz called!"
66
- 6
67
- end
68
- def [](x)
69
- get(x)
70
- end
71
- def []=(x,y)
72
- put(x,y)
73
- end
74
- def has_key?(x)
75
- containsKey(x)
76
- end
77
- def to_s
78
- "something interesting...."
79
- end
80
- def inspect
81
- "something equally interesting...."
82
- end
107
+ dputs "########################## WARNING #############################3"
108
+ value = OBJFXBuilderWrapper.new(value, type)
109
+ value.on_put {|k, v| rctor value, k, v }
83
110
  end
84
111
  end
85
- end
86
112
  if (value == nil)
87
113
  begin
88
- dputs callz + "attemping it (#{type} => #{type.inspect})"
89
114
  #TODO: does this work?
90
115
  value = type.ruby_class.new
91
- dputs callz + "got taaatempt"
92
- dprint callz
93
- dp value
94
116
  rescue InstantiationException => exception
95
117
  raise LoadException.new(exception);
96
118
  rescue IllegalAccessException => exception
97
119
  raise LoadException.new(exception);
98
120
  end
99
121
  else
100
-
101
- dputs value.size
102
- dputs callz + "parent loader is #{parentLoader.builderFactory} and got #{value} for #{type} (#{value.inspect} #{type.inspect}, #{parentLoader.builderFactory.inspect})"
103
- end
122
+ end
104
123
  end
105
-
124
+ if factory
125
+ rputs value, "build(FactoryBuilderBuilder, #{type.ruby_class}, #{factory.inspect}) do"
126
+ elsif @value
127
+ rno_show(value)
128
+ rputs value, value.inspect
129
+ else
130
+ rputs value, "build(#{type.ruby_class}) do"
131
+ end
132
+ rnest 1
106
133
  return value;
107
134
  end
108
135
  end
@@ -257,14 +284,11 @@ class ReferenceElement < ValueElement
257
284
  @source = nil;
258
285
 
259
286
  def processAttribute(prefix, localName, value)
260
- dputs callz + "processing attrib"
261
- dp prefix, localName, value
262
287
  if (prefix == nil)
263
288
  if (localName == (FXL::REFERENCE_SOURCE_ATTRIBUTE))
264
289
  if (loadListener != nil)
265
290
  loadListener.readInternalAttribute(localName, value);
266
291
  end
267
- dputs callz + "SAVING SOURCES"
268
292
  @source = value;
269
293
  else
270
294
  super(prefix, localName, value);
@@ -386,7 +410,12 @@ class RootElement < ValueElement
386
410
  value=nil
387
411
  root = parentLoader.root
388
412
  if (root == nil)
389
- raise LoadException.new("Root hasn't been set. Use method setRoot() before load.");
413
+ if $JRUBYFX_AOT_COMPILING
414
+ root = parentLoader.root = type.ruby_class.new
415
+ value = root
416
+ else
417
+ raise LoadException.new("Root hasn't been set. Use method setRoot() before load.");
418
+ end
390
419
  else
391
420
  if (!type.isAssignableFrom(root.java_class()))
392
421
  raise LoadException.new("Root is not an instance of " + type.getName() + ".");
@@ -394,7 +423,8 @@ class RootElement < ValueElement
394
423
 
395
424
  value = root;
396
425
  end
397
-
426
+ rputs value, "with(__local_fxml_controller) do"
427
+ rnest 1
398
428
  return value;
399
429
  end
400
430
  end
@@ -409,10 +439,6 @@ class PropertyElement < Element
409
439
  @sourceType = nil
410
440
  @readOnly = nil
411
441
  super(current, xmlStreamReader, loadListener, parentLoader)
412
- dputs (callz) + "Property Elt"
413
- dputs callz + name
414
- dprint callz
415
- dp sourceType
416
442
  if (parent == nil)
417
443
  raise LoadException.new("Invalid root element.");
418
444
  end
@@ -432,10 +458,8 @@ class PropertyElement < Element
432
458
 
433
459
  parentProperties = parent.getProperties();
434
460
  if (parent.isTyped())
435
- dputs (callz) +"it be typed"
436
461
  @readOnly = parent.getValueAdapter().read_only?(name);
437
462
  else
438
- dputs (callz) +"it be chedrk"
439
463
  # If the map already defines a value for the property, assume
440
464
  # that it is read-only
441
465
  @readOnly = parentProperties.has_key?(name);
@@ -446,12 +470,9 @@ class PropertyElement < Element
446
470
  if (value == nil)
447
471
  raise LoadException.new("Invalid property.");
448
472
  end
449
- dputs (callz) +"saving property #{name} => #{value}"
450
473
  updateValue(value);
451
474
  end
452
- dputs (callz) +"doneish"
453
475
  else
454
- dputs (callz) +"ITS READ OHLY"
455
476
  # The element represents a static property
456
477
  @readOnly = false;
457
478
  end
@@ -462,33 +483,26 @@ class PropertyElement < Element
462
483
  end
463
484
 
464
485
  def add( element)
465
- dputs ( callz) +"Adding #{element} to ===> #{name}"
466
- dprint callz
467
- dp element
468
- dp element.class
469
- dp element.java_class
470
- if element.class.inspect == "Java::JavaNet::URL"
471
- # element = element.java_object
472
- end
486
+ @pushd = true
487
+ rp = nil
473
488
  # Coerce the element to the list item type
474
489
  if (parent.isTyped())
475
490
  listType = parent.getValueAdapter().getGenericType(name);
476
- dputs callz + "Typed and list type is #{listType}"
477
491
  lit = RubyWrapperBeanAdapter.getListItemType(listType)
478
- # FIXME: HACK!
479
- if element.class.inspect == "Java::JavaNet::URL"
480
- lit = Java::java.lang.String.java_class
481
- end
482
-
492
+ # FIXME: HACK!
493
+ if element.class.inspect == "Java::JavaNet::URL"
494
+ lit = Java::java.lang.String.java_class
495
+ rp = rget(element).match(/build\(FxmlBuilderBuilder, \{"value"=>(.*)\}, Java::JavaNet::URL\) do\n( )*end/)[1]
496
+ end
483
497
  element = RubyWrapperBeanAdapter.coerce(element, lit);
484
498
  end
485
499
 
486
500
  # Add the item to the list
487
- super(element);
501
+ super(element, name, rp);
488
502
  end
489
503
 
490
504
  def set( value)
491
- dputs (callz) +"setting prope value #{name} ==> #{value}"
505
+ @pushd = true
492
506
  # Update the value
493
507
  updateValue(value);
494
508
 
@@ -507,7 +521,6 @@ class PropertyElement < Element
507
521
  end
508
522
 
509
523
  def processAttribute( prefix, localName, value)
510
- dputs (callz) +"processing #{prefix}, #{localName}, #{value} for #{name}"
511
524
  if (!readOnly)
512
525
  raise LoadException.new("Attributes are not supported for writable property elements.");
513
526
  end
@@ -517,17 +530,18 @@ dputs (callz) +"processing #{prefix}, #{localName}, #{value} for #{name}"
517
530
 
518
531
  def processEndElement()
519
532
  super();
520
- dputs (callz) +"ENDENDLT "
521
533
  if (readOnly)
522
534
  processInstancePropertyAttributes();
523
535
  processEventHandlerAttributes();
536
+ unless @pushd
537
+ rputs parent.value, "with(get#{@name[0].upcase}#{@name[1..-1]}) do\n#{rget(@value)||@value.inspect}\nend" unless parent.value == @value
538
+ end
524
539
  end
525
540
  end
526
541
 
527
542
  def processCharacters()
528
543
  if (!readOnly)
529
544
  text = xmlStreamReader.getText();
530
- dputs (callz) +"whitlespa"
531
545
  #TODO: normal regexes
532
546
  text = extraneousWhitespacePattern.matcher(text).replaceAll(" ");
533
547
 
@@ -568,118 +582,114 @@ class UnknownStaticPropertyElement < Element
568
582
  end
569
583
 
570
584
  # Element representing a script block
571
- # class ScriptElement < Element
572
- # # TODO: fix
573
- # @source = nil;
574
- # @charset = parentLoader.charset;
575
- #
576
- # def isCollection()
577
- # return false;
578
- # end
579
-
580
- # def processStartElement()
581
- # super();
582
- #
583
- # if (source != nil && !staticLoad)
584
- # int i = source.rindex(".");
585
- # if (i == -1)
586
- # raise LoadException.new("Cannot determine type of script \"" + source + "\".");
587
- # end
588
- #
589
- # extension = source[(i + 1)..-1];
590
- # scriptEngine = nil
591
- # #TODO: use JRUBY stuff
592
- # oldLoader = Thread.currentThread().getContextClassLoader();
593
- # begin
594
- # Thread.currentThread().setContextClassLoader(classLoader);
595
- # scriptEngineManager = getScriptEngineManager();
596
- # scriptEngine = scriptEngineManager.getEngineByExtension(extension);
597
- # ensure
598
- # Thread.currentThread().setContextClassLoader(oldLoader);
599
- # end
600
- #
601
- # if (scriptEngine == nil)
602
- # raise LoadException.new("Unable to locate scripting engine for" + " extension " + extension + ".");
603
- # end
604
- #
605
- # scriptEngine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE);
606
- #
607
- # begin
608
- # location = nil
609
- # if (source[0] == '/')
610
- # location = classLoader.getResource(source[(1)..-1]);
611
- # else
612
- # if (parentLoader.location == nil)
613
- # raise LoadException.new("Base location is undefined.");
614
- # end
615
- #
616
- # location = URL.new(parentLoader.location, source);
617
- # end
618
- #
619
- # InputStreamReader scriptReader = nil;
620
- # begin
621
- # scriptReader = InputStreamReader.new(location.openStream(), charset);
622
- # scriptEngine.eval(scriptReader);
623
- # rescue ScriptException => exception
624
- # exception.printStackTrace();
625
- # end
626
- # finally
627
- # if (scriptReader != nil)
628
- # scriptReader.close();
629
- # end
630
- # end
631
- # rescue IOException => exception
632
- # raise LoadException.new(exception);
633
- # end
634
- # end
635
- # end
636
- #
637
- # def processEndElement()
638
- # super();
639
- #
640
- # if (value != nil && !staticLoad)
641
- # # Evaluate the script
642
- # begin
643
- # scriptEngine.eval((String) value);
644
- # rescue ScriptException => exception
645
- # System.err.println(exception.getMessage());
646
- # end
647
- # end
648
- # end
649
- #
650
- # def processCharacters()
651
- # if (source != nil)
652
- # raise LoadException.new("Script source already specified.");
653
- # end
654
- #
655
- # if (scriptEngine == nil && !staticLoad)
656
- # raise LoadException.new("Page language not specified.");
657
- # end
658
- #
659
- # updateValue(xmlStreamReader.getText());
660
- # end
661
- #
662
- # def processAttribute(String prefix, String localName, String value)
663
- #
664
- # if (prefix == nil
665
- # && localName == (FXL::SCRIPT_SOURCE_ATTRIBUTE))
666
- # if (loadListener != nil)
667
- # loadListener.readInternalAttribute(localName, value);
668
- # end
669
- #
670
- # source = value;
671
- # elsif (localName == (FXL::SCRIPT_CHARSET_ATTRIBUTE))
672
- # if (loadListener != nil)
673
- # loadListener.readInternalAttribute(localName, value);
674
- # end
675
- #
676
- # charset = Charset.forName(value);
677
- # else
678
- # raise LoadException.new(prefix == nil ? localName : prefix + ":" + localName
679
- # + " is not a valid attribute.");
680
- # end
681
- # end
682
- # end
585
+ class ScriptElement < Element
586
+ def initialize(current, xmlStreamReader, loadListener, parentLoader)
587
+ super
588
+ @source = nil;
589
+ @charset = parentLoader.charset;
590
+ end
591
+
592
+ def isCollection()
593
+ return false;
594
+ end
595
+
596
+ def processStartElement()
597
+ super();
598
+
599
+ if (@source != nil && !staticLoad)
600
+ i = @source.rindex(".");
601
+ if (i == nil)
602
+ raise ("Cannot determine type of script \"" + @source + "\".");
603
+ end
604
+ extension = @source[(i + 1)..-1];
605
+ scriptEngine = nil
606
+ #TODO: use JRUBY stuff
607
+ oldLoader = Thread.currentThread().getContextClassLoader();
608
+ begin
609
+ Thread.currentThread().setContextClassLoader(classLoader);
610
+ scriptEngineManager = getScriptEngineManager();
611
+ scriptEngine = scriptEngineManager.getEngineByExtension(extension);
612
+ ensure
613
+ Thread.currentThread().setContextClassLoader(oldLoader);
614
+ end
615
+
616
+ if (scriptEngine == nil)
617
+ raise ("Unable to locate scripting engine for" + " extension " + extension + ".");
618
+ end
619
+
620
+ scriptEngine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE);
621
+
622
+ begin
623
+ location = nil
624
+ if (@source[0] == '/')
625
+ location = classLoader.getResource(@source[(1)..-1]);
626
+ else
627
+ if (parentLoader.location == nil)
628
+ raise LoadException.new("Base location is undefined.");
629
+ end
630
+
631
+ location = URL.new(parentLoader.location, @source);
632
+ end
633
+
634
+ InputStreamReader scriptReader = nil;
635
+ begin
636
+ scriptReader = InputStreamReader.new(location.openStream(), @charset);
637
+ scriptEngine.eval(scriptReader);
638
+ rescue ScriptException => exception
639
+ exception.printStackTrace();
640
+ ensure
641
+ if (scriptReader != nil)
642
+ scriptReader.close();
643
+ end
644
+ end
645
+ rescue IOException => exception
646
+ raise LoadException.new(exception);
647
+ end
648
+ end
649
+ end
650
+
651
+ def processEndElement()
652
+ super();
653
+ if (value != nil && !parentLoader.staticLoad)
654
+ # Evaluate the script
655
+ begin
656
+ rputs nil, "__local_sem_lang_inst_#{rget_sem(parentLoader.scriptEngine)}.eval(#{value.to_s.inspect})"
657
+ parentLoader.scriptEngine.eval( value.to_s);
658
+ rescue ScriptException => exception
659
+ STDERR.puts (exception.getMessage());
660
+ end
661
+ end
662
+ end
663
+
664
+ def processCharacters()
665
+ if (@source != nil)
666
+ raise LoadException.new("Script source already specified.");
667
+ end
668
+
669
+ if (parentLoader.scriptEngine == nil && !parentLoader.staticLoad)
670
+ raise LoadException.new("Page language not specified.");
671
+ end
672
+ updateValue(xmlStreamReader.getText());
673
+ end
674
+
675
+ def processAttribute(prefix, localName, value)
676
+ if (prefix == nil && localName == (FXL::SCRIPT_SOURCE_ATTRIBUTE))
677
+ if (loadListener != nil)
678
+ loadListener.readInternalAttribute(localName, value);
679
+ end
680
+
681
+ @source = value;
682
+ elsif (localName == (FXL::SCRIPT_CHARSET_ATTRIBUTE))
683
+ if (loadListener != nil)
684
+ loadListener.readInternalAttribute(localName, value);
685
+ end
686
+
687
+ @charset = Charset.forName(value);
688
+ else
689
+ raise LoadException.new(prefix == nil ? localName : prefix + ":" + localName + " is not a valid attribute.");
690
+ end
691
+ end
692
+ end
683
693
 
684
694
  # Element representing a define block
685
695
  class DefineElement < Element
@@ -688,6 +698,7 @@ class DefineElement < Element
688
698
  end
689
699
 
690
700
  def add(element)
701
+ rputs parent.value, rget(element)
691
702
  # No-op
692
703
  end
693
704