當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassReflection.forName方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.utils.reflect.ClassReflection.forName方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassReflection.forName方法的具體用法?Java ClassReflection.forName怎麽用?Java ClassReflection.forName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.utils.reflect.ClassReflection的用法示例。


在下文中一共展示了ClassReflection.forName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClass

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/**
 * Returns the Class matching the name of the JsonValue, or null if there is no match or it's nameless.
 */
private Class getClass(JsonValue value, ObjectMap<String, Class> tagsToClasses) {
    if (value.name() != null && value.name().length() > 0) {
        String className = value.name();
        Class type = tagsToClasses.get(className);
        if (type == null) {
            try {
                type = ClassReflection.forName(className);
            } catch (ReflectionException ex) {
                type = null;
            }
        }
        return type;
    }
    return null;
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:19,代碼來源:JsonFieldUpdater.java

示例2: PlatformDistributor

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/**
 * Creates platform specific object by reflection.
 * <p>
 * Uses class names given by {@link #getAndroidClassName()} and {@link #getIOSClassName()}
 * <p>
 * If you need to run project on different platform use {@link #setMockObject(Object)} to polyfill platform object.
 *
 * @throws PlatformDistributorException Throws when something is wrong with environment
 */
@SuppressWarnings("unchecked")
protected PlatformDistributor() throws PlatformDistributorException
{
    String className = null;
    if (Gdx.app.getType() == Application.ApplicationType.Android) {
        className = getAndroidClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.iOS) {
        className = getIOSClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        className = getWebGLClassName();
    } else {
        return;
    }
    try {
        Class objClass = ClassReflection.forName(className);
        platformObject = (T) ClassReflection.getConstructor(objClass).newInstance();
    } catch (ReflectionException e) {
        e.printStackTrace();
        throw new PlatformDistributorException("Something wrong with environment");
    }
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:31,代碼來源:PlatformDistributor.java

示例3: get

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private Bundlable get() {
	try {
		String clName = getString( CLASS_NAME );
		if (aliases.containsKey( clName )) {
			clName = aliases.get( clName );
		}
		
		Class<?> cl = ClassReflection.forName( clName );
		if (cl != null) {
			Bundlable object = (Bundlable) ClassReflection.newInstance(cl);
			object.restoreFromBundle( this );
			return object;
		} else {
			return null;
		}
	} catch (Exception e) {
		e = null;
		return null;
	}	
}
 
開發者ID:kurtyu,項目名稱:PixelDungeonTC,代碼行數:21,代碼來源:Bundle.java

示例4: read

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
@Override
public void read(Json json, JsonValue jsonValue) {
    try {
        name = jsonValue.getString("name");
        optional = jsonValue.getBoolean("optional");
        if (jsonValue.get("value").isNumber()) {
            type = Float.TYPE;
            value = Double.parseDouble(jsonValue.getString("value"));
        } else {
            type = ClassReflection.forName(jsonValue.getString("type"));
            if (jsonValue.get("value").isNull()) {
                value = null;
            } else {
                value = jsonValue.getString("value");
            }
        }
    } catch (ReflectionException ex) {
        Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex);
        DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?");
    }
}
 
開發者ID:raeleus,項目名稱:skin-composer,代碼行數:22,代碼來源:StyleProperty.java

示例5: readActions

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/**
 * Read the actions from the suppled XML element and loads them into the
 * supplied ActionsContainer.
 * 
 * The XML element should contain children in the following format:
 * 
 * <pre>
 * &lt;actionClassName parameter1Name="parameter1Value" parameter2Name="parameter2Value" ... /&gt;
 * </pre>
 * 
 * @param ac
 * @param actionsElement
 */
@SuppressWarnings({ "unchecked" })
public static void readActions(ActionsContainer ac, Element actionsElement) {
	if (actionsElement != null) {
		for (int i = 0; i < actionsElement.getChildCount(); ++i) {
			Element actionElement = actionsElement.getChild(i);
			String implementationClassName = actionElement.getName();
			implementationClassName = Action.class.getPackage().getName() + "."
					+ StringUtil.capitalizeFirstLetter(implementationClassName);
			try {
				Class<? extends Action> actionClass = (Class<? extends Action>) ClassReflection
						.forName(implementationClassName);
				Action newAction = ac.addAction(actionClass);
				if (newAction != null) {
					newAction.loadFromXML(actionElement);
				}

			} catch (ReflectionException e) {
				throw new GdxRuntimeException(e);
			}
		}
	}
}
 
開發者ID:mganzarcik,項目名稱:fabulae,代碼行數:36,代碼來源:XMLUtil.java

示例6: tryLoadDesktopTwitterAPI

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void tryLoadDesktopTwitterAPI() {
	if (Gdx.app.getType() != ApplicationType.Desktop) {
		Gdx.app.debug(TAG, "Skip loading Twitter API for Desktop. Not running Desktop. \n");
		return;
	}
	try {

		final Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.desktop.DesktopTwitterAPI");
		Object twitter = ClassReflection.getConstructor(twitterClazz, TwitterConfig.class).newInstance(config);

		twitterAPI = (TwitterAPI) twitter;

		Gdx.app.debug(TAG, "gdx-twitter for Desktop loaded successfully.");

	} catch (ReflectionException e) {
		Gdx.app.debug(TAG, "Error creating gdx-twitter for Desktop (are the gdx-twitter **.jar files installed?). \n");
		e.printStackTrace();
	}

}
 
開發者ID:TomGrill,項目名稱:gdx-twitter,代碼行數:21,代碼來源:TwitterSystem.java

示例7: tryLoadHTMLTwitterAPI

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void tryLoadHTMLTwitterAPI() {
	if (Gdx.app.getType() != ApplicationType.WebGL) {
		Gdx.app.debug(TAG, "Skip loading gdx-twitter for HTML. Not running HTML. \n");
		return;
	}

	try {

		final Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.html.HTMLTwitterAPI");
		Object twitter = ClassReflection.getConstructor(twitterClazz, TwitterConfig.class).newInstance(config);

		twitterAPI = (TwitterAPI) twitter;

		Gdx.app.debug(TAG, "gdx-twitter for HTML loaded successfully.");

	} catch (ReflectionException e) {
		Gdx.app.debug(TAG, "Error creating gdx-twitter for HTML (are the gdx-twitter **.jar files installed?). \n");
		e.printStackTrace();
	}

}
 
開發者ID:TomGrill,項目名稱:gdx-twitter,代碼行數:22,代碼來源:TwitterSystem.java

示例8: tryLoadIOSTWitterAPI

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void tryLoadIOSTWitterAPI() {

		if (Gdx.app.getType() != ApplicationType.iOS) {
			Gdx.app.debug(TAG, "Skip loading gdx-twitter for iOS. Not running iOS. \n");
			return;
		}
		try {

			// Class<?> activityClazz =
			// ClassReflection.forName("com.badlogic.gdx.backends.iosrobovm.IOSApplication");
			final Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.ios.IOSTwitterAPI");

			Object twitter = ClassReflection.getConstructor(twitterClazz, TwitterConfig.class).newInstance(config);

			twitterAPI = (TwitterAPI) twitter;

			Gdx.app.debug(TAG, "gdx-twitter for iOS loaded successfully.");

		} catch (ReflectionException e) {
			Gdx.app.debug(TAG, "Error creating gdx-twitter for iOS (are the gdx-twitter **.jar files installed?). \n");
			e.printStackTrace();
		}

	}
 
開發者ID:TomGrill,項目名稱:gdx-twitter,代碼行數:25,代碼來源:TwitterSystem.java

示例9: newDialog

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
@Override
public <T> T newDialog(Class<T> cls) {
	String className = cls.getName();
	if (registeredDialogs.containsKey(className)) {

		try {
			final Class<T> dialogClazz = ClassReflection.forName(registeredDialogs.get(className));

			Object dialogObject = ClassReflection.getConstructor(dialogClazz, Activity.class).newInstance(activity);

			return dialogClazz.cast(dialogObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	throw new RuntimeException(cls.getName() + "is not registered.");
}
 
開發者ID:TomGrill,項目名稱:gdx-dialogs,代碼行數:18,代碼來源:AndroidGDXDialogs.java

示例10: installDesktopGDXDialogs

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void installDesktopGDXDialogs() {
	if (Gdx.app.getType() != ApplicationType.Desktop) {
		showDebugSkipInstall(ApplicationType.Desktop.name());
		return;
	}
	try {

		final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.desktop.DesktopGDXDialogs");

		Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance();

		this.gdxDialogs = (GDXDialogs) dialogManager;

		showDebugInstallSuccessful(ApplicationType.Desktop.name());

	} catch (ReflectionException e) {
		showErrorInstall(ApplicationType.Desktop.name(), "desktop");
		e.printStackTrace();
	}

}
 
開發者ID:TomGrill,項目名稱:gdx-dialogs,代碼行數:22,代碼來源:GDXDialogsSystem.java

示例11: installHTMLGDXDialogs

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void installHTMLGDXDialogs() {
	if (Gdx.app.getType() != ApplicationType.WebGL) {
		showDebugSkipInstall(ApplicationType.WebGL.name());
		return;
	}

	try {

		final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.html.HTMLGDXDialogs");
		Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance();

		this.gdxDialogs = (GDXDialogs) dialogManager;
		showDebugInstallSuccessful(ApplicationType.WebGL.name());

	} catch (ReflectionException e) {
		showErrorInstall(ApplicationType.WebGL.name(), "html");
		e.printStackTrace();
	}

}
 
開發者ID:TomGrill,項目名稱:gdx-dialogs,代碼行數:21,代碼來源:GDXDialogsSystem.java

示例12: extractFromBinaries

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private static Array<Class<?>> extractFromBinaries(final Iterable<Class<? extends Annotation>> annotations,
        final String mainPackageName, final Queue<Pair<File, Integer>> filesWithDepthsToProcess)
                throws ReflectionException {
    final Array<Class<?>> result = GdxArrays.newArray();
    while (!filesWithDepthsToProcess.isEmpty()) {
        final Pair<File, Integer> classPathFileWithDepth = filesWithDepthsToProcess.poll();
        final File classPathFile = classPathFileWithDepth.getFirst();
        final int depth = classPathFileWithDepth.getSecond();
        if (classPathFile.isDirectory()) {
            addAllChildren(filesWithDepthsToProcess, classPathFile, depth);
        } else {
            final String className = getBinaryClassName(mainPackageName, classPathFile, depth);
            if (!isFromPackage(mainPackageName, className)) {
                continue;
            }
            final Class<?> classToProcess = ClassReflection.forName(className);
            processClass(annotations, result, classToProcess);
        }
    }
    return result;
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn,代碼行數:22,代碼來源:FallbackDesktopClassScanner.java

示例13: findClassesAnnotatedWith

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
@Override
public Array<Class<?>> findClassesAnnotatedWith(final Class<?> root,
        final Iterable<Class<? extends Annotation>> annotations) {
    final Array<Class<?>> result = GdxArrays.newArray();
    final String packageName = extractPackageName(root);
    for (final String className : JTranscReflection.getAllClasses()) {
        if (Strings.isNotEmpty(className) && className.startsWith(packageName)) {
            try {
                final Class<?> processed = ClassReflection.forName(className);
                if (isAnnotatedWithAny(processed, annotations)) {
                    result.add(processed);
                }
            } catch (final Exception exception) {
                Gdx.app.debug("JTransc", "Error thrown during processing of class: " + className, exception);
            }
        }
    }
    return result;
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:20,代碼來源:JTranscClassScanner.java

示例14: processClassName

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private static void processClassName(final Iterable<Class<? extends Annotation>> annotations,
        final Array<Class<?>> result, final String packageName, final String className) {
    if (!className.startsWith(packageName)) {
        return;
    }
    try {
        final Class<?> classToProcess = ClassReflection.forName(className);
        for (final Class<? extends Annotation> annotation : annotations) {
            if (ClassReflection.isAnnotationPresent(classToProcess, annotation)) {
                result.add(classToProcess);
                return;
            }
        }
    } catch (final ReflectionException exception) {
        exception.printStackTrace(); // Unexpected. Classes should be present.
    }
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:18,代碼來源:AndroidClassScanner.java

示例15: findClass

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private static Class<?> findClass(String name) {
    try {
        return ClassReflection.forName(name);
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:TomGrill,項目名稱:gdx-firebase,代碼行數:8,代碼來源:FirebaseLoader.java


注:本文中的com.badlogic.gdx.utils.reflect.ClassReflection.forName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。