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