jrubyfx-fxmlloader 0.2-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.
- data/LICENSE +25 -0
- data/README +5 -0
- data/Rakefile +71 -0
- data/lib/FXMLLoader-j8.jar +0 -0
- data/lib/fxmlloader/elts.rb +564 -0
- data/lib/fxmlloader/j8_expression_value.rb +243 -0
- data/lib/fxmlloader/real_elts.rb +697 -0
- data/lib/fxmlloader/rorba.rb +133 -0
- data/lib/fxmlloader/rrba.rb +1007 -0
- data/lib/fxmlloader/value_elts.rb +267 -0
- data/lib/jrubyfx-fxmlloader.rb +724 -0
- metadata +57 -0
@@ -0,0 +1,267 @@
|
|
1
|
+
require_relative './elts'
|
2
|
+
|
3
|
+
class StupidFixTODOInsets < Java::javafx::geometry::InsetsBuilder
|
4
|
+
def initialize()
|
5
|
+
super
|
6
|
+
end
|
7
|
+
add_method_signature :getLeft, [Java::double]
|
8
|
+
def getLeft()
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
add_method_signature :setLeft, [Java::java.lang.Void, Java::double]
|
13
|
+
def setLeft(value)
|
14
|
+
left(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
add_method_signature :getRight, [Java::double]
|
18
|
+
def getRight()
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
add_method_signature :setRight, [Java::java.lang.Void, Java::double]
|
23
|
+
def setRight(value)
|
24
|
+
right(value)
|
25
|
+
end
|
26
|
+
add_method_signature :getBottom, [Java::double]
|
27
|
+
def getBottom()
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
add_method_signature :setBottom, [Java::java.lang.Void, Java::double]
|
32
|
+
def setBottom(value)
|
33
|
+
bottom(value)
|
34
|
+
end
|
35
|
+
add_method_signature :getTop, [Java::double]
|
36
|
+
def getTop()
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
add_method_signature :setTop, [Java::java.lang.Void, Java::double]
|
41
|
+
def setTop(value)
|
42
|
+
top(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
dputs "GAAAAAAAAAAAAAA!!!!!"
|
47
|
+
dputs caller
|
48
|
+
990
|
49
|
+
end
|
50
|
+
def to_s
|
51
|
+
"the thingabmabomb"
|
52
|
+
end
|
53
|
+
def inspect
|
54
|
+
"whozamawhatzit"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class ValueElement < Element
|
59
|
+
attr_accessor :fx_id
|
60
|
+
@fx_id = nil;
|
61
|
+
def processStartElement
|
62
|
+
super
|
63
|
+
|
64
|
+
updateValue(constructValue());
|
65
|
+
|
66
|
+
if (value.is_a? Builder)
|
67
|
+
processInstancePropertyAttributes();
|
68
|
+
else
|
69
|
+
processValue();
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def processEndElement()
|
74
|
+
dputs callz + "process end super?"
|
75
|
+
super
|
76
|
+
dputs callz + "process end superd!"
|
77
|
+
dp value
|
78
|
+
|
79
|
+
# Build the value, if necessary
|
80
|
+
if (value.is_a? Builder)
|
81
|
+
dputs "build it"
|
82
|
+
updateValue(value.build());
|
83
|
+
dputs "process it"
|
84
|
+
processValue();
|
85
|
+
else
|
86
|
+
processInstancePropertyAttributes();
|
87
|
+
end
|
88
|
+
dputs "donet"
|
89
|
+
processEventHandlerAttributes();
|
90
|
+
dputs "ahndersAtrrs"
|
91
|
+
# Process static property attributes
|
92
|
+
if (staticPropertyAttributes.length > 0)
|
93
|
+
for attribute in staticPropertyAttributes
|
94
|
+
dputs "process prodp attr-----------"
|
95
|
+
dp attribute
|
96
|
+
processPropertyAttribute(attribute);
|
97
|
+
end
|
98
|
+
end
|
99
|
+
dputs "staticpro"
|
100
|
+
# Process static property elements
|
101
|
+
if (staticPropertyElements.length > 0)
|
102
|
+
for element in staticPropertyElements
|
103
|
+
RubyWrapperBeanAdapter.put(value, element.sourceType, element.name, element.value);
|
104
|
+
end
|
105
|
+
end
|
106
|
+
dputs "parentS>AS"
|
107
|
+
if (parent != nil)
|
108
|
+
if (parent.isCollection())
|
109
|
+
parent.add(value);
|
110
|
+
else
|
111
|
+
dputs callz + " ANd setting #{value} on #{parent}"
|
112
|
+
parent.set value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def getListValue( parent, listPropertyName, value)
|
118
|
+
# If possible, coerce the value to the list item type
|
119
|
+
if (parent.isTyped())
|
120
|
+
listType = parent.getValueAdapter().getGenericType(listPropertyName);
|
121
|
+
|
122
|
+
if (listType != nil)
|
123
|
+
itemType = RubyWrapperBeanAdapter.getGenericListItemType(listType);
|
124
|
+
|
125
|
+
if (itemType.is_a? ParameterizedType)
|
126
|
+
itemType = (itemType).getRawType();
|
127
|
+
end
|
128
|
+
|
129
|
+
value = RubyWrapperBeanAdapter.coerce(value,itemType);
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
return value;
|
134
|
+
end
|
135
|
+
|
136
|
+
def processValue()
|
137
|
+
# If this is the root element, update the value
|
138
|
+
if (parent == nil)
|
139
|
+
root = value;
|
140
|
+
|
141
|
+
# checking version of fx namespace - throw exception if not supported
|
142
|
+
fxNSURI = xmlStreamReader.getNamespaceContext().getNamespaceURI("fx");
|
143
|
+
if (fxNSURI != nil)
|
144
|
+
fxVersion = fxNSURI[(fxNSURI.rindex("/") + 1)..-1];
|
145
|
+
if (parentLoader.compareJFXVersions(FxmlLoader::FX_NAMESPACE_VERSION, fxVersion) < 0)
|
146
|
+
raise LoadException.new("Loading FXML document of version " + fxVersion + " by JavaFX runtime supporting version " + FxmlLoader::FX_NAMESPACE_VERSION);
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# checking the version JavaFX API - print warning if not supported
|
151
|
+
defaultNSURI = xmlStreamReader.getNamespaceContext().getNamespaceURI("");
|
152
|
+
if (defaultNSURI != nil)
|
153
|
+
nsVersion = defaultNSURI[(defaultNSURI.lastIndexOf("/") + 1)..-1]
|
154
|
+
if (parentLoader.compareJFXVersions(FXL::JAVAFX_VERSION, nsVersion) < 0)
|
155
|
+
Logging.getJavaFXLogger().warning("Loading FXML document with JavaFX API of version " + nsVersion + " by JavaFX runtime of version " + FXL::JAVAFX_VERSION);
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Add the value to the namespace
|
161
|
+
if (@fx_id != nil)
|
162
|
+
parentLoader.namespace[@fx_id] = value
|
163
|
+
|
164
|
+
# If the value defines an ID property, set it
|
165
|
+
idProperty = value.java_class.annotation(IDProperty.java_class);
|
166
|
+
|
167
|
+
if (idProperty != nil)
|
168
|
+
properties = getProperties();
|
169
|
+
# set fx:id property value to Node.id only if Node.id was not
|
170
|
+
# already set when processing start element attributes
|
171
|
+
if (properties[idProperty.value] == nil)
|
172
|
+
dputs callz + "saving ID property #{idProperty.value}"
|
173
|
+
properties[idProperty.value()]= @fx_id;
|
174
|
+
end
|
175
|
+
end
|
176
|
+
dputs callz+ "About to set instance variable #{@fx_id}"
|
177
|
+
# Set the controller field value
|
178
|
+
if (parentLoader.controller != nil)
|
179
|
+
field = parentLoader.controller.instance_variable_set("@" + @fx_id, value)
|
180
|
+
end
|
181
|
+
dputs callz + "Set.."
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def processCharacters()
|
186
|
+
type = value.java_class
|
187
|
+
defaultProperty = type.getAnnotation(DefaultProperty.java_class);
|
188
|
+
|
189
|
+
# If the default property is a read-only list, add the value to it;
|
190
|
+
# otherwise, set the value as the default property
|
191
|
+
if (defaultProperty != nil)
|
192
|
+
text = xmlStreamReader.getText();
|
193
|
+
#TODO: FIX
|
194
|
+
text = extraneousWhitespacePattern.matcher(text).replaceAll(" ");
|
195
|
+
|
196
|
+
defaultPropertyName = defaultProperty.value();
|
197
|
+
valueAdapter = getValueAdapter();
|
198
|
+
|
199
|
+
if (valueAdapter.read_only?(defaultPropertyName) && List.class.isAssignableFrom(valueAdapter.getType(defaultPropertyName)))
|
200
|
+
list = valueAdapter.get(defaultPropertyName);
|
201
|
+
list.add(getListValue(self, defaultPropertyName, text));
|
202
|
+
else
|
203
|
+
valueAdapter.put(defaultPropertyName, text.strip);
|
204
|
+
end
|
205
|
+
else
|
206
|
+
throw LoadException.new(type.getName() + " does not have a default property.");
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def processAttribute( prefix, localName, value)
|
211
|
+
if (prefix != nil && prefix == (FXL::FX_NAMESPACE_PREFIX))
|
212
|
+
if (localName == (FXL::FX_ID_ATTRIBUTE))
|
213
|
+
# Verify that ID is a valid identifier
|
214
|
+
if (value == (FXL::NULL_KEYWORD))
|
215
|
+
raise LoadException.new("Invalid identifier.");
|
216
|
+
end
|
217
|
+
#
|
218
|
+
# value.length.times do |i|
|
219
|
+
# # TODO: FIX
|
220
|
+
# if (!Java.java.lang.Character.java_send :isJavaIdentifierPart, [Java::char], value[i].to_java(:char))
|
221
|
+
# raise LoadException.new("Invalid identifier.");
|
222
|
+
# end
|
223
|
+
# end
|
224
|
+
dputs callz + "Found FXID is #{value}"
|
225
|
+
@fx_id = value;
|
226
|
+
|
227
|
+
elsif (localName == (FXL::FX_CONTROLLER_ATTRIBUTE))
|
228
|
+
if (parentLoader.current.parent != nil)
|
229
|
+
raise LoadException.new(FXL::FX_NAMESPACE_PREFIX + ":" + FXL::FX_CONTROLLER_ATTRIBUTE + " can only be applied to root element.");
|
230
|
+
end
|
231
|
+
|
232
|
+
dputs callz + "Found controller attrib is #{value} (#{parentLoader.controller}, #{staticLoad})"
|
233
|
+
if (parentLoader.controller != nil)
|
234
|
+
raise LoadException.new("Controller value already specified.");
|
235
|
+
end
|
236
|
+
|
237
|
+
if (!staticLoad)
|
238
|
+
type = nil
|
239
|
+
begin
|
240
|
+
type = parentLoader.constantize(value)
|
241
|
+
rescue ClassNotFoundException => exception
|
242
|
+
raise LoadException.new(exception);
|
243
|
+
end
|
244
|
+
|
245
|
+
begin
|
246
|
+
if (parentLoader.controllerFactory == nil)
|
247
|
+
# TODO: does this work?
|
248
|
+
parentLoader.controller = type.new
|
249
|
+
else
|
250
|
+
parentLoder.controller = (parentLoader.controllerFactory.call(type));
|
251
|
+
end
|
252
|
+
rescue InstantiationException => exception
|
253
|
+
raise LoadException.new(exception);
|
254
|
+
rescue IllegalAccessException => exception
|
255
|
+
raise LoadException.new(exception);
|
256
|
+
end
|
257
|
+
end
|
258
|
+
else
|
259
|
+
raise LoadException.new("Invalid attribute.");
|
260
|
+
end
|
261
|
+
else
|
262
|
+
dputs callz + "Super Again!"
|
263
|
+
super(prefix, localName, value);
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
@@ -0,0 +1,724 @@
|
|
1
|
+
=begin
|
2
|
+
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
3
|
+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4
|
+
*
|
5
|
+
* This code is free software; you can redistribute it and/or modify it
|
6
|
+
* under the terms of the GNU General Public License version 2 only, as
|
7
|
+
* published by the Free Software Foundation. Oracle designates this
|
8
|
+
* particular file as subject to the "Classpath" exception as provided
|
9
|
+
* by Oracle in the LICENSE file that accompanied this code.
|
10
|
+
*
|
11
|
+
* This code is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
+
* version 2 for more details (a copy is included in the LICENSE file that
|
15
|
+
* accompanied this code).
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU General Public License version
|
18
|
+
* 2 along with this work; if not, write to the Free Software Foundation,
|
19
|
+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
20
|
+
*
|
21
|
+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
22
|
+
* or visit www.oracle.com if you need additional information or have any
|
23
|
+
* questions.
|
24
|
+
*/
|
25
|
+
=end
|
26
|
+
|
27
|
+
|
28
|
+
begin
|
29
|
+
# Attempt to load a javafx class
|
30
|
+
Java.javafx.application.Application
|
31
|
+
rescue LoadError, NameError
|
32
|
+
puts "JRubyFX and JavaFX runtime not found. Please load this file from JRubyFX"
|
33
|
+
exit -2
|
34
|
+
end
|
35
|
+
|
36
|
+
#java_import 'javax.xml.stream.util.StreamReaderDelegate'
|
37
|
+
#java_import 'javax.xml.stream.XMLStreamException', 'javax.xml.stream.XMLInputFactory',
|
38
|
+
# 'java.io.InputStreamReader', 'javax.xml.stream.XMLStreamConstants'
|
39
|
+
java_import 'java.net.URL', 'java.nio.charset.Charset', 'java.lang.ClassNotFoundException'
|
40
|
+
#java_import 'javafx.fxml.LoadException'
|
41
|
+
java_import 'javafx.fxml.JavaFXBuilderFactory'
|
42
|
+
java_import 'java.lang.InstantiationException', 'java.lang.IllegalAccessException'
|
43
|
+
|
44
|
+
java_import *%w[com.sun.javafx.Logging
|
45
|
+
java.io.IOException
|
46
|
+
java.io.InputStream
|
47
|
+
java.io.InputStreamReader
|
48
|
+
java.lang.reflect.Constructor
|
49
|
+
java.lang.reflect.InvocationTargetException
|
50
|
+
java.lang.reflect.Modifier
|
51
|
+
java.lang.reflect.ParameterizedType
|
52
|
+
java.lang.reflect.Type
|
53
|
+
java.net.URL
|
54
|
+
java.nio.charset.Charset
|
55
|
+
java.util.AbstractMap
|
56
|
+
java.util.ArrayList
|
57
|
+
java.util.Collections
|
58
|
+
java.util.HashMap
|
59
|
+
java.util.LinkedList
|
60
|
+
java.util.List
|
61
|
+
java.util.Map
|
62
|
+
java.util.ResourceBundle
|
63
|
+
java.util.Set
|
64
|
+
java.util.regex.Pattern
|
65
|
+
|
66
|
+
javafx.beans.DefaultProperty
|
67
|
+
javafx.beans.property.Property
|
68
|
+
javafx.beans.value.ChangeListener
|
69
|
+
javafx.beans.value.ObservableValue
|
70
|
+
javafx.collections.FXCollections
|
71
|
+
javafx.collections.ListChangeListener
|
72
|
+
javafx.collections.MapChangeListener
|
73
|
+
javafx.collections.ObservableList
|
74
|
+
javafx.collections.ObservableMap
|
75
|
+
javafx.event.Event
|
76
|
+
javafx.event.EventHandler
|
77
|
+
javafx.event.EventType
|
78
|
+
javafx.util.Builder
|
79
|
+
javafx.util.BuilderFactory
|
80
|
+
javafx.util.Callback
|
81
|
+
|
82
|
+
javax.script.Bindings
|
83
|
+
javax.script.ScriptContext
|
84
|
+
javax.script.ScriptEngine
|
85
|
+
javax.script.ScriptEngineManager
|
86
|
+
javax.script.ScriptException
|
87
|
+
javax.script.SimpleBindings
|
88
|
+
javax.xml.stream.XMLInputFactory
|
89
|
+
javax.xml.stream.XMLStreamConstants
|
90
|
+
javax.xml.stream.XMLStreamException
|
91
|
+
javax.xml.stream.XMLStreamReader
|
92
|
+
javax.xml.stream.util.StreamReaderDelegate
|
93
|
+
|
94
|
+
com.sun.javafx.beans.IDProperty
|
95
|
+
com.sun.javafx.fxml.LoadListener
|
96
|
+
com.sun.javafx.fxml.ObservableListChangeEvent
|
97
|
+
com.sun.javafx.fxml.ObservableMapChangeEvent
|
98
|
+
com.sun.javafx.fxml.PropertyChangeEvent
|
99
|
+
java.net.MalformedURLException
|
100
|
+
java.security.AccessController
|
101
|
+
java.security.PrivilegedAction
|
102
|
+
java.util.Locale
|
103
|
+
java.lang.NoSuchMethodException
|
104
|
+
java.util.StringTokenizer
|
105
|
+
sun.reflect.misc.ConstructorUtil
|
106
|
+
sun.reflect.misc.FieldUtil
|
107
|
+
sun.reflect.misc.MethodUtil
|
108
|
+
sun.reflect.misc.ReflectUtil]
|
109
|
+
|
110
|
+
class LoadException < Exception
|
111
|
+
def initialize(stuff)
|
112
|
+
super
|
113
|
+
end
|
114
|
+
end
|
115
|
+
$DEBUG_IT_FXML = false
|
116
|
+
def dp(*args)
|
117
|
+
p *args if $DEBUG_IT_FXML
|
118
|
+
end
|
119
|
+
def dputs(*args)
|
120
|
+
puts *args if $DEBUG_IT_FXML
|
121
|
+
end
|
122
|
+
def dprint(*args)
|
123
|
+
print *args if $DEBUG_IT_FXML
|
124
|
+
end
|
125
|
+
|
126
|
+
# Override to safely get ruby class of non-java_class objects
|
127
|
+
class Class
|
128
|
+
def ruby_class
|
129
|
+
self
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
#Long to avoid collisions
|
134
|
+
MAGIC_FXML_JAVAFX_JRUBYFX_FXMLLOADER__FILE__LOCATION_SUPER_SECRET = __FILE__
|
135
|
+
|
136
|
+
FXL = java_import('javafx.fxml.FXMLLoader')[0]
|
137
|
+
class FxmlLoader
|
138
|
+
attr_accessor :location, :root, :template, :builderFactory, :namespace, :staticLoad, :current, :controllerFactory
|
139
|
+
attr_reader :controller
|
140
|
+
FX_NAMESPACE_VERSION="1"
|
141
|
+
def initialize(url=nil, ctrlr=nil, resourcs=nil, buildFactory=nil, charset=nil, loaders=nil)
|
142
|
+
@location = url
|
143
|
+
@builderFactory = buildFactory || JavaFXBuilderFactory.new
|
144
|
+
@template = false
|
145
|
+
if resourcs
|
146
|
+
dputs "WHOA WHOAT!!!! resources"
|
147
|
+
dp resourcs
|
148
|
+
end
|
149
|
+
if loaders
|
150
|
+
dputs "WHOA WHOAT!!!! loaders"
|
151
|
+
dp loaders
|
152
|
+
end
|
153
|
+
@namespace = FXCollections.observableHashMap()
|
154
|
+
self.controller = ctrlr
|
155
|
+
@packages = []
|
156
|
+
@classes = {}
|
157
|
+
@root = nil
|
158
|
+
@charset = charset || Charset.forName(FXL::DEFAULT_CHARSET_NAME)
|
159
|
+
end
|
160
|
+
|
161
|
+
def controller=(controller)
|
162
|
+
@controller = controller
|
163
|
+
unless controller
|
164
|
+
@namespace.delete(FXL::CONTROLLER_KEYWORD)
|
165
|
+
else
|
166
|
+
@namespace[FXL::CONTROLLER_KEYWORD] = controller
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def load()
|
171
|
+
dp "This is the namespace", @namespace
|
172
|
+
# TODO: actually open it properly
|
173
|
+
inputStream = @location.open_stream
|
174
|
+
if @template
|
175
|
+
@root = nil
|
176
|
+
else
|
177
|
+
clearImports
|
178
|
+
end
|
179
|
+
|
180
|
+
@namespace[FXL::LOCATION_KEY] = @location
|
181
|
+
@namespace[FXL::RESOURCES_KEY] = @resources
|
182
|
+
|
183
|
+
@script_engine = nil
|
184
|
+
|
185
|
+
begin
|
186
|
+
xmlInputFactory = XMLInputFactory.newFactory
|
187
|
+
xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true)
|
188
|
+
|
189
|
+
# Some stream readers incorrectly report an empty string as the prefix
|
190
|
+
# for the default namespace; correct this as needed
|
191
|
+
inputStreamReader = InputStreamReader.new(inputStream, @charset);
|
192
|
+
@xmlStreamReader = SRDelegateClass.new(xmlInputFactory.createXMLStreamReader(inputStreamReader))
|
193
|
+
rescue XMLStreamException => e
|
194
|
+
raise LoadException.new(e)
|
195
|
+
end
|
196
|
+
|
197
|
+
# Parse the XML stream
|
198
|
+
begin
|
199
|
+
while @xmlStreamReader.hasNext()
|
200
|
+
dputs "......"
|
201
|
+
event = @xmlStreamReader.next();
|
202
|
+
dputs "#{event} aout happened, dude"
|
203
|
+
case event
|
204
|
+
when XMLStreamConstants::PROCESSING_INSTRUCTION
|
205
|
+
dputs "processing instr"
|
206
|
+
processProcessingInstruction
|
207
|
+
when XMLStreamConstants::COMMENT
|
208
|
+
dputs "processing comment"
|
209
|
+
processComment
|
210
|
+
when XMLStreamConstants::START_ELEMENT
|
211
|
+
dputs "processing start"
|
212
|
+
processStartElement
|
213
|
+
when XMLStreamConstants::END_ELEMENT
|
214
|
+
dputs "processing end"
|
215
|
+
processEndElement
|
216
|
+
when XMLStreamConstants::CHARACTERS
|
217
|
+
dputs "processing chars"
|
218
|
+
processCharacters
|
219
|
+
end
|
220
|
+
end
|
221
|
+
rescue XMLStreamException => exception
|
222
|
+
raise Exception.new(exception)
|
223
|
+
end
|
224
|
+
dputs "Saving stuff!!!!s"
|
225
|
+
if @controller
|
226
|
+
# TODO: initialize should be called here
|
227
|
+
# Inject controller fields
|
228
|
+
@controller.instance_variable_set("@" + FXL::LOCATION_KEY, @location)
|
229
|
+
@controller.instance_variable_set("@" + FXL::RESOURCES_KEY, @resources)
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
@xmlStreamReader = nil
|
234
|
+
return @root
|
235
|
+
end
|
236
|
+
|
237
|
+
def clearImports
|
238
|
+
@packages.clear
|
239
|
+
@classes.clear
|
240
|
+
end
|
241
|
+
|
242
|
+
def processProcessingInstruction
|
243
|
+
piTarget = @xmlStreamReader.getPITarget().strip
|
244
|
+
if piTarget == FXL::LANGUAGE_PROCESSING_INSTRUCTION
|
245
|
+
processLanguage
|
246
|
+
elsif piTarget == FXL::IMPORT_PROCESSING_INSTRUCTION
|
247
|
+
processImport
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def processLanguage
|
252
|
+
if @scriptEngine
|
253
|
+
raise LoadException.new("Page language already set.")
|
254
|
+
end
|
255
|
+
|
256
|
+
language = @xmlStreamReader.getPIData()
|
257
|
+
|
258
|
+
if @loadListener
|
259
|
+
@loadListener.readLanguageProcessingInstruction(language)
|
260
|
+
end
|
261
|
+
|
262
|
+
unless staticLoad
|
263
|
+
scriptEngineManager = getScriptEngineManager()
|
264
|
+
scriptEngine = scriptEngineManager.getEngineByName(language)
|
265
|
+
scriptEngine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def processImport
|
270
|
+
target = @xmlStreamReader.getPIData().strip
|
271
|
+
|
272
|
+
if @loadListener
|
273
|
+
@loadListener.readImportProcessingInstruction(target)
|
274
|
+
end
|
275
|
+
|
276
|
+
if target.end_with?(".*")
|
277
|
+
importPackage(target[0,target.length - 2])
|
278
|
+
else
|
279
|
+
importClass(target)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def processComment
|
284
|
+
@loadListener.readComment(@xmlStreamReader.text) if @loadListener
|
285
|
+
end
|
286
|
+
|
287
|
+
def processStartElement()
|
288
|
+
# Create the element
|
289
|
+
createElement();
|
290
|
+
|
291
|
+
# Process the start tag
|
292
|
+
@current.processStartElement();
|
293
|
+
|
294
|
+
# Set the root value
|
295
|
+
unless @root
|
296
|
+
@root = @current.value;
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def createElement()
|
301
|
+
prefix = @xmlStreamReader.getPrefix();
|
302
|
+
localName = @xmlStreamReader.getLocalName();
|
303
|
+
|
304
|
+
if !prefix
|
305
|
+
i = localName.rindex('.')
|
306
|
+
|
307
|
+
if localName[(i ? i : -1) + 1] == localName[(i ? i : -1) + 1].downcase
|
308
|
+
name = localName[((i ? i : -1) + 1)..-1]
|
309
|
+
|
310
|
+
if (i == nil)
|
311
|
+
# This is an instance property
|
312
|
+
if @loadListener
|
313
|
+
@loadListener.beginPropertyElement(name, nil)
|
314
|
+
end
|
315
|
+
|
316
|
+
@current = PropertyElement.new(@current, @xmlStreamReader, @loadListener, self, name, nil)
|
317
|
+
else
|
318
|
+
# This is a static property
|
319
|
+
sourceType = getType(localName[0, i]);
|
320
|
+
if sourceType
|
321
|
+
if @loadListener
|
322
|
+
@loadListener.beginPropertyElement(name, sourceType);
|
323
|
+
end
|
324
|
+
|
325
|
+
@current = PropertyElement.new(@current, @xmlStreamReader, @loadListener, self,name, sourceType)
|
326
|
+
elsif (@staticLoad)
|
327
|
+
# The source type was not recognized
|
328
|
+
if @loadListener
|
329
|
+
@loadListener.beginUnknownStaticPropertyElement(localName);
|
330
|
+
end
|
331
|
+
|
332
|
+
@current = FXL::UnknownStaticPropertyElement.new
|
333
|
+
else
|
334
|
+
raise LoadException.new(localName + " is not a valid property.");
|
335
|
+
end
|
336
|
+
end
|
337
|
+
else
|
338
|
+
if (@current == nil && @root)
|
339
|
+
raise LoadException.new("Root value already specified.");
|
340
|
+
end
|
341
|
+
|
342
|
+
type = getType(localName);
|
343
|
+
prefixz = @xmlStreamReader.getLocation().getLineNumber().to_s + ": "
|
344
|
+
numz = 1
|
345
|
+
pppn = @current
|
346
|
+
while pppn
|
347
|
+
numz+=1
|
348
|
+
pppn = pppn.parent
|
349
|
+
end
|
350
|
+
prefixz = (" " * numz) + prefixz
|
351
|
+
dputs "#{prefixz}Creating new stuff"
|
352
|
+
dprint prefixz
|
353
|
+
dp localName
|
354
|
+
dprint prefixz
|
355
|
+
dp type
|
356
|
+
|
357
|
+
if type
|
358
|
+
if @loadListener
|
359
|
+
@loadListener.beginInstanceDeclarationElement(type);
|
360
|
+
end
|
361
|
+
@current = InstanceDeclarationElement.new(@current, @xmlStreamReader, @loadListener, self, type)
|
362
|
+
elsif (@staticLoad)
|
363
|
+
# The type was not recognized
|
364
|
+
if @loadListener
|
365
|
+
@loadListener.beginUnknownTypeElement(localName);
|
366
|
+
end
|
367
|
+
|
368
|
+
@current = UnknownTypeElement.new(@current, @xmlStreamReader, @loadListener, self)
|
369
|
+
else
|
370
|
+
raise LoadException.new(localName + " is not a valid type.");
|
371
|
+
end
|
372
|
+
end
|
373
|
+
elsif prefix == FXL::FX_NAMESPACE_PREFIX
|
374
|
+
if localName == FXL::INCLUDE_TAG
|
375
|
+
if @loadListener
|
376
|
+
@loadListener.beginIncludeElement()
|
377
|
+
end
|
378
|
+
@current = IncludeElement.new(@current, @xmlStreamReader, @loadListener, self)
|
379
|
+
elsif localName == FXL::REFERENCE_TAG
|
380
|
+
if @loadListener
|
381
|
+
@loadListener.beginReferenceElement
|
382
|
+
end
|
383
|
+
|
384
|
+
@current = ReferenceElement.new(@current, @xmlStreamReader, @loadListener, self)
|
385
|
+
elsif localName == FXL::COPY_TAG
|
386
|
+
if @loadListener
|
387
|
+
@loadListener.beginCopyElement();
|
388
|
+
end
|
389
|
+
|
390
|
+
@current = CopyElement.new(@current, @xmlStreamReader, @loadListener, self)
|
391
|
+
elsif localName == FXL::ROOT_TAG
|
392
|
+
if @loadListener
|
393
|
+
@loadListener.beginRootElement();
|
394
|
+
end
|
395
|
+
|
396
|
+
@current = RootElement.new(@current, @xmlStreamReader, @loadListener, self)
|
397
|
+
elsif localName == FXL::SCRIPT_TAG
|
398
|
+
if @loadListener
|
399
|
+
@loadListener.beginScriptElement();
|
400
|
+
end
|
401
|
+
|
402
|
+
@current = ScriptElement.new(@current, @xmlStreamReader, @loadListener, self)
|
403
|
+
elsif localName == FXL::DEFINE_TAG
|
404
|
+
if @loadListener
|
405
|
+
@loadListener.beginDefineElement();
|
406
|
+
end
|
407
|
+
|
408
|
+
@current = DefineElement.new(@current, @xmlStreamReader, @loadListener, self)
|
409
|
+
else
|
410
|
+
raise LoadException.new(prefix + ":" + localName + " is not a valid element.");
|
411
|
+
end
|
412
|
+
else
|
413
|
+
raise LoadException.new("Unexpected namespace prefix: " + prefix + ".");
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
def processEndElement()
|
418
|
+
dputs "ending!!!!!!!!"
|
419
|
+
@current.processEndElement();
|
420
|
+
if @loadListener
|
421
|
+
@loadListener.endElement(@current.value);
|
422
|
+
end
|
423
|
+
|
424
|
+
# Move up the stack
|
425
|
+
@current = @current.parent;
|
426
|
+
end
|
427
|
+
|
428
|
+
def processCharacters()
|
429
|
+
# Process the characters
|
430
|
+
if (!@xmlStreamReader.isWhiteSpace())
|
431
|
+
@current.processCharacters();
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
def importPackage(name)
|
436
|
+
@packages << name
|
437
|
+
end
|
438
|
+
|
439
|
+
def importClass(name)
|
440
|
+
begin
|
441
|
+
loadType(name, true);
|
442
|
+
rescue ClassNotFoundException => exception
|
443
|
+
raise LoadException.new(exception);
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
# steal handy methods from activesupport
|
448
|
+
# Tries to find a constant with the name specified in the argument string.
|
449
|
+
#
|
450
|
+
# 'Module'.constantize # => Module
|
451
|
+
# 'Test::Unit'.constantize # => Test::Unit
|
452
|
+
#
|
453
|
+
# The name is assumed to be the one of a top-level constant, no matter
|
454
|
+
# whether it starts with "::" or not. No lexical context is taken into
|
455
|
+
# account:
|
456
|
+
#
|
457
|
+
# C = 'outside'
|
458
|
+
# module M
|
459
|
+
# C = 'inside'
|
460
|
+
# C # => 'inside'
|
461
|
+
# 'C'.constantize # => 'outside', same as ::C
|
462
|
+
# end
|
463
|
+
#
|
464
|
+
# NameError is raised when the name is not in CamelCase or the constant is
|
465
|
+
# unknown.
|
466
|
+
def constantize(camel_cased_word)
|
467
|
+
names = camel_cased_word.split('.')
|
468
|
+
names.shift if names.empty? || names.first.empty?
|
469
|
+
|
470
|
+
names.inject(Object) do |constant, name|
|
471
|
+
if constant == Object
|
472
|
+
constant.const_get(name)
|
473
|
+
else
|
474
|
+
candidate = constant.const_get(name)
|
475
|
+
next candidate if constant.const_defined?(name, false)
|
476
|
+
next candidate unless Object.const_defined?(name)
|
477
|
+
|
478
|
+
# Go down the ancestors to check it it's owned
|
479
|
+
# directly before we reach Object or the end of ancestors.
|
480
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
481
|
+
break const if ancestor == Object
|
482
|
+
break ancestor if ancestor.const_defined?(name, false)
|
483
|
+
const
|
484
|
+
end
|
485
|
+
|
486
|
+
# owner is in Object, so raise
|
487
|
+
constant.const_get(name, false)
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
# Tries to find a constant with the name specified in the argument string.
|
493
|
+
#
|
494
|
+
# 'Module'.safe_constantize # => Module
|
495
|
+
# 'Test::Unit'.safe_constantize # => Test::Unit
|
496
|
+
#
|
497
|
+
# The name is assumed to be the one of a top-level constant, no matter
|
498
|
+
# whether it starts with "::" or not. No lexical context is taken into
|
499
|
+
# account:
|
500
|
+
#
|
501
|
+
# C = 'outside'
|
502
|
+
# module M
|
503
|
+
# C = 'inside'
|
504
|
+
# C # => 'inside'
|
505
|
+
# 'C'.safe_constantize # => 'outside', same as ::C
|
506
|
+
# end
|
507
|
+
#
|
508
|
+
# +nil+ is returned when the name is not in CamelCase or the constant (or
|
509
|
+
# part of it) is unknown.
|
510
|
+
#
|
511
|
+
# 'blargle'.safe_constantize # => nil
|
512
|
+
# 'UnknownModule'.safe_constantize # => nil
|
513
|
+
# 'UnknownModule::Foo::Bar'.safe_constantize # => nil
|
514
|
+
def safe_constantize(camel_cased_word)
|
515
|
+
constantize(camel_cased_word)
|
516
|
+
rescue NameError => e
|
517
|
+
raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ ||
|
518
|
+
e.name.to_s == camel_cased_word.to_s
|
519
|
+
rescue ArgumentError => e
|
520
|
+
raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/
|
521
|
+
end
|
522
|
+
|
523
|
+
def getType(name)
|
524
|
+
type = nil
|
525
|
+
|
526
|
+
if name[0] == name[0].downcase
|
527
|
+
# This is a fully-qualified class name
|
528
|
+
begin
|
529
|
+
type = loadType(name, false);
|
530
|
+
rescue ClassNotFoundException => exception
|
531
|
+
# No-op
|
532
|
+
end
|
533
|
+
else
|
534
|
+
# This is an unqualified class name
|
535
|
+
type = @classes[name];
|
536
|
+
|
537
|
+
unless type
|
538
|
+
# The class has not been loaded yet; look it up
|
539
|
+
@packages.each do |packageName|
|
540
|
+
begin
|
541
|
+
type = loadTypeForPackage(packageName, name);
|
542
|
+
rescue ClassNotFoundException => exception
|
543
|
+
# No-op
|
544
|
+
end
|
545
|
+
break if type
|
546
|
+
end
|
547
|
+
unless type
|
548
|
+
# check for ruby
|
549
|
+
# TODO: this should require an import or something perhaps? need to think more about this?
|
550
|
+
begin
|
551
|
+
type = constantize(name)
|
552
|
+
rescue
|
553
|
+
# No-op
|
554
|
+
end
|
555
|
+
end
|
556
|
+
@classes[name] = type if type
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
return type;
|
561
|
+
end
|
562
|
+
|
563
|
+
def loadType(name, cache)
|
564
|
+
i = name.index('.');
|
565
|
+
n = name.length;
|
566
|
+
while (i &&
|
567
|
+
i < n &&
|
568
|
+
name[i + 1] == name[i + 1].downcase)
|
569
|
+
i = name.index('.', i + 1);
|
570
|
+
end
|
571
|
+
|
572
|
+
if (i == nil || i == n)
|
573
|
+
raise ClassNotFoundException.new();
|
574
|
+
end
|
575
|
+
|
576
|
+
packageName = name[0, i];
|
577
|
+
className = name[(i + 1)..-1];
|
578
|
+
|
579
|
+
type = loadTypeForPackage(packageName, className);
|
580
|
+
|
581
|
+
if (cache)
|
582
|
+
@classes[className] = type
|
583
|
+
end
|
584
|
+
|
585
|
+
return type;
|
586
|
+
end
|
587
|
+
|
588
|
+
|
589
|
+
def getScriptEngineManager()
|
590
|
+
unless @scriptEngineManager
|
591
|
+
@scriptEngineManager = Java.javax.script.ScriptEngineManager.new
|
592
|
+
@scriptEngineManager.setBindings(SimpleBindings.new(@namespace))
|
593
|
+
end
|
594
|
+
|
595
|
+
return @scriptEngineManager;
|
596
|
+
end
|
597
|
+
|
598
|
+
def loadTypeForPackage(packageName, className=nil)
|
599
|
+
packageName = (packageName + "." + className.gsub('.', '$')) if className
|
600
|
+
#TODO: fix for ruby stuff
|
601
|
+
return Java.java.lang.Class::forName(packageName, true, FXL::default_class_loader);
|
602
|
+
end
|
603
|
+
def compareJFXVersions(rtVer, nsVer)
|
604
|
+
|
605
|
+
retVal = 0;
|
606
|
+
|
607
|
+
if (rtVer == nil || "" == (rtVer) || nsVer == nil || "" == (nsVer))
|
608
|
+
return retVal;
|
609
|
+
end
|
610
|
+
|
611
|
+
if (rtVer == (nsVer))
|
612
|
+
return retVal;
|
613
|
+
end
|
614
|
+
|
615
|
+
# version string can contain '-'
|
616
|
+
dashIndex = rtVer.index("-");
|
617
|
+
dashIndex = -1 unless dashIndex
|
618
|
+
if (dashIndex > 0)
|
619
|
+
|
620
|
+
rtVer = rtVer[0, dashIndex]
|
621
|
+
end
|
622
|
+
|
623
|
+
# or "_"
|
624
|
+
underIndex = rtVer.index("_");
|
625
|
+
underIndex = -1 unless underIndex
|
626
|
+
if (underIndex > 0)
|
627
|
+
|
628
|
+
rtVer = rtVer[0, underIndex]
|
629
|
+
end
|
630
|
+
|
631
|
+
# do not try to compare if the string is not valid version format
|
632
|
+
if (!rtVer.match(/^(\d+)(\.\d+)*$/) || !nsVer.match(/^(\d+)(\.\d+)*$/))
|
633
|
+
return retVal;
|
634
|
+
end
|
635
|
+
|
636
|
+
nsVerTokenizer = StringTokenizer.new(nsVer, ".");
|
637
|
+
rtVerTokenizer = StringTokenizer.new(rtVer, ".");
|
638
|
+
nsDigit = 0
|
639
|
+
rtDigit = 0;
|
640
|
+
rtVerEnd = false;
|
641
|
+
|
642
|
+
while (nsVerTokenizer.hasMoreTokens() && retVal == 0)
|
643
|
+
nsDigit = nsVerTokenizer.nextToken().to_i
|
644
|
+
if (rtVerTokenizer.hasMoreTokens())
|
645
|
+
rtDigit = rtVerTokenizer.nextToken().to_i
|
646
|
+
retVal = rtDigit - nsDigit;
|
647
|
+
else
|
648
|
+
rtVerEnd = true;
|
649
|
+
break;
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
if (rtVerTokenizer.hasMoreTokens() && retVal == 0)
|
654
|
+
rtDigit = rtVerTokenizer.nextToken().to_i
|
655
|
+
if (rtDigit > 0)
|
656
|
+
retVal = 1;
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
if (rtVerEnd)
|
661
|
+
if (nsDigit > 0)
|
662
|
+
retVal = -1;
|
663
|
+
else
|
664
|
+
while (nsVerTokenizer.hasMoreTokens())
|
665
|
+
nsDigit = nsVerTokenizer.nextToken().to_i
|
666
|
+
if (nsDigit > 0)
|
667
|
+
retVal = -1;
|
668
|
+
break;
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|
672
|
+
end
|
673
|
+
|
674
|
+
return retVal;
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
678
|
+
|
679
|
+
class SRDelegateClass < StreamReaderDelegate
|
680
|
+
def getPrefix()
|
681
|
+
|
682
|
+
prefix = super
|
683
|
+
|
684
|
+
if prefix && prefix.length == 0
|
685
|
+
prefix = nil
|
686
|
+
end
|
687
|
+
return prefix;
|
688
|
+
end
|
689
|
+
|
690
|
+
def getAttributePrefix(index)
|
691
|
+
prefix = super
|
692
|
+
|
693
|
+
if prefix && prefix.length == 0
|
694
|
+
prefix = nil
|
695
|
+
end
|
696
|
+
return prefix;
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
require_relative 'fxmlloader/j8_expression_value'
|
701
|
+
require_relative 'fxmlloader/elts'
|
702
|
+
require_relative 'fxmlloader/value_elts'
|
703
|
+
require_relative 'fxmlloader/real_elts'
|
704
|
+
require_relative 'fxmlloader/rrba'
|
705
|
+
require_relative 'fxmlloader/rorba'
|
706
|
+
require_relative 'FXMLLoader-j8.jar'
|
707
|
+
|
708
|
+
java_import 'org.jruby.jfx8.KeyPath'
|
709
|
+
java_import 'org.jruby.jfx8.Expression'
|
710
|
+
|
711
|
+
|
712
|
+
class RRBAdapters < org.jruby.jfx8.RubyBeanAdapter
|
713
|
+
def get(names, key)
|
714
|
+
RubyWrapperBeanAdapter.for(names)[key]
|
715
|
+
end
|
716
|
+
def set(names, key, value)
|
717
|
+
RubyWrapperBeanAdapter.for(names)[key] = value
|
718
|
+
end
|
719
|
+
def contains(names, key)
|
720
|
+
RubyWrapperBeanAdapter.for(names).has_key? key
|
721
|
+
end
|
722
|
+
end
|
723
|
+
|
724
|
+
org.jruby.jfx8.RubyBeanAdapter.load_ruby_space RRBAdapters.new
|