}
for (Method method : resourceClass.getMethods())
{
Path subPath = getMethodAnnotation(method, resourceClass, Path.class, false);
HttpMethod httpMethod = getMethodAnnotation(method, resourceClass, HttpMethod.class, true);
if (subPath != null || httpMethod != null)
{
List<MethodParameter> params = createMethodParametersList(resourceClass, method);
if (httpMethod != null)
{
Produces p = getMethodAnnotation(method, resourceClass, Produces.class, false);
if (p == null)
p = resourceClass.getAnnotation(Produces.class); // from resource
// class
List<MediaType> produces = MediaTypeHelper.createProducesList(p);
Consumes c = getMethodAnnotation(method, resourceClass, Consumes.class, false);
if (c == null)
c = resourceClass.getAnnotation(Consumes.class); // from resource
// class
List<MediaType> consumes = MediaTypeHelper.createConsumesList(c);
if (subPath == null)
{
// resource method
ResourceMethodDescriptor res =
new ResourceMethodDescriptorImpl(method, httpMethod.value(), params, this, consumes, produces,
new DefaultMethodInvoker());
ResourceMethodDescriptor exist =
findMethodResourceMediaType(resourceMethods.getList(httpMethod.value()), res.consumes(), res
.produces());
if (exist == null)
{
resourceMethods.add(httpMethod.value(), res);
}
else
{
String msg =
"Two resource method " + res + " and " + exist
+ " with the same HTTP method, consumes and produces found.";
throw new RuntimeException(msg);
}
}
else
{
// sub-resource method
SubResourceMethodDescriptor subRes =
new SubResourceMethodDescriptorImpl(new PathValue(subPath.value()), method, httpMethod.value(),
params, this, consumes, produces, new DefaultMethodInvoker());
SubResourceMethodDescriptor exist = null;
ResourceMethodMap<SubResourceMethodDescriptor> rmm =
(ResourceMethodMap<SubResourceMethodDescriptor>)subResourceMethods.getMethodMap(subRes
.getUriPattern());
// rmm is never null, empty map instead
List<SubResourceMethodDescriptor> l = rmm.getList(httpMethod.value());
exist =
(SubResourceMethodDescriptor)findMethodResourceMediaType(l, subRes.consumes(), subRes.produces());
if (exist == null)
{
rmm.add(httpMethod.value(), subRes);
}
else
{
String msg =
"Two sub-resource method " + subRes + " and " + exist