Param wadlParam = _wadlGenerator.createParam(r, m, p);
return wadlParam;
}
private Resource generateResource(AbstractResource r, String path, Set<Class<?>> visitedClasses) {
Resource wadlResource = _wadlGenerator.createResource( r, path );
// prevent infinite recursion
if (visitedClasses.contains(r.getResourceClass()))
return wadlResource;
else
visitedClasses.add(r.getResourceClass());
// for each resource method
Map<String, Param> wadlResourceParams = new HashMap<String, Param>();
for (AbstractResourceMethod m : r.getResourceMethods()) {
com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlResourceParams, m);
wadlResource.getMethodOrResource().add(wadlMethod);
}
// add parameters that are associated with the resource PATH template
for (Param wadlParam : wadlResourceParams.values()) {
wadlResource.getParam().add(wadlParam);
}
// for each sub-resource method
Map<String, Resource> wadlSubResources = new HashMap<String, Resource>();
Map<String, Map<String, Param>> wadlSubResourcesParams =
new HashMap<String, Map<String, Param>>();
for (AbstractSubResourceMethod m : r.getSubResourceMethods()) {
// find or create sub resource for uri template
String template = m.getPath().getValue();
Resource wadlSubResource = wadlSubResources.get(template);
Map<String, Param> wadlSubResourceParams = wadlSubResourcesParams.get(template);
if (wadlSubResource == null) {
wadlSubResource = new Resource();
wadlSubResource.setPath(template);
wadlSubResources.put(template, wadlSubResource);
wadlSubResourceParams = new HashMap<String, Param>();
wadlSubResourcesParams.put(template, wadlSubResourceParams);
wadlResource.getMethodOrResource().add(wadlSubResource);
}
com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlSubResourceParams, m);
wadlSubResource.getMethodOrResource().add(wadlMethod);
}
// add parameters that are associated with each sub-resource method PATH template
for (Map.Entry<String, Resource> e : wadlSubResources.entrySet()) {
String template = e.getKey();
Resource wadlSubResource = e.getValue();
Map<String, Param> wadlSubResourceParams = wadlSubResourcesParams.get(template);
for (Param wadlParam : wadlSubResourceParams.values()) {
wadlSubResource.getParam().add(wadlParam);
}
}
// for each sub resource locator
for (AbstractSubResourceLocator l : r.getSubResourceLocators()) {
AbstractResource subResource = IntrospectionModeller.createResource(
l.getMethod().getReturnType());
Resource wadlSubResource = generateResource(subResource,
l.getPath().getValue(), visitedClasses);
wadlResource.getMethodOrResource().add(wadlSubResource);
for (Parameter p : l.getParameters()) {
Param wadlParam = generateParam(r, l, p);
if (wadlParam != null && wadlParam.getStyle()==ParamStyle.TEMPLATE)
wadlSubResource.getParam().add(wadlParam);
}
}
return wadlResource;
}