package com.activeandroid.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.activeandroid.Model;

public final class ReflectionUtils {
	//////////////////////////////////////////////////////////////////////////////////////
	// PUBLIC METHODS
	//////////////////////////////////////////////////////////////////////////////////////

	public static boolean isModel(Class<?> type) {
		if (type.isPrimitive()) {
			return false;
		}
		else if (type.equals(Model.class)) {
			return true;
		}
		else if (type.getSuperclass() != null) {
			return isModel(type.getSuperclass());
		}

		return false;
	}

	public static boolean isTypeSerializer(Class<?> type) {
		if (type.isPrimitive()) {
			return false;
		}
		else if (type.equals(Model.class)) {
			return true;
		}
		else if (type.getSuperclass() != null) {
			return isModel(type.getSuperclass());
		}

		return false;
	}

	// Meta-data

	@SuppressWarnings("unchecked")
	public static <T> T getMetaData(Context context, String name) {
		try {
			final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
					PackageManager.GET_META_DATA);

			if (ai.metaData != null) {
				return (T) ai.metaData.get(name);
			}
		}
		catch (Exception e) {
			Log.w("Couldn't find meta-data: " + name);
		}

		return null;
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// PRIVATE METHODS
	//////////////////////////////////////////////////////////////////////////////////////

	public static boolean isSubclassOf(Class<?> type, Class<?> superClass) {
		if (type.isPrimitive()) {
			return false;
		}
		else if (type.equals(superClass)) {
			return true;
		}
		else if (type.getSuperclass() != null) {
			return isSubclassOf(type.getSuperclass(), superClass);
		}

		return false;
	}
}
@@ -175,16 +175,68 @@
 d.Model;
+%0Aimport com.activeandroid.serializer.TypeSerializer;
 %0A%0Apublic
@@ -516,491 +516,158 @@
 %7B%0A%09%09
-if (type.isPrimitive()) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09else if (type.equals(Model.class)) %7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09else if (type.getSuperclass() != null) %7B%0A%09%09%09return isModel(type.getSuperclass());%0A%09%09%7D%0A%0A%09%09return false;%0A%09%7D%0A%0A%09public static boolean isTypeSerializer(Class%3C?%3E type) %7B%0A%09%09if (type.isPrimitive()) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09else if (type.equals(Model.class)) %7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09else if (type.getSuperclass() != null) %7B%0A%09%09%09return isModel(type.getSuperclass());%0A%09%09%7D%0A%0A%09%09return false
+return isSubclassOf(type, Model.class);%0A%09%7D%0A%0A%09public static boolean isTypeSerializer(Class%3C?%3E type) %7B%0A%09%09return isSubclassOf(type, TypeSerializer.class)
 ;%0A%09%7D
@@ -1385,61 +1385,62 @@
 ype.
-isPrimitive()) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09else if (type
+getSuperclass() != null) %7B%0A%09%09%09if (type.getSuperclass()
 .equ
@@ -1457,24 +1457,25 @@
 lass)) %7B%0A%09%09%09
+%09
 return true;
@@ -1479,54 +1479,13 @@
 ue;%0A
+%09
 %09%09%7D%0A
-%09%09else if (type.getSuperclass() != null) %7B
 %0A%09%09%09

Fix isSubclassOf method