if (containsSafe(visitedInterfaces, clazz)) {
return;
}
visitedInterfaces.add(clazz);
if (!clazz.isInterface()) {
throw new JsonProtocolModelParseException(
"Parser root type must be an interface: " + clazz);
}
JsonParserRoot jsonParserRoot = clazz.getAnnotation(JsonParserRoot.class);
if (jsonParserRoot == null) {
throw new JsonProtocolModelParseException(
JsonParserRoot.class.getCanonicalName() + " annotation is expected in " + clazz);
}
for (Method m : clazz.getMethods()) {
JsonParseMethod jsonParseMethod = m.getAnnotation(JsonParseMethod.class);
if (jsonParseMethod == null) {
throw new JsonProtocolModelParseException(
JsonParseMethod.class.getCanonicalName() + " annotation is expected in " + clazz);
}
Class<?>[] exceptionTypes = m.getExceptionTypes();
if (exceptionTypes.length > 1) {
throw new JsonProtocolModelParseException("Too many exception declared in " + m);
}
if (exceptionTypes.length < 1 || exceptionTypes[0] != JsonProtocolParseException.class) {
throw new JsonProtocolModelParseException(
JsonProtocolParseException.class.getCanonicalName() +
" exception must be declared in " + m);
}
Type returnType = m.getGenericReturnType();
TypeHandler<?> typeHandler = type2TypeHandler.get(returnType);
if (typeHandler == null) {
throw new JsonProtocolModelParseException("Unknown return type in " + m);
}
Type[] arguments = m.getGenericParameterTypes();
if (arguments.length != 1) {
throw new JsonProtocolModelParseException("Exactly one argument is expected in " + m);
}
Type argument = arguments[0];
MethodDelegate delegate;
if (argument == JSONObject.class) {
delegate = new ParseDelegate(typeHandler);
} else if (argument == Object.class) {
delegate = new ParseDelegate(typeHandler);
} else {
throw new JsonProtocolModelParseException("Unrecognized argument type in " + m);
}
methodMap.put(m, delegate);
}
for (Type baseType : clazz.getGenericInterfaces()) {
if (baseType instanceof Class == false) {
throw new JsonProtocolModelParseException("Base interface must be class in " + clazz);
}
Class<?> baseClass = (Class<?>) baseType;
parseInterfaceRecursive(baseClass);
}
}