0N/A/*
2362N/A * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Aimport java.beans.PropertyEditor;
0N/Aimport java.beans.PropertyEditorManager;
0N/A
0N/Afinal class TestEditor {
0N/A private final PropertyEditor editor;
0N/A
0N/A TestEditor(Class type) {
0N/A System.out.println("Property class: " + type);
0N/A
0N/A this.editor = PropertyEditorManager.findEditor(type);
0N/A if (this.editor == null)
0N/A throw new Error("could not find editor for " + type);
0N/A
0N/A System.out.println("PropertyEditor class: " + this.editor.getClass());
0N/A validate(null, null);
0N/A }
0N/A
0N/A void testJava(Object value) {
0N/A this.editor.setValue(value);
0N/A
632N/A Object object = execute("Executor", "execute", this.editor.getJavaInitializationString());
0N/A
0N/A System.out.println("Property value before: " + value);
0N/A System.out.println("Property value after: " + object);
0N/A
0N/A if (!areEqual(value, object))
0N/A throw new Error("values are not equal");
0N/A }
0N/A
0N/A void testValue(Object value, String text) {
0N/A this.editor.setValue(value);
0N/A validate(value, text);
0N/A }
0N/A
0N/A void testText(String text, Object value) {
0N/A this.editor.setAsText(text);
0N/A validate(value, text);
0N/A }
0N/A
0N/A private void validate(Object value, String text) {
0N/A if (!areEqual(value, this.editor.getValue()))
0N/A throw new Error("value should be " + value);
0N/A
0N/A if (!areEqual(text, this.editor.getAsText()))
0N/A throw new Error("text should be " + text);
0N/A }
0N/A
0N/A private static boolean areEqual(Object object1, Object object2) {
0N/A return (object1 == null)
0N/A ? object2 == null
0N/A : object1.equals(object2);
0N/A }
0N/A
632N/A private static Object execute(String classname, String methodname, String value) {
632N/A String content
632N/A = "public class " + classname + " {"
632N/A + " public static Object " + methodname + "() throws Exception {"
632N/A + " return " + value + ";"
632N/A + " }"
632N/A + "}";
0N/A
632N/A try {
632N/A MemoryClassLoader loader = new MemoryClassLoader();
632N/A Class type = loader.compile(classname, content);
632N/A return type.getMethod(methodname).invoke(null);
0N/A }
632N/A catch (Exception exception) {
632N/A throw new Error(exception);
0N/A }
0N/A }
0N/A}