1 /* 2 * Copyright (c) 2010, 2015, 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 26 package test.javafx.fxml; 27 28 import java.io.IOException; 29 import java.util.Map; 30 import javafx.fxml.FXMLLoader; 31 import javafx.fxml.LoadListener; 32 import org.junit.Test; 33 34 import static org.junit.Assert.*; 35 36 public class RT_18218Test { 37 @Test 38 @SuppressWarnings({"unchecked", "deprecation"}) 39 public void testStaticScriptLoad() throws IOException { 40 FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("rt_18218.fxml")); 41 fxmlLoader.impl_setStaticLoad(true); 42 fxmlLoader.setLoadListener(new LoadListener() { 43 private String unknownStaticPropertyElementName = null; 44 45 @Override 46 public void readImportProcessingInstruction(String target) { 47 } 48 49 @Override 50 public void readLanguageProcessingInstruction(String language) { 51 } 52 53 @Override 54 public void readComment(String comment) { 55 } 56 57 @Override 58 public void beginInstanceDeclarationElement(Class<?> type) { 59 } 60 61 @Override 62 public void beginUnknownTypeElement(String name) { 63 } 64 65 @Override 66 public void beginIncludeElement() { 67 } 68 69 @Override 70 public void beginReferenceElement() { 71 } 72 73 @Override 74 public void beginCopyElement() { 75 } 76 77 @Override 78 public void beginRootElement() { 79 } 80 81 @Override 82 public void beginPropertyElement(String name, Class<?> sourceType) { 83 } 84 85 @Override 86 public void beginUnknownStaticPropertyElement(String name) { 87 unknownStaticPropertyElementName = name; 88 } 89 90 @Override 91 public void beginScriptElement() { 92 } 93 94 @Override 95 public void beginDefineElement() { 96 } 97 98 @Override 99 public void readInternalAttribute(String name, String value) { 100 } 101 102 @Override 103 public void readPropertyAttribute(String name, Class<?> sourceType, String value) { 104 } 105 106 @Override 107 public void readUnknownStaticPropertyAttribute(String name, String value) { 108 assertEquals(name, "Gadget.bar"); 109 assertEquals(value, "123456"); 110 } 111 112 @Override 113 public void readEventHandlerAttribute(String name, String value) { 114 } 115 116 @Override 117 public void endElement(Object value) { 118 if (unknownStaticPropertyElementName != null) { 119 if (unknownStaticPropertyElementName.equals("Gadget.bar")) { 120 assertEquals(value, "abcdef"); 121 } else if (unknownStaticPropertyElementName.equals("Gadget.baz")) { 122 assertEquals(value.getClass(), Widget.class); 123 } else { 124 throw new RuntimeException(); 125 } 126 127 unknownStaticPropertyElementName = null; 128 } 129 } 130 }); 131 132 fxmlLoader.load(); 133 134 Map<String, Object> gadget = (Map<String, Object>)fxmlLoader.getNamespace().get("gadget"); 135 assertNotNull(gadget); 136 137 Widget widget2 = (Widget)fxmlLoader.getNamespace().get("widget2"); 138 assertNotNull(widget2); 139 assertEquals(widget2.getName(), "Widget 2"); 140 } 141 }