Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javafx.fxml;
import com.sun.javafx.fxml.BeanAdapter;
import com.sun.javafx.fxml.builder.JavaFXFontBuilder;
import com.sun.javafx.fxml.builder.JavaFXImageBuilder;
import com.sun.javafx.fxml.builder.JavaFXSceneBuilder;
import com.sun.javafx.fxml.builder.ProxyBuilder;
import com.sun.javafx.fxml.builder.TriangleMeshBuilder;
import com.sun.javafx.fxml.builder.URLBuilder;
import com.sun.javafx.logging.PlatformLogger;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.beans.NamedArg;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.shape.TriangleMesh;
import javafx.scene.text.Font;
import javafx.util.Builder;
import javafx.util.BuilderFactory;
import com.sun.javafx.reflect.ConstructorUtil;
import com.sun.javafx.reflect.MethodUtil;
/**
* JavaFX builder factory.
* @since JavaFX 2.0
*/
public final class JavaFXBuilderFactory implements BuilderFactory {
private final ClassLoader classLoader;
private final boolean webSupported;
private static final String WEBVIEW_NAME = "javafx.scene.web.WebView";
// WebViewBuilder class name loaded via reflection
// TODO: Uncomment the following when RT-40037 is fixed.
// private static final String WEBVIEW_BUILDER_NAME =
// "com.sun.javafx.fxml.builder.web.JavaFXWebViewBuilder";
// TODO: Remove the following when RT-40037 is fixed.
private static final String WEBVIEW_BUILDER_NAME =
"com.sun.javafx.fxml.builder.web.WebViewBuilder";
/**
* Default constructor.
*/
public JavaFXBuilderFactory() {
this(FXMLLoader.getDefaultClassLoader());
}
/**
* Constructor that takes a class loader.
*
* @param classLoader the class loader to use when loading classes
* @since JavaFX 2.1
*/
public JavaFXBuilderFactory(ClassLoader classLoader) {
if (classLoader == null) {
throw new NullPointerException();
}
this.classLoader = classLoader;
this.webSupported = Platform.isSupported(ConditionalFeature.WEB);
}
/**
* Returns the builder for the specified type, or null if no builder is
* used. Most classes will note use a builder.
*
* @param type the class being looked up
*
* @return the builder for the class, or null if no builder is used
*/
@Override
public Builder> getBuilder(Class> type) {
if (type == null) {
throw new NullPointerException();
}
Builder> builder;
// All classes without a default constructor need to appear here, as
// well as any other class that has special requirements that need
// a builder to handle them.
if (type == Scene.class) {
builder = new JavaFXSceneBuilder();
} else if (type == Font.class) {
builder = new JavaFXFontBuilder();
} else if (type == Image.class) {
builder = new JavaFXImageBuilder();
} else if (type == URL.class) {
builder = new URLBuilder(classLoader);
} else if (type == TriangleMesh.class) {
builder = new TriangleMeshBuilder();
} else if (webSupported && type.getName().equals(WEBVIEW_NAME)) {
// TODO: enable this code when RT-40037 is fixed.
// // Construct a WebViewBuilder via reflection
// try {
// Class> builderClass =
// (Class>)classLoader.loadClass(WEBVIEW_BUILDER_NAME);
// Constructor> constructor = builderClass.getConstructor(new Class[0]);
// builder = constructor.newInstance();
// } catch (Exception ex) {
// // This should never happen
// ex.printStackTrace();
// builder = null;
// }
// TODO: Remove the following when RT-40037 is fixed.
try {
Class> builderClass = classLoader.loadClass(WEBVIEW_BUILDER_NAME);
ObjectBuilderWrapper wrapper = new ObjectBuilderWrapper(builderClass);
builder = wrapper.createBuilder();
} catch (Exception ex) {
builder = null;
}
} else if (scanForConstructorAnnotations(type)) {
builder = new ProxyBuilder(type);
} else {
// No builder will be used to construct this class. The class must
// have a public default constructor, which is the case for all
// platform classes, except those handled above.
builder = null;
}
return builder;
}
private boolean scanForConstructorAnnotations(Class> type) {
Constructor constructors[] = ConstructorUtil.getConstructors(type);
for (Constructor constructor : constructors) {
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
for (Annotation annotation : paramAnnotations[i]) {
if (annotation instanceof NamedArg) {
return true;
}
}
}
}
return false;
}
/**
* Legacy ObjectBuilder wrapper.
*
* TODO: move this legacy functionality to JavaFXWebViewBuilder and modify
* it to work without requiring the legacy builders. See RT-40037.
*/
private static final class ObjectBuilderWrapper {
private static final Object[] NO_ARGS = {};
private static final Class>[] NO_SIG = {};
private final Class> builderClass;
private final Method createMethod;
private final Method buildMethod;
private final Map methods = new HashMap();
private final Map getters = new HashMap();
private final Map setters = new HashMap();
final class ObjectBuilder extends AbstractMap implements Builder