@Test public void testBuildResourceWithMock() throws Exception { WADLGenerator generator = new WADLGenerator(); Mockery mockContext = new Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); } }; final ClassMetadata metadata = mockContext.mock(ClassMetadata.class); final MethodMetadata methodMeta = mockContext.mock(MethodMetadata.class); final java.lang.reflect.Method method = BasicResourceWithVoidReturn.class.getMethod("basicReturn"); mockContext.checking(new Expectations() { { oneOf(metadata).getResourceClass(); will(returnValue(BasicResourceWithVoidReturn.class)); oneOf(metadata).getPath(); will(returnValue("myResourcePath")); oneOf(metadata).getResourceMethods(); will(returnValue(Collections.singletonList(methodMeta))); oneOf(methodMeta).getHttpMethod(); will(returnValue(HttpMethod.GET)); oneOf(methodMeta).getFormalParameters(); will(returnValue(Collections.emptyList())); oneOf(methodMeta).getProduces(); will(returnValue(Collections.emptySet())); exactly(2).of(methodMeta).getReflectionMethod(); will(returnValue(method)); oneOf(methodMeta).getFormalParameters(); will(returnValue(null)); oneOf(metadata).getInjectableFields(); will(returnValue(null)); oneOf(metadata).getSubResourceMethods(); will(returnValue(null)); oneOf(metadata).getSubResourceLocators(); will(returnValue(null)); } }); Resource actualRes = generator.buildResource(metadata); assertNull(actualRes.getId()); assertEquals(MediaType.APPLICATION_FORM_URLENCODED, actualRes.getQueryType()); assertEquals(0, actualRes.getType().size()); assertEquals(0, actualRes.getDoc().size()); assertEquals("myResourcePath", actualRes.getPath()); assertEquals(0, actualRes.getParam().size()); assertEquals(1, actualRes.getMethodOrResource().size()); Method m = ((Method)actualRes.getMethodOrResource().get(0)); assertEquals(HttpMethod.GET, m.getName()); assertNull(m.getId()); assertEquals(0, m.getDoc().size()); assertNull(m.getHref()); assertNull(m.getRequest()); assertEquals(1, m.getResponse().size()); List<Response> resps = m.getResponse(); assertEquals(Collections.singletonList(Long.valueOf(204)), resps.get(0).getStatus()); assertEquals(0, resps.get(0).getAny().size()); assertEquals(0, resps.get(0).getDoc().size()); assertEquals(0, resps.get(0).getOtherAttributes().size()); assertEquals(0, resps.get(0).getParam().size()); mockContext.assertIsSatisfied(); }
Resource buildResource(ClassMetadata metadata) { Resource r = new Resource(); if (metadata != null) { Class<?> resClass = metadata.getResourceClass(); if (resClass != null) { WADLDoc d = resClass.getAnnotation(WADLDoc.class); if (d != null) { r.getDoc().add(getDocument(d)); } } } String path = metadata.getPath(); if (path == null) { Class<?> resClass = metadata.getResourceClass(); if (DynamicResource.class.isAssignableFrom(resClass)) { try { DynamicResource dynRes = (DynamicResource)resClass.newInstance(); path = dynRes.getPath(); } catch (Exception e) { } } } UriTemplateProcessor processor = JaxRsUriTemplateProcessor.newNormalizedInstance(path); String pathStr = processor.getTemplate(); for (String var : processor.getVariableNames()) { pathStr = pathStr.replaceAll("\\{(\\s)*" + var + "(\\s)*:.*\\}", "{" + var + "}"); } r.setPath(pathStr); List<Object> methodOrSubresource = r.getMethodOrResource(); List<Param> resourceParams = r.getParam(); List<MethodMetadata> methodMetadata = metadata.getResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Method m = buildMethod(metadata, methodMeta); methodOrSubresource.add(m); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } } } List<Injectable> fields = metadata.getInjectableFields(); if (fields != null) { for (Injectable p : metadata.getInjectableFields()) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: resourceParams.add(buildParam(p)); break; case HEADER: resourceParams.add(buildParam(p)); break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } methodMetadata = metadata.getSubResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); Method m = buildMethod(metadata, methodMeta); subRes.getMethodOrResource().add(m); subRes.setPath(methodMeta.getPath()); methodOrSubresource.add(subRes); List<Param> subResParams = subRes.getParam(); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } methodMetadata = metadata.getSubResourceLocators(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); subRes.setPath(methodMeta.getPath()); if (methodMeta != null) { java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); if (d != null) { subRes.getDoc().add(getDocument(d)); } } } methodOrSubresource.add(subRes); List<Injectable> params = methodMeta.getFormalParameters(); List<Param> subResParams = subRes.getParam(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case HEADER: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } return r; }
WADLGenerator { Resource buildResource(ClassMetadata metadata) { Resource r = new Resource(); if (metadata != null) { Class<?> resClass = metadata.getResourceClass(); if (resClass != null) { WADLDoc d = resClass.getAnnotation(WADLDoc.class); if (d != null) { r.getDoc().add(getDocument(d)); } } } String path = metadata.getPath(); if (path == null) { Class<?> resClass = metadata.getResourceClass(); if (DynamicResource.class.isAssignableFrom(resClass)) { try { DynamicResource dynRes = (DynamicResource)resClass.newInstance(); path = dynRes.getPath(); } catch (Exception e) { } } } UriTemplateProcessor processor = JaxRsUriTemplateProcessor.newNormalizedInstance(path); String pathStr = processor.getTemplate(); for (String var : processor.getVariableNames()) { pathStr = pathStr.replaceAll("\\{(\\s)*" + var + "(\\s)*:.*\\}", "{" + var + "}"); } r.setPath(pathStr); List<Object> methodOrSubresource = r.getMethodOrResource(); List<Param> resourceParams = r.getParam(); List<MethodMetadata> methodMetadata = metadata.getResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Method m = buildMethod(metadata, methodMeta); methodOrSubresource.add(m); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } } } List<Injectable> fields = metadata.getInjectableFields(); if (fields != null) { for (Injectable p : metadata.getInjectableFields()) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: resourceParams.add(buildParam(p)); break; case HEADER: resourceParams.add(buildParam(p)); break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } methodMetadata = metadata.getSubResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); Method m = buildMethod(metadata, methodMeta); subRes.getMethodOrResource().add(m); subRes.setPath(methodMeta.getPath()); methodOrSubresource.add(subRes); List<Param> subResParams = subRes.getParam(); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } methodMetadata = metadata.getSubResourceLocators(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); subRes.setPath(methodMeta.getPath()); if (methodMeta != null) { java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); if (d != null) { subRes.getDoc().add(getDocument(d)); } } } methodOrSubresource.add(subRes); List<Injectable> params = methodMeta.getFormalParameters(); List<Param> subResParams = subRes.getParam(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case HEADER: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } return r; } }
WADLGenerator { Resource buildResource(ClassMetadata metadata) { Resource r = new Resource(); if (metadata != null) { Class<?> resClass = metadata.getResourceClass(); if (resClass != null) { WADLDoc d = resClass.getAnnotation(WADLDoc.class); if (d != null) { r.getDoc().add(getDocument(d)); } } } String path = metadata.getPath(); if (path == null) { Class<?> resClass = metadata.getResourceClass(); if (DynamicResource.class.isAssignableFrom(resClass)) { try { DynamicResource dynRes = (DynamicResource)resClass.newInstance(); path = dynRes.getPath(); } catch (Exception e) { } } } UriTemplateProcessor processor = JaxRsUriTemplateProcessor.newNormalizedInstance(path); String pathStr = processor.getTemplate(); for (String var : processor.getVariableNames()) { pathStr = pathStr.replaceAll("\\{(\\s)*" + var + "(\\s)*:.*\\}", "{" + var + "}"); } r.setPath(pathStr); List<Object> methodOrSubresource = r.getMethodOrResource(); List<Param> resourceParams = r.getParam(); List<MethodMetadata> methodMetadata = metadata.getResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Method m = buildMethod(metadata, methodMeta); methodOrSubresource.add(m); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } } } List<Injectable> fields = metadata.getInjectableFields(); if (fields != null) { for (Injectable p : metadata.getInjectableFields()) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: resourceParams.add(buildParam(p)); break; case HEADER: resourceParams.add(buildParam(p)); break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } methodMetadata = metadata.getSubResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); Method m = buildMethod(metadata, methodMeta); subRes.getMethodOrResource().add(m); subRes.setPath(methodMeta.getPath()); methodOrSubresource.add(subRes); List<Param> subResParams = subRes.getParam(); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } methodMetadata = metadata.getSubResourceLocators(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); subRes.setPath(methodMeta.getPath()); if (methodMeta != null) { java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); if (d != null) { subRes.getDoc().add(getDocument(d)); } } } methodOrSubresource.add(subRes); List<Injectable> params = methodMeta.getFormalParameters(); List<Param> subResParams = subRes.getParam(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case HEADER: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } return r; }  }
WADLGenerator { Resource buildResource(ClassMetadata metadata) { Resource r = new Resource(); if (metadata != null) { Class<?> resClass = metadata.getResourceClass(); if (resClass != null) { WADLDoc d = resClass.getAnnotation(WADLDoc.class); if (d != null) { r.getDoc().add(getDocument(d)); } } } String path = metadata.getPath(); if (path == null) { Class<?> resClass = metadata.getResourceClass(); if (DynamicResource.class.isAssignableFrom(resClass)) { try { DynamicResource dynRes = (DynamicResource)resClass.newInstance(); path = dynRes.getPath(); } catch (Exception e) { } } } UriTemplateProcessor processor = JaxRsUriTemplateProcessor.newNormalizedInstance(path); String pathStr = processor.getTemplate(); for (String var : processor.getVariableNames()) { pathStr = pathStr.replaceAll("\\{(\\s)*" + var + "(\\s)*:.*\\}", "{" + var + "}"); } r.setPath(pathStr); List<Object> methodOrSubresource = r.getMethodOrResource(); List<Param> resourceParams = r.getParam(); List<MethodMetadata> methodMetadata = metadata.getResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Method m = buildMethod(metadata, methodMeta); methodOrSubresource.add(m); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } } } List<Injectable> fields = metadata.getInjectableFields(); if (fields != null) { for (Injectable p : metadata.getInjectableFields()) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: resourceParams.add(buildParam(p)); break; case HEADER: resourceParams.add(buildParam(p)); break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } methodMetadata = metadata.getSubResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); Method m = buildMethod(metadata, methodMeta); subRes.getMethodOrResource().add(m); subRes.setPath(methodMeta.getPath()); methodOrSubresource.add(subRes); List<Param> subResParams = subRes.getParam(); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } methodMetadata = metadata.getSubResourceLocators(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); subRes.setPath(methodMeta.getPath()); if (methodMeta != null) { java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); if (d != null) { subRes.getDoc().add(getDocument(d)); } } } methodOrSubresource.add(subRes); List<Injectable> params = methodMeta.getFormalParameters(); List<Param> subResParams = subRes.getParam(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case HEADER: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } return r; }  Application generate(String baseURI, Set<Class<?>> classes); }
WADLGenerator { Resource buildResource(ClassMetadata metadata) { Resource r = new Resource(); if (metadata != null) { Class<?> resClass = metadata.getResourceClass(); if (resClass != null) { WADLDoc d = resClass.getAnnotation(WADLDoc.class); if (d != null) { r.getDoc().add(getDocument(d)); } } } String path = metadata.getPath(); if (path == null) { Class<?> resClass = metadata.getResourceClass(); if (DynamicResource.class.isAssignableFrom(resClass)) { try { DynamicResource dynRes = (DynamicResource)resClass.newInstance(); path = dynRes.getPath(); } catch (Exception e) { } } } UriTemplateProcessor processor = JaxRsUriTemplateProcessor.newNormalizedInstance(path); String pathStr = processor.getTemplate(); for (String var : processor.getVariableNames()) { pathStr = pathStr.replaceAll("\\{(\\s)*" + var + "(\\s)*:.*\\}", "{" + var + "}"); } r.setPath(pathStr); List<Object> methodOrSubresource = r.getMethodOrResource(); List<Param> resourceParams = r.getParam(); List<MethodMetadata> methodMetadata = metadata.getResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Method m = buildMethod(metadata, methodMeta); methodOrSubresource.add(m); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } } } List<Injectable> fields = metadata.getInjectableFields(); if (fields != null) { for (Injectable p : metadata.getInjectableFields()) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: resourceParams.add(buildParam(p)); break; case HEADER: resourceParams.add(buildParam(p)); break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : resourceParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { resourceParams.add(param); } break; case CONTEXT: break; } } } methodMetadata = metadata.getSubResourceMethods(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); Method m = buildMethod(metadata, methodMeta); subRes.getMethodOrResource().add(m); subRes.setPath(methodMeta.getPath()); methodOrSubresource.add(subRes); List<Param> subResParams = subRes.getParam(); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: break; case HEADER: break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } methodMetadata = metadata.getSubResourceLocators(); if (methodMetadata != null && !methodMetadata.isEmpty()) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); subRes.setPath(methodMeta.getPath()); if (methodMeta != null) { java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); if (d != null) { subRes.getDoc().add(getDocument(d)); } } } methodOrSubresource.add(subRes); List<Injectable> params = methodMeta.getFormalParameters(); List<Param> subResParams = subRes.getParam(); if (params != null && params.size() > 0) { for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case HEADER: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case ENTITY: break; case COOKIE: break; case FORM: break; case PATH: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case MATRIX: param = buildParam(p); for (Param rParam : subResParams) { if (param.getName() != null && param.getName().equals(rParam .getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { subRes.getParam().add(param); } break; case CONTEXT: break; } } } } } return r; }  Application generate(String baseURI, Set<Class<?>> classes);  }