private static int compare(Constraint constraint, Class<?> type,
			Object compare, Object compareTo) throws ConfException {

		Class<?>[] compareToArgsTypes = { type };

		// let's try static comapre(x, y) on creatorType
		Class<?>[] compareArgsTypes = { type, type };

		Class<?> comparatorType;

		if (constraint.comparator() != None.class) {
			comparatorType = constraint.comparator();
		} else {
			comparatorType = FactoryRegistry.getFactoryType(type);
		}

		try {
			Method comparator = ReflectUtils.getMethod(comparatorType, COMPARE,
					compareArgsTypes);

			if (ReflectUtils.isFieldAssignableFrom(int.class, comparator)) {
				return (Integer) comparator.invoke(null, compare, compareTo);
			}

		} catch (Exception e) {
			Logger.fine("Cannot invoke static compare(x,y) for type %s",
					type.getName());
		}

		Exception cause = null;

		// no luck, let's try compareTo!
		try {
			Method comparatorTo = ReflectUtils.getMethod(type, COMPARE_TO,
					compareToArgsTypes);

			if (ReflectUtils.isFieldAssignableFrom(int.class, comparatorTo)) {
				return (Integer) comparatorTo.invoke(compare, compareTo);
			}
		} catch (Exception e) {
			Logger.fine("Cannot invoke compareTo for type %s", type.getName());
			cause = e;
		}

		throw new ConfException(cause, "Cannot compare type %s", type.getName());

	}