From cc61894c659b2b90ee1bda303ba8b41eca70abf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pe=CC=81rez=20Garci=CC=81a?= Date: Sat, 25 May 2013 16:26:04 +0200 Subject: [PATCH] First commit, the play begins! --- .gitignore | 21 + LICENSE.txt | 202 ++++++ NOTICE.txt | 8 + README.md | 184 +++++ pom.xml | 241 +++++++ spring-wadl-generator/README.md | 24 + spring-wadl-generator/pom.xml | 109 +++ .../autentia/lang/AbstractClassMetadata.java | 41 ++ .../java/com/autentia/lang/ClassMetadata.java | 24 + .../autentia/lang/ClassMetadataFromClass.java | 37 + .../autentia/lang/ClassMetadataFromField.java | 39 ++ .../autentia/lang/ClassMetadataFromParam.java | 40 ++ .../lang/ClassMetadataFromReturnType.java | 39 ++ .../java/com/autentia/lang/ClassUtils.java | 50 ++ .../java/com/autentia/web/HttpMethod.java | 22 + .../autentia/web/HttpServletRequestUtils.java | 31 + .../rest/wadl/builder/ApplicationBuilder.java | 45 ++ .../rest/wadl/builder/ApplicationContext.java | 39 ++ .../web/rest/wadl/builder/IncludeBuilder.java | 40 ++ .../web/rest/wadl/builder/MethodBuilder.java | 41 ++ .../web/rest/wadl/builder/MethodContext.java | 52 ++ .../wadl/builder/MethodContextIterator.java | 24 + .../web/rest/wadl/builder/ParamBuilder.java | 84 +++ .../wadl/builder/RepresentationBuilder.java | 48 ++ .../web/rest/wadl/builder/RequestBuilder.java | 32 + .../rest/wadl/builder/ResourceBuilder.java | 48 ++ .../rest/wadl/builder/ResourcesBuilder.java | 44 ++ .../rest/wadl/builder/ResponseBuilder.java | 40 ++ .../springframework/SpringMethodContext.java | 70 ++ .../SpringMethodContextIterator.java | 59 ++ .../SpringWadlBuilderFactory.java | 47 ++ .../builder/namespace/GrammarsDiscoverer.java | 51 ++ .../namespace/QNameBuilderFactory.java | 54 ++ .../builder/namespace/QNameConstants.java | 97 +++ .../param/ParamFromAnnotationBuilder.java | 27 + .../ParamFromAnnotationBuilderCommons.java | 50 ++ .../ParamFromAnnotationBuilderFactory.java | 38 + .../param/ParamFromPathVariableBuilder.java | 41 ++ .../param/ParamFromRequestParamBuilder.java | 48 ++ .../autentia/xml/namespace/QNameBuilder.java | 118 ++++ .../autentia/xml/namespace/QNameMemory.java | 41 ++ .../xml/namespace/QNamePrefixesCache.java | 24 + .../autentia/xml/namespace/QNamesCache.java | 26 + .../cache/InMemoryQNamePrefixesCache.java | 36 + .../namespace/cache/InMemoryQNamesCache.java | 46 ++ .../com/autentia/xml/schema/ClassType.java | 39 ++ .../xml/schema/ClassTypeDiscoverer.java | 68 ++ .../xml/schema/ClassTypeInMemoryStore.java | 43 ++ .../schema/ClassTypeNotFoundException.java | 27 + .../autentia/xml/schema/CollectionType.java | 53 ++ .../xml/schema/FromFileClassType.java | 49 ++ .../autentia/xml/schema/SchemaBuilder.java | 35 + .../com/autentia/xml/schema/SingleType.java | 80 +++ .../java/dev/wadl/_2009/_02/Application.java | 344 +++++++++ .../java/net/java/dev/wadl/_2009/_02/Doc.java | 244 +++++++ .../net/java/dev/wadl/_2009/_02/Grammars.java | 246 +++++++ .../java/dev/wadl/_2009/_02/HTTPMethods.java | 66 ++ .../net/java/dev/wadl/_2009/_02/Include.java | 206 ++++++ .../net/java/dev/wadl/_2009/_02/Link.java | 331 +++++++++ .../net/java/dev/wadl/_2009/_02/Method.java | 413 +++++++++++ .../dev/wadl/_2009/_02/ObjectFactory.java | 166 +++++ .../net/java/dev/wadl/_2009/_02/Option.java | 290 ++++++++ .../net/java/dev/wadl/_2009/_02/Param.java | 658 ++++++++++++++++++ .../java/dev/wadl/_2009/_02/ParamStyle.java | 82 +++ .../dev/wadl/_2009/_02/Representation.java | 462 ++++++++++++ .../net/java/dev/wadl/_2009/_02/Request.java | 321 +++++++++ .../net/java/dev/wadl/_2009/_02/Resource.java | 491 +++++++++++++ .../java/dev/wadl/_2009/_02/ResourceType.java | 372 ++++++++++ .../java/dev/wadl/_2009/_02/Resources.java | 310 +++++++++ .../net/java/dev/wadl/_2009/_02/Response.java | 371 ++++++++++ .../java/dev/wadl/_2009/_02/package-info.java | 37 + .../main/resources/META-INF/sun-jaxb.episode | 65 ++ .../src/main/resources/basicCollections.xsd | 83 +++ .../src/main/resources/wadl.xsd | 283 ++++++++ .../test/java/com/autentia/dummy/Address.java | 22 + .../dummy/AddressInMultipleLines.java | 45 ++ .../com/autentia/dummy/AddressInOneLine.java | 40 ++ .../test/java/com/autentia/dummy/Contact.java | 41 ++ .../com/autentia/dummy/ContactAnnotated.java | 63 ++ .../ContactAnnotatedWithDifferentName.java | 50 ++ .../ContactWhichAttributeIsAnInterface.java | 93 +++ .../java/com/autentia/dummy/JavaMethod.java | 61 ++ .../src/test/java/com/autentia/dummy/Xxx.java | 20 + .../test/java/com/autentia/dummy/Xxxo.java | 20 + .../lang/ClassMetadataForCollectionsTest.java | 66 ++ .../lang/ClassMetadataForSingleTypesTest.java | 57 ++ .../com/autentia/lang/ClassUtilsTest.java | 78 +++ .../java/com/autentia/lang/DummyClass.java | 35 + .../rest/wadl/builder/IncludeBuilderTest.java | 49 ++ .../rest/wadl/builder/ParamBuilderTest.java | 100 +++ .../builder/RepresentationBuilderTest.java | 55 ++ .../namespace/GrammarsDiscovererTest.java | 84 +++ .../QNameBuilderForBasicTypesTest.java | 75 ++ .../QNameBuilderForComplexTypesTest.java | 88 +++ .../xml/schema/ClassTypeDiscovererTest.java | 70 ++ .../xml/schema/CollectionTypeTest.java | 39 ++ .../xml/schema/SchemaBuilderTest.java | 47 ++ .../autentia/xml/schema/SingleTypeTest.java | 56 ++ .../src/test/resources/logback-test.xml | 34 + spring-wadl-showcase/README.md | 29 + spring-wadl-showcase/pom.xml | 64 ++ .../showcase/contacts/AddressBook.java | 72 ++ .../autentia/showcase/contacts/Contact.java | 61 ++ .../rest/contacts/AddressBookController.java | 77 ++ .../web/rest/contacts/AppRestConstants.java | 28 + .../web/rest/contacts/EchoController.java | 42 ++ .../web/rest/wadl/WadlController.java | 69 ++ .../src/main/resources/logback.xml | 34 + .../webapp/WEB-INF/applicationContext.xml | 31 + .../WEB-INF/spring-wadl-showcase-servlet.xml | 34 + .../src/main/webapp/WEB-INF/web.xml | 60 ++ .../src/main/webapp/index.jsp | 22 + src/main/config/copyrightHeader.txt | 13 + wadl-packaging/README.md | 6 + wadl-packaging/pom.xml | 19 + .../wadl-zipper-maven-plugin/README.md | 52 ++ .../wadl-zipper-maven-plugin/pom.xml | 63 ++ .../autentia/maven/plugin/WadlZipperMojo.java | 59 ++ wadl-packaging/wadl-zipper/README.md | 4 + wadl-packaging/wadl-zipper/pom.xml | 30 + .../wadl/zipper/GrammarsUrisExtractor.java | 67 ++ .../web/rest/wadl/zipper/HttpClient.java | 33 + .../web/rest/wadl/zipper/WadlZipper.java | 85 +++ .../autentia/web/rest/wadl/zipper/Zip.java | 58 ++ .../zipper/GrammarsUrisExtractorTest.java | 43 ++ .../web/rest/wadl/zipper/WadlZipperTest.java | 68 ++ wadl-packaging/wadl-zipper/wadl.zip | Bin 0 -> 22 bytes 127 files changed, 11368 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 NOTICE.txt create mode 100644 README.md create mode 100644 pom.xml create mode 100644 spring-wadl-generator/README.md create mode 100644 spring-wadl-generator/pom.xml create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/AbstractClassMetadata.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadata.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromClass.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromField.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromParam.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromReturnType.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/lang/ClassUtils.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/HttpMethod.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/HttpServletRequestUtils.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationContext.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/IncludeBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContext.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContextIterator.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ParamBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RepresentationBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RequestBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourceBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourcesBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResponseBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContext.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContextIterator.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringWadlBuilderFactory.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/GrammarsDiscoverer.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameBuilderFactory.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameConstants.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderCommons.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderFactory.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromPathVariableBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromRequestParamBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameMemory.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamePrefixesCache.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamesCache.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamePrefixesCache.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamesCache.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassType.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeDiscoverer.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeInMemoryStore.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeNotFoundException.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/CollectionType.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/FromFileClassType.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/SchemaBuilder.java create mode 100644 spring-wadl-generator/src/main/java/com/autentia/xml/schema/SingleType.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Application.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Doc.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Grammars.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/HTTPMethods.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Include.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Link.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Method.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/ObjectFactory.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Option.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Param.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/ParamStyle.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Representation.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Request.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Resource.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/ResourceType.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Resources.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Response.java create mode 100644 spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/package-info.java create mode 100644 spring-wadl-generator/src/main/resources/META-INF/sun-jaxb.episode create mode 100644 spring-wadl-generator/src/main/resources/basicCollections.xsd create mode 100644 spring-wadl-generator/src/main/resources/wadl.xsd create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/Address.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/AddressInMultipleLines.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/AddressInOneLine.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/Contact.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/ContactAnnotated.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/ContactAnnotatedWithDifferentName.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/ContactWhichAttributeIsAnInterface.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/JavaMethod.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/Xxx.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/dummy/Xxxo.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/lang/ClassMetadataForCollectionsTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/lang/ClassMetadataForSingleTypesTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/lang/ClassUtilsTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/lang/DummyClass.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/web/rest/wadl/builder/IncludeBuilderTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/web/rest/wadl/builder/ParamBuilderTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/web/rest/wadl/builder/RepresentationBuilderTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/web/rest/wadl/builder/namespace/GrammarsDiscovererTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/web/rest/wadl/builder/namespace/QNameBuilderForBasicTypesTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/web/rest/wadl/builder/namespace/QNameBuilderForComplexTypesTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/xml/schema/ClassTypeDiscovererTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/xml/schema/CollectionTypeTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/xml/schema/SchemaBuilderTest.java create mode 100644 spring-wadl-generator/src/test/java/com/autentia/xml/schema/SingleTypeTest.java create mode 100644 spring-wadl-generator/src/test/resources/logback-test.xml create mode 100644 spring-wadl-showcase/README.md create mode 100644 spring-wadl-showcase/pom.xml create mode 100644 spring-wadl-showcase/src/main/java/com/autentia/showcase/contacts/AddressBook.java create mode 100644 spring-wadl-showcase/src/main/java/com/autentia/showcase/contacts/Contact.java create mode 100644 spring-wadl-showcase/src/main/java/com/autentia/showcase/web/rest/contacts/AddressBookController.java create mode 100644 spring-wadl-showcase/src/main/java/com/autentia/showcase/web/rest/contacts/AppRestConstants.java create mode 100644 spring-wadl-showcase/src/main/java/com/autentia/showcase/web/rest/contacts/EchoController.java create mode 100644 spring-wadl-showcase/src/main/java/com/autentia/showcase/web/rest/wadl/WadlController.java create mode 100644 spring-wadl-showcase/src/main/resources/logback.xml create mode 100644 spring-wadl-showcase/src/main/webapp/WEB-INF/applicationContext.xml create mode 100644 spring-wadl-showcase/src/main/webapp/WEB-INF/spring-wadl-showcase-servlet.xml create mode 100644 spring-wadl-showcase/src/main/webapp/WEB-INF/web.xml create mode 100644 spring-wadl-showcase/src/main/webapp/index.jsp create mode 100644 src/main/config/copyrightHeader.txt create mode 100644 wadl-packaging/README.md create mode 100644 wadl-packaging/pom.xml create mode 100644 wadl-packaging/wadl-zipper-maven-plugin/README.md create mode 100644 wadl-packaging/wadl-zipper-maven-plugin/pom.xml create mode 100644 wadl-packaging/wadl-zipper-maven-plugin/src/main/java/com/autentia/maven/plugin/WadlZipperMojo.java create mode 100644 wadl-packaging/wadl-zipper/README.md create mode 100644 wadl-packaging/wadl-zipper/pom.xml create mode 100644 wadl-packaging/wadl-zipper/src/main/java/com/autentia/web/rest/wadl/zipper/GrammarsUrisExtractor.java create mode 100644 wadl-packaging/wadl-zipper/src/main/java/com/autentia/web/rest/wadl/zipper/HttpClient.java create mode 100644 wadl-packaging/wadl-zipper/src/main/java/com/autentia/web/rest/wadl/zipper/WadlZipper.java create mode 100644 wadl-packaging/wadl-zipper/src/main/java/com/autentia/web/rest/wadl/zipper/Zip.java create mode 100644 wadl-packaging/wadl-zipper/src/test/java/com/autentia/web/rest/wadl/zipper/GrammarsUrisExtractorTest.java create mode 100644 wadl-packaging/wadl-zipper/src/test/java/com/autentia/web/rest/wadl/zipper/WadlZipperTest.java create mode 100644 wadl-packaging/wadl-zipper/wadl.zip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..890f4e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# Maven output directory. +target/ + +# Eclipse configuration. +.metadata/ +.project +.settings/ +.classpath + +# IntelliJ configuration. +.idea/ +*.iml + +# vi backups. +*.swp + +# gitk temporary files. +/.gitk*/ + +# Mac files. +.DS_Store diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 0000000..b1da1ca --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,8 @@ + Autentia WADL Tools + Copyright 2013 Autentia Real Business Solution S.L. + + This product includes software developed at: + + - The Apache Software Foundation (http://www.apache.org/). + + - SpringSource (http://www.springsource.org/). diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ea8dad --- /dev/null +++ b/README.md @@ -0,0 +1,184 @@ +spring-wadl +=========== + +Introduction +------------ + +This project is a library to generate the WADL of several REST services implemented with Spring Web MVC. + +Some of the features that make interesting this project are: + + * Very **easy to integrate** in your already Spring Web MVC project. + + * Very **low intrusive** with your actual code. Just add one controllers and all is working. + + * Capable of **generate automatically the grammars sections of the WADL**, and the corresponding schemas for the + complex types of your REST services. Just adding one standard JAXB annotation in the complex types of your REST + services. + + * **Manages automatically simple types**, like strings, integers, booleans, ... **and collections** of these simple + types. + + +In this project you can find the next subprojects: + + * **spring-wadl-generator** - it's the library you need to add in the Maven dependencies of your project pom.xml. + + * **spring-wadl-showcase** - it's an example use of the library, where you can view how to configure the controllers, + the annotations, ... + + + +Installation +------------ + +### Download + +Right now we are not in the Maven central repository (we are working on it), so you have to clone the project and +install it in you local machine or your own Maven repository (Artifactory, Archiva, Nexus, or whatever other you use). + +But don't worry, it's very easy. In the command line, go to the directory where you want to install the project and +type: + + git clone ... + cd spring-wadl-generator + mvn clean install + +If you have any problem, be sure you have installed correctly: +[Java](http://www.oracle.com/technetwork/java/javase/downloads/index.html), +[Maven](http://maven.apache.org/), and [Git](http://git-scm.com/) + + + +### Add dependencies + +You need to modify the _dependencies_ section of your pom.xml and add: + +```xml +... + + ... + + com.autentia.web.rest + spring-wadl-generator + 1.0 + + ... + +... +``` + + + +### Add the Spring Web MVC Controllers + +Add the next class to your project: + +```java +package whatever.you.want; + +import com.autentia.web.rest.wadl.builder.ApplicationBuilder; +import com.autentia.web.rest.wadl.builder.impl.springframework.SpringWadlBuilderFactory; +import com.autentia.xml.schema.SchemaBuilder; +import net.java.dev.wadl._2009._02.Application; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; +import javax.servlet.http.HttpServletRequest; + +@Controller +@RequestMapping(value = "/rest", produces = {"application/xml"}) +public class WadlController { + + private final ApplicationBuilder applicationBuilder; + private final SchemaBuilder schemaBuilder; + + @Autowired + public WadlController(RequestMappingHandlerMapping handlerMapping) { + final SpringWadlBuilderFactory wadlBuilderFactory = new SpringWadlBuilderFactory(handlerMapping); + applicationBuilder = wadlBuilderFactory.getApplicationBuilder(); + schemaBuilder = wadlBuilderFactory.getSchemaBuilder(); + } + + @ResponseBody + @RequestMapping(value = "wadl", method = RequestMethod.GET) + public Application generateWadl(HttpServletRequest request) { + return applicationBuilder.build(request); + } + + @ResponseBody + @RequestMapping(value = "schema/{classTypeName}", method = RequestMethod.GET) + public String generateSchema(@PathVariable String classTypeName) { + return schemaBuilder.buildFor(classTypeName); + } + + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(IllegalArgumentException.class) + public void handleException() { + // Do nothing, just magic annotations. + } +} +``` + +Be sure this controller is in the Spring Web MVC context (maybe put in a package scanned by the context, or adding it +manually). + +Now the WADL generation should be working. With this example you can access it on: +**** + + + +### Schema of complex types + +JAXB is used to generate the schema for complex types. + +In the simple and common case, you can generate the schema for your complex types (the classes you use in your request +or responses) just annotating the classes with `@XmlAccessorType(XmlAccessType.FIELD)` and `@XmlRootElement`. +For example: + +```java +... +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement +public class Contact { + + private final String id; + private final String name; + private final String email; + ... +``` + +In more complex cases you can use any other JAXB annotations in whatever way you want. + + + +Generating WADL on compilation time +----------------------------------- + +We show how to configure our projects to access the WADL in runtime like any other resource on our REST API. But +sometimes is either not desirable, or impossible (imagine you have to send the development version of your WADL to some +partner or colleague that don't have access to your development network). + +In this cases we can generate the WADL on compilation time, and afterwards send it by the way we want. + +To view how to do this, check the projects under **wadl-packaging**. + + + +URLs of interest +---------------- + + * W3C XML Schema Definition Language (XSD) 1.1 Part 1: Structures --> + + * XML Schema Patterns for Common Data Structures --> + + * JAXB annotations + + * Unofficial JAXB Guide --> diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9ef86dd --- /dev/null +++ b/pom.xml @@ -0,0 +1,241 @@ + + + + 4.0.0 + + com.autentia.web.rest + wadl-tools + 1.0-SNAPSHOT + pom + + 2013 + + Autentia Real Business S.L. + http://www.autentia.com + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + manual + + + + + spring-wadl-generator + spring-wadl-showcase + wadl-packaging + + + + UTF-8 + 3.2.2.RELEASE + 0.6.4 + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.14 + + + integration-test + + integration-test + + + + verify + + verify + + + + + + + org.mortbay.jetty + jetty-maven-plugin + 8.1.10.v20130312 + + 2 + 9999 + stop + + + + + + + + + + start-jetty + pre-integration-test + + + start + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + + + + + + com.mycila.maven-license-plugin + maven-license-plugin + 1.10.b1 + false + +
${basedir}/src/main/config/copyrightHeader.txt
+ true + true + true + ${project.build.sourceEncoding} + + ${project.inceptionYear} + + + .idea/** + **/LICENSE.txt + **/NOTICE.txt + **/*.gitignore + **/*.markdown + **/*.md + **/sun-jaxb.episode + +
+ + + + check + + + +
+
+
+ + + + + commons-io + commons-io + 2.4 + + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.12 + + + + org.apache.httpcomponents + httpclient + 4.2.3 + + + + javax.servlet + servlet-api + 2.5 + provided + + + + ch.qos.logback + logback-classic + 1.0.11 + runtime + + + + + + + org.apache.commons + commons-lang3 + 3.1 + + + + org.slf4j + slf4j-api + 1.7.5 + + + + junit + junit + 4.11 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + + + org.mockito + mockito-core + 1.9.5 + test + + + + + + springsource-repo + SpringSource Repository + http://repo.springsource.org/release + + + +
diff --git a/spring-wadl-generator/README.md b/spring-wadl-generator/README.md new file mode 100644 index 0000000..4ef9c53 --- /dev/null +++ b/spring-wadl-generator/README.md @@ -0,0 +1,24 @@ +spring-wadl-generator +===================== + +Library you can use to generate WADL automatically from your Spring Web MVC application. + + + +Something about generation of code +---------------------------------- + +The classes used to build de WADL was generated automatically from the WADL schema. To do this was used de Maven plugin: +**maven-jaxb2-plugin**. + +After the generation, the classes was moved to _src/main/java_ and some tuning was made to them. For example to +change some namespaces, or add some features with commons-lang 3. + +This tuning should not be a problem, because WADL is a W3C specification, so it's not probable it will change. + +Anyway, if is necessary generate these classes again, could be done with: + + mvn jaxb2:generate + +This command will generate the classes on _target/generated-source_, and afterwards will be necessary to merge with the +code in _src/main/java_. Be careful with the merge to not destroy the tuning already done!!! diff --git a/spring-wadl-generator/pom.xml b/spring-wadl-generator/pom.xml new file mode 100644 index 0000000..61ca1e7 --- /dev/null +++ b/spring-wadl-generator/pom.xml @@ -0,0 +1,109 @@ + + + + 4.0.0 + + + com.autentia.web.rest + wadl-tools + 1.0-SNAPSHOT + + + spring-wadl-generator + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.8.3 + + + + + + + + + + 2.2 + false + + true + + -Xcommons-lang + -Xvalue-constructor + -Xfluent-api + + + + + org.jvnet.jaxb2_commons + jaxb2-commons-lang + 2.3 + + + org.jvnet.jaxb2_commons + jaxb2-value-constructor + 3.0 + + + org.jvnet.jaxb2_commons + jaxb2-fluent-api + 3.0 + + + + + + + + + + + commons-io + commons-io + + + + org.springframework + spring-webmvc + + + + org.codehaus.jackson + jackson-mapper-asl + + + + javax.servlet + servlet-api + + + + org.jvnet.jaxb2_commons + jaxb2-basics-runtime + ${jaxb2.version} + + + com.sun.xml.bind + jaxb-impl + 2.2.6 + + + + ch.qos.logback + logback-classic + test + + + + diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/AbstractClassMetadata.java b/spring-wadl-generator/src/main/java/com/autentia/lang/AbstractClassMetadata.java new file mode 100644 index 0000000..c5cb82a --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/AbstractClassMetadata.java @@ -0,0 +1,41 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +import static com.autentia.lang.ClassUtils.isArrayOrCollection; + +public abstract class AbstractClassMetadata implements ClassMetadata { + + @Override + public boolean isCollection() { + return isArrayOrCollection(getType()); + } + + @Override + public Class getComponentType() { + if (!isCollection()) { + throw new IllegalStateException("Cannot call this method because this metadata does not represent a collection. This metadata is for class: " + getType()); + } + + if (getType().isArray()) { + return getType().getComponentType(); + } + + return getActualType(); + } + + abstract Class getActualType(); +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadata.java b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadata.java new file mode 100644 index 0000000..67cdf19 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadata.java @@ -0,0 +1,24 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +public interface ClassMetadata { + boolean isCollection(); + + Class getType(); + + Class getComponentType(); +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromClass.java b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromClass.java new file mode 100644 index 0000000..c954553 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromClass.java @@ -0,0 +1,37 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +import static com.autentia.lang.ClassUtils.getElementsClassOf; + +public class ClassMetadataFromClass extends AbstractClassMetadata { + + private final Class clazz; + + public ClassMetadataFromClass(Class clazz) { + this.clazz = clazz; + } + + @Override + public Class getType() { + return clazz; + } + + @Override + Class getActualType() { + return getElementsClassOf(clazz); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromField.java b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromField.java new file mode 100644 index 0000000..7b6a612 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromField.java @@ -0,0 +1,39 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; + +public class ClassMetadataFromField extends AbstractClassMetadata { + + private final Field field; + + public ClassMetadataFromField(Field field) { + this.field = field; + } + + @Override + public Class getType() { + return field.getType(); + } + + @Override + Class getActualType() { + final ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType(); + return (Class) parameterizedType.getActualTypeArguments()[0]; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromParam.java b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromParam.java new file mode 100644 index 0000000..9c360ce --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromParam.java @@ -0,0 +1,40 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; + +public class ClassMetadataFromParam extends AbstractClassMetadata { + private final Method method; + private final int paramIndex; + + public ClassMetadataFromParam(Method method, int paramIndex) { + this.method = method; + this.paramIndex = paramIndex; + } + + @Override + public Class getType() { + return method.getParameterTypes()[paramIndex]; + } + + @Override + Class getActualType() { + final ParameterizedType parameterizedParamType = (ParameterizedType) method.getGenericParameterTypes()[paramIndex]; + return (Class) parameterizedParamType.getActualTypeArguments()[0]; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromReturnType.java b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromReturnType.java new file mode 100644 index 0000000..5a9012a --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassMetadataFromReturnType.java @@ -0,0 +1,39 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; + +public class ClassMetadataFromReturnType extends AbstractClassMetadata { + + private final Method method; + + public ClassMetadataFromReturnType(Method method) { + this.method = method; + } + + @Override + public Class getType() { + return method.getReturnType(); + } + + @Override + Class getActualType() { + final ParameterizedType parameterizedReturnType = (ParameterizedType) method.getGenericReturnType(); + return (Class) parameterizedReturnType.getActualTypeArguments()[0]; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/lang/ClassUtils.java b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassUtils.java new file mode 100644 index 0000000..a3c0a7a --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/lang/ClassUtils.java @@ -0,0 +1,50 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.lang; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; + +public final class ClassUtils { + + private static final Logger logger = LoggerFactory.getLogger(ClassUtils.class); + + private ClassUtils() { + // Private default constructor because we don't want instances of this class. + } + + public static boolean isArrayOrCollection(Class clazz) { + return clazz.isArray() || Collection.class.isAssignableFrom(clazz); + } + + public static Class getElementsClassOf(Class clazz) { + if (clazz.isArray()) { + return clazz.getComponentType(); + } + if (Collection.class.isAssignableFrom(clazz)) { + // TODO check for annotation + logger.warn("In Java its not possible to discover de Generic type of a collection like: {}", clazz); + return Object.class; + } + return clazz; + } + + public static boolean isVoid(Class clazz) { + return Void.class.equals(clazz) || void.class.equals(clazz); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/HttpMethod.java b/spring-wadl-generator/src/main/java/com/autentia/web/HttpMethod.java new file mode 100644 index 0000000..17a97bb --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/HttpMethod.java @@ -0,0 +1,22 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web; + +public enum HttpMethod { + + GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/HttpServletRequestUtils.java b/spring-wadl-generator/src/main/java/com/autentia/web/HttpServletRequestUtils.java new file mode 100644 index 0000000..162dc49 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/HttpServletRequestUtils.java @@ -0,0 +1,31 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web; + +import javax.servlet.http.HttpServletRequest; + +public final class HttpServletRequestUtils { + + private HttpServletRequestUtils() { + // Utility class, so instances are not allowed. + } + + public static String getBaseUrlOf(HttpServletRequest request) { + return request.getScheme() + "://" + request.getServerName() + ':' + request.getServerPort() + + request.getContextPath() + request.getServletPath(); + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationBuilder.java new file mode 100644 index 0000000..80324a7 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationBuilder.java @@ -0,0 +1,45 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.web.HttpServletRequestUtils; +import net.java.dev.wadl._2009._02.Application; +import net.java.dev.wadl._2009._02.Doc; +import net.java.dev.wadl._2009._02.Grammars; + +import javax.servlet.http.HttpServletRequest; + +public class ApplicationBuilder { + + private final ResourcesBuilder resourcesBuilder; + private final IncludeBuilder includeBuilder; + + public ApplicationBuilder(ApplicationContext ctx) { + resourcesBuilder = new ResourcesBuilder(ctx); + includeBuilder = new IncludeBuilder(ctx.getGrammarsDiscoverer()); + } + + public Application build(HttpServletRequest request) { + return build(HttpServletRequestUtils.getBaseUrlOf(request)); + } + + public Application build(String baseUrl) { + return new Application() + .withDoc(new Doc().withTitle("REST Service WADL")) + .withResources(resourcesBuilder.build(baseUrl)) + .withGrammars(new Grammars().withInclude(includeBuilder.build())); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationContext.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationContext.java new file mode 100644 index 0000000..8d03ee3 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ApplicationContext.java @@ -0,0 +1,39 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; + +public class ApplicationContext implements Iterable { + + private final MethodContextIterator methodContextIterator; + private final GrammarsDiscoverer grammarsDiscoverer; + + public ApplicationContext(MethodContextIterator methodContextIterator, GrammarsDiscoverer grammarsDiscoverer) { + this.methodContextIterator = methodContextIterator; + this.grammarsDiscoverer = grammarsDiscoverer; + } + + @Override + public MethodContextIterator iterator() { + methodContextIterator.initWith(this); + return methodContextIterator; + } + + public GrammarsDiscoverer getGrammarsDiscoverer() { + return grammarsDiscoverer; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/IncludeBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/IncludeBuilder.java new file mode 100644 index 0000000..c7d404a --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/IncludeBuilder.java @@ -0,0 +1,40 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import net.java.dev.wadl._2009._02.Include; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +class IncludeBuilder { + + private final GrammarsDiscoverer grammarsDiscoverer; + + IncludeBuilder(GrammarsDiscoverer grammarsDiscoverer) { + this.grammarsDiscoverer = grammarsDiscoverer; + } + + Collection build() { + final List includes = new ArrayList(); + for (String schemaUrl : grammarsDiscoverer.getSchemaUrlsForComplexTypes()) { + includes.add(new Include().withHref(schemaUrl)); + } + return includes; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodBuilder.java new file mode 100644 index 0000000..3c430f4 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodBuilder.java @@ -0,0 +1,41 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.web.HttpMethod; +import net.java.dev.wadl._2009._02.Method; + +import java.util.ArrayList; +import java.util.Collection; + +class MethodBuilder { + + final RequestBuilder requestBuilder = new RequestBuilder(); + final ResponseBuilder responseBuilder = new ResponseBuilder(); + + Collection build(MethodContext ctx) { + final Collection methods = new ArrayList(); + + for (HttpMethod httpMethod : ctx.getHttpMethods()) { + methods.add(new Method() + .withName(httpMethod.name()) + .withId(ctx.getJavaMethod().getName()) + .withRequest(requestBuilder.build(ctx)) + .withResponse(responseBuilder.build(ctx))); + } + return methods; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContext.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContext.java new file mode 100644 index 0000000..884a529 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContext.java @@ -0,0 +1,52 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.web.HttpMethod; +import org.springframework.http.MediaType; + +import java.lang.reflect.Method; +import java.util.Set; + +public abstract class MethodContext { + + private final ApplicationContext parentContext; + private ParamBuilder paramBuilder; + + protected MethodContext(ApplicationContext parentContext) { + this.parentContext = parentContext; + } + + ApplicationContext getParentContext() { + return parentContext; + } + + ParamBuilder getParamBuilder() { + return paramBuilder; + } + + void setParamBuilder(ParamBuilder paramBuilder) { + this.paramBuilder = paramBuilder; + } + + protected abstract String discoverPath(); + + protected abstract Method getJavaMethod(); + + protected abstract Set getHttpMethods(); + + protected abstract Set getMediaTypes(); +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContextIterator.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContextIterator.java new file mode 100644 index 0000000..10c61f2 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/MethodContextIterator.java @@ -0,0 +1,24 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import java.util.Iterator; + +public interface MethodContextIterator extends Iterator { + + void initWith(ApplicationContext parentContext); + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ParamBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ParamBuilder.java new file mode 100644 index 0000000..a6c7b58 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ParamBuilder.java @@ -0,0 +1,84 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.web.rest.wadl.builder.param.ParamFromAnnotationBuilder; +import com.autentia.web.rest.wadl.builder.param.ParamFromAnnotationBuilderFactory; +import net.java.dev.wadl._2009._02.Param; +import net.java.dev.wadl._2009._02.ParamStyle; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +class ParamBuilder { + + private final Method javaMethod; + private final ParamFromAnnotationBuilderFactory factory; + private List templateParams = new ArrayList(); + private List noTemplateParams = new ArrayList(); + private boolean allParametersAreBuilt = false; + + ParamBuilder(MethodContext ctx) { + javaMethod = ctx.getJavaMethod(); + factory = new ParamFromAnnotationBuilderFactory(ctx.getParentContext().getGrammarsDiscoverer()); + } + + List buildTemplateParams() { + buildAllParams(); + return templateParams; + } + + List buildNoTemplateParams() { + buildAllParams(); + return noTemplateParams; + } + + private void buildAllParams() { + if (allParametersAreBuilt) { + return; + } + + final Annotation[][] paramAnnotations = javaMethod.getParameterAnnotations(); + + for (int paramIndex = 0; paramIndex < paramAnnotations.length; paramIndex++) { + for (Annotation annotation : paramAnnotations[paramIndex]) { + final ParamFromAnnotationBuilder paramFromAnnotationBuilder = factory.builderFor(annotation); + if (paramFromAnnotationBuilder != null) { + classify(paramFromAnnotationBuilder.build(javaMethod, paramIndex, annotation)); + + // Each parameter is just of one style, so we can jump to the next parameter + break; + } + } + } + + templateParams = Collections.unmodifiableList(templateParams); + noTemplateParams = Collections.unmodifiableList(noTemplateParams); + allParametersAreBuilt = true; + } + + private void classify(Param param) { + if (param.getStyle() == ParamStyle.TEMPLATE) { + templateParams.add(param); + + } else { + noTemplateParams.add(param); + } + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RepresentationBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RepresentationBuilder.java new file mode 100644 index 0000000..3b7e4e4 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RepresentationBuilder.java @@ -0,0 +1,48 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import com.autentia.lang.ClassMetadataFromReturnType; +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import net.java.dev.wadl._2009._02.Representation; +import org.springframework.http.MediaType; + +import javax.xml.namespace.QName; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; + +import static com.autentia.lang.ClassUtils.isVoid; + +class RepresentationBuilder { + + Collection build(MethodContext ctx) { + final Collection representations = new ArrayList(); + final Method javaMethod = ctx.getJavaMethod(); + final GrammarsDiscoverer grammarsDiscoverer = ctx.getParentContext().getGrammarsDiscoverer(); + + for (MediaType mediaType : ctx.getMediaTypes()) { + final Class returnType = javaMethod.getReturnType(); + if (isVoid(returnType)) { + continue; + } + + final QName qName = grammarsDiscoverer.discoverQNameFor(new ClassMetadataFromReturnType(javaMethod)); + representations.add(new Representation().withMediaType(mediaType.toString()).withElement(qName)); + } + return representations; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RequestBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RequestBuilder.java new file mode 100644 index 0000000..acbd798 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/RequestBuilder.java @@ -0,0 +1,32 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import net.java.dev.wadl._2009._02.Param; +import net.java.dev.wadl._2009._02.Request; + +import java.util.Collections; + +class RequestBuilder { + + static final Request EMPTY_REQUEST = new Request().withParam(Collections.emptyList()); + + Request build(MethodContext ctx) { + final Request request = new Request().withParam(ctx.getParamBuilder().buildNoTemplateParams()); + return request.equals(EMPTY_REQUEST) ? null : request; + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourceBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourceBuilder.java new file mode 100644 index 0000000..376254e --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourceBuilder.java @@ -0,0 +1,48 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import net.java.dev.wadl._2009._02.Resource; + +import java.util.ArrayList; +import java.util.Collection; + +class ResourceBuilder { + + private final ApplicationContext applicationContext; + private final MethodBuilder methodBuilder = new MethodBuilder(); + + ResourceBuilder(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + Collection build() { + final Collection resources = new ArrayList(); + + for (MethodContext methodContext : applicationContext) { + methodContext.setParamBuilder(new ParamBuilder(methodContext)); + + resources.add(new Resource() + .withPath(methodContext.discoverPath()) + .withParam(methodContext.getParamBuilder().buildTemplateParams()) + // Cast to Collection because in other case Collection is resolved with withMethodOrResource(Object... values), + // and we want to resolve with withMethodOrResource(Collection values) + .withMethodOrResource((Collection) methodBuilder.build(methodContext))); + } + return resources; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourcesBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourcesBuilder.java new file mode 100644 index 0000000..0031cc7 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResourcesBuilder.java @@ -0,0 +1,44 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import net.java.dev.wadl._2009._02.Resources; + +import java.util.ArrayList; +import java.util.Collection; + +class ResourcesBuilder { + + private final ResourceBuilder resourceBuilder; + + ResourcesBuilder(ApplicationContext ctx) { + resourceBuilder = new ResourceBuilder(ctx); + } + + Collection build(String baseUrl) { + final Collection resourcesElements = new ArrayList(); + + /* + * By now just one 'resources' element is returned, but the method returns a collection + * because the specification supports several elements of this kind. + */ + resourcesElements.add(new Resources() + .withBase(baseUrl) + .withResource(resourceBuilder.build())); + + return resourcesElements; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResponseBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResponseBuilder.java new file mode 100644 index 0000000..6645903 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/ResponseBuilder.java @@ -0,0 +1,40 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder; + +import net.java.dev.wadl._2009._02.Response; + +import java.util.ArrayList; +import java.util.Collection; + +class ResponseBuilder { + + private static final long OK = 200L; + + private final RepresentationBuilder representationBuilder = new RepresentationBuilder(); + + Collection build(MethodContext ctx) { + final Collection responses = new ArrayList(); + /* + * By now just one 'response' element is returned, but the method returns a collection + * because the specification supports several elements of this kind. + */ + responses.add(new Response() + .withStatus(OK) + .withRepresentation(representationBuilder.build(ctx))); + return responses; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContext.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContext.java new file mode 100644 index 0000000..b4253f2 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContext.java @@ -0,0 +1,70 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.impl.springframework; + +import com.autentia.web.HttpMethod; +import com.autentia.web.rest.wadl.builder.ApplicationContext; +import com.autentia.web.rest.wadl.builder.MethodContext; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; + +import java.lang.reflect.Method; +import java.util.EnumSet; +import java.util.Set; + +class SpringMethodContext extends MethodContext { + + private final RequestMappingInfo mappingInfo; + private final HandlerMethod handlerMethod; + + SpringMethodContext(ApplicationContext parentContext, RequestMappingInfo mappingInfo, HandlerMethod handlerMethod) { + super(parentContext); + this.mappingInfo = mappingInfo; + this.handlerMethod = handlerMethod; + } + + @Override + protected String discoverPath() { + String path = null; + for (String uri : mappingInfo.getPatternsCondition().getPatterns()) { + path = uri; + } + return path; + } + + @Override + protected Method getJavaMethod() { + return handlerMethod.getMethod(); + } + + @Override + protected Set getHttpMethods() { + final Set httpMethods = EnumSet.noneOf(HttpMethod.class); + + for (RequestMethod requestMethod : mappingInfo.getMethodsCondition().getMethods()) { + httpMethods.add(HttpMethod.valueOf(requestMethod.name())); + } + return httpMethods; + } + + @Override + protected Set getMediaTypes() { + return mappingInfo.getProducesCondition().getProducibleMediaTypes(); + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContextIterator.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContextIterator.java new file mode 100644 index 0000000..d9381ae --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringMethodContextIterator.java @@ -0,0 +1,59 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.impl.springframework; + +import com.autentia.web.rest.wadl.builder.ApplicationContext; +import com.autentia.web.rest.wadl.builder.MethodContext; +import com.autentia.web.rest.wadl.builder.MethodContextIterator; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; + +import java.util.Iterator; +import java.util.Map; + +class SpringMethodContextIterator implements MethodContextIterator { + + private final RequestMappingHandlerMapping handlerMapping; + private Iterator> iterator; + private ApplicationContext parentContext; + + SpringMethodContextIterator(RequestMappingHandlerMapping handlerMapping) { + this.handlerMapping = handlerMapping; + } + + @Override + public void initWith(ApplicationContext parentContext) { + iterator = handlerMapping.getHandlerMethods().entrySet().iterator(); + this.parentContext = parentContext; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public MethodContext next() { + final Map.Entry next = iterator.next(); + return new SpringMethodContext(parentContext, next.getKey(), next.getValue()); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringWadlBuilderFactory.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringWadlBuilderFactory.java new file mode 100644 index 0000000..6c08653 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/impl/springframework/SpringWadlBuilderFactory.java @@ -0,0 +1,47 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.impl.springframework; + +import com.autentia.web.rest.wadl.builder.ApplicationBuilder; +import com.autentia.web.rest.wadl.builder.ApplicationContext; +import com.autentia.xml.schema.ClassTypeDiscoverer; +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import com.autentia.web.rest.wadl.builder.namespace.QNameBuilderFactory; +import com.autentia.xml.schema.SchemaBuilder; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; + +public class SpringWadlBuilderFactory { + + private final ApplicationBuilder applicationBuilder; + private final SchemaBuilder schemaBuilder; + + public SpringWadlBuilderFactory(RequestMappingHandlerMapping handlerMapping) { + final ClassTypeDiscoverer classTypeDiscoverer = new ClassTypeDiscoverer(new QNameBuilderFactory().getBuilder()); + final GrammarsDiscoverer grammarsDiscoverer = new GrammarsDiscoverer(classTypeDiscoverer); + final ApplicationContext appCtx = new ApplicationContext(new SpringMethodContextIterator(handlerMapping), grammarsDiscoverer); + applicationBuilder = new ApplicationBuilder(appCtx); + schemaBuilder = new SchemaBuilder(classTypeDiscoverer); + } + + public ApplicationBuilder getApplicationBuilder() { + return applicationBuilder; + } + + public SchemaBuilder getSchemaBuilder() { + return schemaBuilder; + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/GrammarsDiscoverer.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/GrammarsDiscoverer.java new file mode 100644 index 0000000..bd5fca4 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/GrammarsDiscoverer.java @@ -0,0 +1,51 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.namespace; + +import com.autentia.lang.ClassMetadata; +import com.autentia.xml.schema.ClassTypeDiscoverer; + +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.List; + +public class GrammarsDiscoverer { + + private final ClassTypeDiscoverer classTypeDiscoverer; + + public GrammarsDiscoverer(ClassTypeDiscoverer classTypeDiscoverer) { + this.classTypeDiscoverer = classTypeDiscoverer; + } + + public QName discoverQNameFor(ClassMetadata classMetadata) { + final QName qName = findInBasicTypesBy(classMetadata.getType()); + return qName != null ? qName : classTypeDiscoverer.discoverFor(classMetadata).getQName(); + } + + private QName findInBasicTypesBy(Class clazz) { + final QName qName = QNameConstants.BASIC_SINGLE_TYPES.get(clazz); + return qName != null ? qName : QNameConstants.BASIC_COLLECTION_TYPES.get(clazz); + } + + public List getSchemaUrlsForComplexTypes() { + final List urls = new ArrayList(); + for (String localPart : classTypeDiscoverer.getAllByLocalPart().keySet()) { + urls.add("schema/" + localPart); + } + return urls; + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameBuilderFactory.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameBuilderFactory.java new file mode 100644 index 0000000..c147d1a --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameBuilderFactory.java @@ -0,0 +1,54 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.namespace; + +import com.autentia.xml.namespace.QNameBuilder; +import com.autentia.xml.namespace.QNameMemory; +import com.autentia.xml.namespace.QNamePrefixesCache; +import com.autentia.xml.namespace.QNamesCache; +import com.autentia.xml.namespace.cache.InMemoryQNamePrefixesCache; +import com.autentia.xml.namespace.cache.InMemoryQNamesCache; + +import static com.autentia.web.rest.wadl.builder.namespace.QNameConstants.BASIC_COLLECTION_TYPES; +import static com.autentia.web.rest.wadl.builder.namespace.QNameConstants.BASIC_SINGLE_TYPES; + +public class QNameBuilderFactory { + + public QNameBuilder getBuilder() { + return new QNameBuilder( + new QNameMemory( + initCacheForSingleTypes(), + initCacheForCollectionTypes(), + initCacheForAlreadyUsedPrefixes())); + } + + private QNamesCache initCacheForSingleTypes() { + return new InMemoryQNamesCache(BASIC_SINGLE_TYPES); + } + + private QNamesCache initCacheForCollectionTypes() { + return new InMemoryQNamesCache(BASIC_COLLECTION_TYPES); + } + + private QNamePrefixesCache initCacheForAlreadyUsedPrefixes() { + final QNamePrefixesCache cache = new InMemoryQNamePrefixesCache(); + cache.add("xs"); + cache.add("wadl"); + cache.add("tc"); + + return cache; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameConstants.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameConstants.java new file mode 100644 index 0000000..1a81837 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/namespace/QNameConstants.java @@ -0,0 +1,97 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.namespace; + +import net.java.dev.wadl._2009._02.Application; + +import javax.xml.namespace.QName; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public final class QNameConstants { + + private QNameConstants() { + // Private empty default constructor because instances of this class are not allowed. + } + + /* + * Single types. + */ + public static final QName BOOLEAN = new QName("http://www.w3.org/2001/XMLSchema", "boolean", "xs"); + public static final QName BYTE = new QName("http://www.w3.org/2001/XMLSchema", "byte", "xs"); + public static final QName SHORT = new QName("http://www.w3.org/2001/XMLSchema", "short", "xs"); + public static final QName INTEGER = new QName("http://www.w3.org/2001/XMLSchema", "integer", "xs"); + public static final QName LONG = new QName("http://www.w3.org/2001/XMLSchema", "long", "xs"); + public static final QName FLOAT = new QName("http://www.w3.org/2001/XMLSchema", "float", "xs"); + public static final QName DOUBLE = new QName("http://www.w3.org/2001/XMLSchema", "double", "xs"); + public static final QName STRING = new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"); + public static final QName DATE = new QName("http://www.w3.org/2001/XMLSchema", "date", "xs"); + public static final QName WADL_APPLICATION = new QName("http://wadl.dev.java.net/2009/02", "application", "wadl"); + + public static final Map, QName> BASIC_SINGLE_TYPES = Collections.unmodifiableMap(new HashMap, QName>() {{ + put(Boolean.class, BOOLEAN); + put(boolean.class, BOOLEAN); + put(byte.class, BYTE); + put(Byte.class, BYTE); + put(short.class, SHORT); + put(Short.class, SHORT); + put(Integer.class, INTEGER); + put(int.class, INTEGER); + put(Long.class, LONG); + put(long.class, LONG); + put(Float.class, FLOAT); + put(float.class, FLOAT); + put(Double.class, DOUBLE); + put(double.class, DOUBLE); + put(String.class, STRING); + put(Date.class, DATE); + put(Application.class, WADL_APPLICATION); + }}); + + /* + * Collections types. + */ + public static final QName BOOLEANS = new QName("http://www.autentia.com/2013/BasicCollections", "booleanCollection", "tcll"); + public static final QName BYTES = new QName("http://www.autentia.com/2013/BasicCollections", "bytesCollection", "tcll"); + public static final QName SHORTS = new QName("http://www.autentia.com/2013/BasicCollections", "shortCollection", "tcll"); + public static final QName INTEGERS = new QName("http://www.autentia.com/2013/BasicCollections", "integerCollection", "tcll"); + public static final QName LONGS = new QName("http://www.autentia.com/2013/BasicCollections", "longCollection", "tcll"); + public static final QName FLOATS = new QName("http://www.autentia.com/2013/BasicCollections", "floatCollection", "tcll"); + public static final QName DOUBLES = new QName("http://www.autentia.com/2013/BasicCollections", "doubleCollection", "tcll"); + public static final QName STRINGS = new QName("http://www.autentia.com/2013/BasicCollections", "stringCollection", "tcll"); + public static final QName DATES = new QName("http://www.autentia.com/2013/BasicCollections", "dateCollection", "tcll"); + + public static final Map, QName> BASIC_COLLECTION_TYPES = Collections.unmodifiableMap(new HashMap, QName>() {{ + put(Boolean.class, BOOLEANS); + put(boolean.class, BOOLEANS); + put(byte.class, BYTES); + put(Byte.class, BYTES); + put(short.class, SHORTS); + put(Short.class, SHORTS); + put(Integer.class, INTEGERS); + put(int.class, INTEGERS); + put(Long.class, LONGS); + put(long.class, LONGS); + put(Float.class, FLOATS); + put(float.class, FLOATS); + put(Double.class, DOUBLES); + put(double.class, DOUBLES); + put(String.class, STRINGS); + put(Date.class, DATES); + }}); +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilder.java new file mode 100644 index 0000000..3439005 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilder.java @@ -0,0 +1,27 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.param; + +import net.java.dev.wadl._2009._02.Param; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +public interface ParamFromAnnotationBuilder { + + Param build(Method javaMethod, int paramIndex, Annotation paramAnnotation); + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderCommons.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderCommons.java new file mode 100644 index 0000000..2a32b07 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderCommons.java @@ -0,0 +1,50 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.param; + +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.LocalVariableTableParameterNameDiscoverer; +import org.springframework.core.ParameterNameDiscoverer; + +import java.lang.reflect.Method; + +abstract class ParamFromAnnotationBuilderCommons implements ParamFromAnnotationBuilder { + + private static final Logger logger = LoggerFactory.getLogger(ParamFromAnnotationBuilderFactory.class); + private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new LocalVariableTableParameterNameDiscoverer(); + + final GrammarsDiscoverer grammarsDiscoverer; + + protected ParamFromAnnotationBuilderCommons(GrammarsDiscoverer grammarsDiscoverer) { + this.grammarsDiscoverer = grammarsDiscoverer; + } + + String discoverParamName(Method javaMethod, int paramIndex, String explicitName) { + String name = explicitName; + if (name.isEmpty()) { + final String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(javaMethod); + if (parameterNames != null) { + name = parameterNames[paramIndex]; + } else { + logger.warn("Cannot determine name of parameter {} for method {}. Maybe you haven't compiled with debug info, or don't have defined the value in corresponding annotation", paramIndex, javaMethod.getName()); + } + } + return name; + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderFactory.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderFactory.java new file mode 100644 index 0000000..4b7902d --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromAnnotationBuilderFactory.java @@ -0,0 +1,38 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.param; + +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.Map; + +public class ParamFromAnnotationBuilderFactory { + + private final Map paramBuilderByAnnotation = new HashMap(); + + public ParamFromAnnotationBuilderFactory(GrammarsDiscoverer grammarsDiscoverer) { + paramBuilderByAnnotation.put(RequestParam.class.getName(), new ParamFromRequestParamBuilder(grammarsDiscoverer)); + paramBuilderByAnnotation.put(PathVariable.class.getName(), new ParamFromPathVariableBuilder(grammarsDiscoverer)); + } + + public ParamFromAnnotationBuilder builderFor(Annotation annotation) { + return paramBuilderByAnnotation.get(annotation.annotationType().getName()); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromPathVariableBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromPathVariableBuilder.java new file mode 100644 index 0000000..b55204a --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromPathVariableBuilder.java @@ -0,0 +1,41 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.param; + +import com.autentia.lang.ClassMetadataFromParam; +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import net.java.dev.wadl._2009._02.Param; +import net.java.dev.wadl._2009._02.ParamStyle; +import org.springframework.web.bind.annotation.PathVariable; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +class ParamFromPathVariableBuilder extends ParamFromAnnotationBuilderCommons { + + ParamFromPathVariableBuilder(GrammarsDiscoverer grammarsDiscoverer) { + super(grammarsDiscoverer); + } + + @Override + public Param build(Method javaMethod, int paramIndex, Annotation paramAnnotation) { + return new Param() + .withName(discoverParamName(javaMethod, paramIndex, ((PathVariable) paramAnnotation).value())) + .withStyle(ParamStyle.TEMPLATE) + .withRequired(true) + .withType(grammarsDiscoverer.discoverQNameFor(new ClassMetadataFromParam(javaMethod, paramIndex))); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromRequestParamBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromRequestParamBuilder.java new file mode 100644 index 0000000..1860abb --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/web/rest/wadl/builder/param/ParamFromRequestParamBuilder.java @@ -0,0 +1,48 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.web.rest.wadl.builder.param; + +import com.autentia.lang.ClassMetadataFromParam; +import com.autentia.web.rest.wadl.builder.namespace.GrammarsDiscoverer; +import net.java.dev.wadl._2009._02.Param; +import net.java.dev.wadl._2009._02.ParamStyle; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ValueConstants; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +class ParamFromRequestParamBuilder extends ParamFromAnnotationBuilderCommons { + + ParamFromRequestParamBuilder(GrammarsDiscoverer grammarsDiscoverer) { + super(grammarsDiscoverer); + } + + @Override + public Param build(Method javaMethod, int paramIndex, Annotation paramAnnotation) { + final RequestParam requestParam = (RequestParam) paramAnnotation; + final Param param = new Param() + .withName(discoverParamName(javaMethod, paramIndex, requestParam.value())) + .withStyle(ParamStyle.QUERY) + .withRequired(requestParam.required()) + .withType(grammarsDiscoverer.discoverQNameFor(new ClassMetadataFromParam(javaMethod, paramIndex))); + + if (!ValueConstants.DEFAULT_NONE.equals(requestParam.defaultValue())) { + param.setDefault(requestParam.defaultValue()); + } + return param; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameBuilder.java new file mode 100644 index 0000000..686e67d --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameBuilder.java @@ -0,0 +1,118 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.namespace; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBIntrospector; +import javax.xml.namespace.QName; +import java.util.regex.Pattern; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +public class QNameBuilder { + + private static final Logger logger = LoggerFactory.getLogger(QNameBuilder.class); + + private static final Pattern BY_DOTS = Pattern.compile("\\."); + private static final Pattern VOWELS = Pattern.compile("[aeiou]"); + private static final QName EMPTY_Q_NAME = new QName("", "", ""); + + private final QNameMemory memory; + + public QNameBuilder(QNameMemory memory) { + this.memory = memory; + } + + public QName buildFor(Class classType) { + return discoverQNameAndCachesIt(classType, "", "", memory.forSingleTypes()); + } + + public QName buildForCollectionOf(Class clazz) { + return discoverQNameAndCachesIt(clazz, "Collection", "cll", memory.forCollectionTypes()); + } + + private QName discoverQNameAndCachesIt(Class classType, String classTypeNameSuffix, String prefixSuffix, QNamesCache cache) { + QName qName = cache.getQNameFor(classType); + if (qName == null) { + qName = discoverQNameFromJaxb(classType); + + final String localPart = (isNotBlank(qName.getLocalPart()) ? qName.getLocalPart() : discoverLocalPartFor(classType)) + classTypeNameSuffix; + final String namespaceUri = isNotBlank(qName.getNamespaceURI()) ? qName.getNamespaceURI() : discoverNamespaceUriFor(classType, localPart); + final String prefix = isNotBlank(qName.getPrefix()) ? qName.getPrefix() : discoverPrefixFor(classType, prefixSuffix); + qName = new QName(namespaceUri, localPart, prefix); + + cache.putQNameFor(classType, qName); + } + return qName; + } + + private QName discoverQNameFromJaxb(Class classType) { + QName qName = null; + try { + final JAXBIntrospector jaxbIntrospector = JAXBContext.newInstance(classType).createJAXBIntrospector(); + qName = jaxbIntrospector.getElementName(classType.getConstructor().newInstance()); + + } catch (Exception e) { + // Add e to the logger message because JAXB Exceptions has a lot of information in the toString(). + // and some loggers implementations just print the getMessage(); + logger.warn("Cannot discover QName from JAXB annotations for class: " + classType.getName() + + ". Preparing generic QName." + e, e); + } + + if (qName == null) { + // Could be null if getElementName returned null, or a exception was thrown. + return EMPTY_Q_NAME; + } + return qName; + } + + private String discoverNamespaceUriFor(Class classType, String localPart) { + final String[] classNameSections = BY_DOTS.split(classType.getName()); + return "http://www." + classNameSections[1] + '.' + classNameSections[0] + "/schema/" + localPart; + } + + private String discoverLocalPartFor(Class classType) { + final String classTypeName = classType.getSimpleName(); + return classTypeName.substring(0, 1).toLowerCase() + classTypeName.substring(1); + } + + private String discoverPrefixFor(Class classType, String suffix) { + final String simpleName = classType.getSimpleName(); + final String classNameWithoutVowels = VOWELS.matcher(simpleName.toLowerCase()).replaceAll(""); + final String reducedClassName = classNameWithoutVowels.length() >= 3 ? classNameWithoutVowels : simpleName; + + String prefix = reducedClassName.substring(0, 3) + suffix; + + int i = 4; + int numberedSuffix = 2; + while (memory.forAlreadyUsedPrefixes().contains(prefix)) { + if (i < reducedClassName.length()) { + prefix = reducedClassName.substring(0, i) + suffix; + i++; + + } else { + prefix = reducedClassName.substring(0, 3) + suffix + numberedSuffix; + numberedSuffix++; + } + } + + memory.forAlreadyUsedPrefixes().add(prefix); + return prefix; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameMemory.java b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameMemory.java new file mode 100644 index 0000000..0fa5d5e --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNameMemory.java @@ -0,0 +1,41 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.namespace; + +public class QNameMemory { + + private final QNamesCache cacheForSingleTypes; + private final QNamesCache cacheForCollectionTypes; + private final QNamePrefixesCache cacheForAlreadyUsedPrefixes; + + public QNameMemory(QNamesCache cacheForSingleTypes, QNamesCache cacheForCollectionTypes, QNamePrefixesCache cacheForAlreadyUsedPrefixes) { + this.cacheForSingleTypes = cacheForSingleTypes; + this.cacheForCollectionTypes = cacheForCollectionTypes; + this.cacheForAlreadyUsedPrefixes = cacheForAlreadyUsedPrefixes; + } + + public QNamesCache forSingleTypes() { + return cacheForSingleTypes; + } + + public QNamesCache forCollectionTypes() { + return cacheForCollectionTypes; + } + + public QNamePrefixesCache forAlreadyUsedPrefixes() { + return cacheForAlreadyUsedPrefixes; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamePrefixesCache.java b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamePrefixesCache.java new file mode 100644 index 0000000..e988c06 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamePrefixesCache.java @@ -0,0 +1,24 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.namespace; + +public interface QNamePrefixesCache { + + boolean contains(String prefix); + + void add(String prefix); + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamesCache.java b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamesCache.java new file mode 100644 index 0000000..a5594d7 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/QNamesCache.java @@ -0,0 +1,26 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.namespace; + +import javax.xml.namespace.QName; + +public interface QNamesCache { + + QName getQNameFor(Class classType); + + void putQNameFor(Class classType, QName qName); + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamePrefixesCache.java b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamePrefixesCache.java new file mode 100644 index 0000000..5a6b7fa --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamePrefixesCache.java @@ -0,0 +1,36 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.namespace.cache; + +import com.autentia.xml.namespace.QNamePrefixesCache; + +import java.util.HashSet; +import java.util.Set; + +public class InMemoryQNamePrefixesCache implements QNamePrefixesCache { + + private final Set cache = new HashSet(); + + @Override + public boolean contains(String prefix) { + return cache.contains(prefix); + } + + @Override + public void add(String prefix) { + cache.add(prefix); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamesCache.java b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamesCache.java new file mode 100644 index 0000000..6db2b1b --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/namespace/cache/InMemoryQNamesCache.java @@ -0,0 +1,46 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.namespace.cache; + +import com.autentia.xml.namespace.QNamesCache; + +import javax.xml.namespace.QName; +import java.util.HashMap; +import java.util.Map; + +public class InMemoryQNamesCache implements QNamesCache { + + private final Map, QName> cache = new HashMap, QName>(); + + public InMemoryQNamesCache() { + // Default constructor do nothing. + } + + public InMemoryQNamesCache(Map, QName> initialValues) { + cache.putAll(initialValues); + } + + @Override + public QName getQNameFor(Class classType) { + return cache.get(classType); + } + + @Override + public void putQNameFor(Class classType, QName qName) { + cache.put(classType, qName); + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassType.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassType.java new file mode 100644 index 0000000..c29905d --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassType.java @@ -0,0 +1,39 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +import javax.xml.namespace.QName; + +public abstract class ClassType { + + final Class clazz; + final QName qName; + + ClassType(Class clazz, QName qName) { + this.qName = qName; + this.clazz = clazz; + } + + public abstract String toSchema(); + + public QName getQName() { + return qName; + } + + public Class getClazz() { + return clazz; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeDiscoverer.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeDiscoverer.java new file mode 100644 index 0000000..99a59ed --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeDiscoverer.java @@ -0,0 +1,68 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +import com.autentia.lang.ClassMetadata; +import com.autentia.xml.namespace.QNameBuilder; + +import javax.xml.namespace.QName; +import java.util.Map; + +public class ClassTypeDiscoverer { + + final QNameBuilder qNameBuilder; + final ClassTypeInMemoryStore classTypeStore = new ClassTypeInMemoryStore(); + + public ClassTypeDiscoverer(QNameBuilder qNameBuilder) { + this.qNameBuilder = qNameBuilder; + } + + public ClassType discoverFor(ClassMetadata classMetadata) { + ClassType classType = classTypeStore.findBy(classMetadata.getType()); + if (classType == null) { + classType = buildClassTypeFor(classMetadata); + classTypeStore.add(classType); + } + + return classType; + } + + private ClassType buildClassTypeFor(ClassMetadata classMetadata) { + final ClassType classType; + if (classMetadata.isCollection()) { + final QName collectionQName = qNameBuilder.buildForCollectionOf(classMetadata.getComponentType()); + final QName elementsQName = qNameBuilder.buildFor(classMetadata.getComponentType()); + classType = new CollectionType(classMetadata.getType(), collectionQName, elementsQName); + + } else { + final QName qName = qNameBuilder.buildFor(classMetadata.getType()); + classType = new SingleType(classMetadata.getType(), qName); + } + return classType; + } + + public ClassType getBy(String localPart) { + final ClassType classType = classTypeStore.findBy(localPart); + if (classType == null) { + throw new ClassTypeNotFoundException("Cannot find class type for localPart: " + localPart); + } + return classType; + } + + public Map getAllByLocalPart() { + return classTypeStore.getAllByLocalPart(); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeInMemoryStore.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeInMemoryStore.java new file mode 100644 index 0000000..4db723c --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeInMemoryStore.java @@ -0,0 +1,43 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +class ClassTypeInMemoryStore { + + private final Map classTypeByLocalPart = new HashMap(); + private final Map, ClassType> classTypeByClass = new HashMap, ClassType>(); + + ClassType findBy(String localPart) { + return classTypeByLocalPart.get(localPart); + } + + ClassType findBy(Class classType) { + return classTypeByClass.get(classType); + } + + Map getAllByLocalPart() { + return Collections.unmodifiableMap(classTypeByLocalPart); + } + + void add(ClassType classType) { + classTypeByLocalPart.put(classType.getQName().getLocalPart(), classType); + classTypeByClass.put(classType.getClazz(), classType); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeNotFoundException.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeNotFoundException.java new file mode 100644 index 0000000..368251f --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/ClassTypeNotFoundException.java @@ -0,0 +1,27 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +public class ClassTypeNotFoundException extends RuntimeException { + + public ClassTypeNotFoundException() { + // Default constructor, do nothing. + } + + public ClassTypeNotFoundException(String message) { + super(message); + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/CollectionType.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/CollectionType.java new file mode 100644 index 0000000..e10afe1 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/CollectionType.java @@ -0,0 +1,53 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +import javax.xml.namespace.QName; + +public class CollectionType extends ClassType { + + private static final String COLLECTION_COMPLEX_TYPE_SCHEMA = "\n" + + "\n" + + '\n' + + " \n" + + '\n' + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n\n"; + + private final QName elementsQName; + + public CollectionType(Class collectionClass, QName collectionQName, QName elementsQName) { + super(collectionClass, collectionQName); + this.elementsQName = elementsQName; + } + + @Override + public String toSchema() { + return COLLECTION_COMPLEX_TYPE_SCHEMA + .replace("???type???", elementsQName.getLocalPart()) + .replace("???name???", elementsQName.getLocalPart()) + .replace("???collectionType???", qName.getLocalPart()) + .replace("???collectionName???", qName.getLocalPart()); + } + + public QName getElementsQName() { + return elementsQName; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/FromFileClassType.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/FromFileClassType.java new file mode 100644 index 0000000..8a74036 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/FromFileClassType.java @@ -0,0 +1,49 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.namespace.QName; +import java.io.File; +import java.io.IOException; + +public class FromFileClassType extends ClassType { + + private static final Logger logger = LoggerFactory.getLogger(FromFileClassType.class); + + private final File sourceFile; + + public FromFileClassType(Class clazz, QName qName, File sourceFile) { + super(clazz, qName); + this.sourceFile = sourceFile; + } + + @Override + public String toSchema() { + try { + return FileUtils.readFileToString(sourceFile, "UTF-8"); + + } catch (IOException e) { +// logger.error(); + e.printStackTrace(); + } + + return null; + } +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/SchemaBuilder.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/SchemaBuilder.java new file mode 100644 index 0000000..edeaa07 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/SchemaBuilder.java @@ -0,0 +1,35 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +/** + * Useful URLs: + * - W3C XML Schema Definition Language (XSD) 1.1 Part 1: Structures --> http://www.w3.org/TR/xmlschema11-1/ + * - XML Schema Patterns for Common Data Structures --> http://www.w3.org/2005/07/xml-schema-patterns.html + */ +public class SchemaBuilder { + + private final ClassTypeDiscoverer classTypeDiscoverer; + + public SchemaBuilder(ClassTypeDiscoverer classTypeDiscoverer) { + this.classTypeDiscoverer = classTypeDiscoverer; + } + + public String buildFor(final String localPart) { + return classTypeDiscoverer.getBy(localPart).toSchema(); + } + +} diff --git a/spring-wadl-generator/src/main/java/com/autentia/xml/schema/SingleType.java b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/SingleType.java new file mode 100644 index 0000000..9bbd256 --- /dev/null +++ b/spring-wadl-generator/src/main/java/com/autentia/xml/schema/SingleType.java @@ -0,0 +1,80 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.autentia.xml.schema; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.namespace.QName; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; +import java.io.IOException; +import java.io.StringWriter; + +public class SingleType extends ClassType { + + private static final Logger logger = LoggerFactory.getLogger(SingleType.class); + + private static final String NON_EXISTING_CLASS_SCHEMA = "\n" + + "\n" + + '\n' + + " \n" + + '\n' + + " \n" + + " \n" + + " \n" + + "\n\n"; + + public SingleType(Class classType, QName qName) { + super(classType, qName); + } + + @Override + public String toSchema() { + try { + return tryBuildSchemaFromJaxbAnnotatedClass(); + + } catch (Exception e) { + // Add e to the logger message because JAXB Exceptions has a lot of information in the toString(). + // and some loggers implementations just print the getMessage(); + logger.warn("Cannot generate schema from JAXB annotations for class: " + clazz.getName() + + ". Preparing generic Schema.\n" + e, e); + return schemaForNonAnnotatedClass(); + } + } + + private String tryBuildSchemaFromJaxbAnnotatedClass() throws JAXBException, IOException { + final StringWriter stringWriter = new StringWriter(); + JAXBContext.newInstance(clazz).generateSchema(new SchemaOutputResolver() { + @Override + public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { + final StreamResult result = new StreamResult(stringWriter); + result.setSystemId("schema" + clazz.getSimpleName()); + return result; + } + }); + + return stringWriter.toString(); + } + + private String schemaForNonAnnotatedClass() { + return NON_EXISTING_CLASS_SCHEMA.replace("???type???", qName.getLocalPart()).replace("???name???", qName.getLocalPart()); + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Application.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Application.java new file mode 100644 index 0000000..19d8be5 --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Application.java @@ -0,0 +1,344 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}grammars" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}resources" maxOccurs="unbounded" minOccurs="0"/>
+ *         <choice maxOccurs="unbounded" minOccurs="0">
+ *           <element ref="{http://wadl.dev.java.net/2009/02}resource_type"/>
+ *           <element ref="{http://wadl.dev.java.net/2009/02}method"/>
+ *           <element ref="{http://wadl.dev.java.net/2009/02}representation"/>
+ *           <element ref="{http://wadl.dev.java.net/2009/02}param"/>
+ *         </choice>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc", + "grammars", + "resources", + "resourceTypeOrMethodOrRepresentation", + "any" +}) +@XmlRootElement(name = "application") +public class Application { + + protected List doc; + protected Grammars grammars; + protected List resources; + @XmlElements({ + @XmlElement(name = "resource_type", type = ResourceType.class), + @XmlElement(name = "method", type = Method.class), + @XmlElement(name = "representation", type = Representation.class), + @XmlElement(name = "param", type = Param.class) + }) + protected List resourceTypeOrMethodOrRepresentation; + @XmlAnyElement(lax = true) + protected List any; + + /** + * Default no-arg constructor + * + */ + public Application() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Application(final List doc, final Grammars grammars, final List resources, final List resourceTypeOrMethodOrRepresentation, final List any) { + this.doc = doc; + this.grammars = grammars; + this.resources = resources; + this.resourceTypeOrMethodOrRepresentation = resourceTypeOrMethodOrRepresentation; + this.any = any; + } + + /** + * Gets the value of the doc property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the doc property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getDoc().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Doc } + * + * + */ + public List getDoc() { + if (doc == null) { + doc = new ArrayList(); + } + return this.doc; + } + + /** + * Gets the value of the grammars property. + * + * @return + * possible object is + * {@link Grammars } + * + */ + public Grammars getGrammars() { + return grammars; + } + + /** + * Sets the value of the grammars property. + * + * @param value + * allowed object is + * {@link Grammars } + * + */ + public void setGrammars(Grammars value) { + this.grammars = value; + } + + /** + * Gets the value of the resources property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the resources property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getResources().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Resources } + * + * + */ + public List getResources() { + if (resources == null) { + resources = new ArrayList(); + } + return this.resources; + } + + /** + * Gets the value of the resourceTypeOrMethodOrRepresentation property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the resourceTypeOrMethodOrRepresentation property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getResourceTypeOrMethodOrRepresentation().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link ResourceType } + * {@link Method } + * {@link Representation } + * {@link Param } + * + * + */ + public List getResourceTypeOrMethodOrRepresentation() { + if (resourceTypeOrMethodOrRepresentation == null) { + resourceTypeOrMethodOrRepresentation = new ArrayList(); + } + return this.resourceTypeOrMethodOrRepresentation; + } + + /** + * Gets the value of the any property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the any property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getAny().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link Element } + * + * + */ + public List getAny() { + if (any == null) { + any = new ArrayList(); + } + return this.any; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Application withDoc(Doc... values) { + if (values!= null) { + for (Doc value: values) { + getDoc().add(value); + } + } + return this; + } + + public Application withDoc(Collection values) { + if (values!= null) { + getDoc().addAll(values); + } + return this; + } + + public Application withGrammars(Grammars value) { + setGrammars(value); + return this; + } + + public Application withResources(Resources... values) { + if (values!= null) { + for (Resources value: values) { + getResources().add(value); + } + } + return this; + } + + public Application withResources(Collection values) { + if (values!= null) { + getResources().addAll(values); + } + return this; + } + + public Application withResourceTypeOrMethodOrRepresentation(Object... values) { + if (values!= null) { + for (Object value: values) { + getResourceTypeOrMethodOrRepresentation().add(value); + } + } + return this; + } + + public Application withResourceTypeOrMethodOrRepresentation(Collection values) { + if (values!= null) { + getResourceTypeOrMethodOrRepresentation().addAll(values); + } + return this; + } + + public Application withAny(Object... values) { + if (values!= null) { + for (Object value: values) { + getAny().add(value); + } + } + return this; + } + + public Application withAny(Collection values) { + if (values!= null) { + getAny().addAll(values); + } + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Doc.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Doc.java new file mode 100644 index 0000000..52e2df3 --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Doc.java @@ -0,0 +1,244 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="title" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute ref="{http://www.w3.org/XML/1998/namespace}lang"/>
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "content" +}) +@XmlRootElement(name = "doc") +public class Doc { + + @XmlMixed + @XmlAnyElement(lax = true) + protected List content; + @XmlAttribute(name = "title") + protected String title; + @XmlAttribute(name = "lang", namespace = "http://www.w3.org/XML/1998/namespace") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Default no-arg constructor + * + */ + public Doc() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Doc(final List content, final String title, final String lang, final Map otherAttributes) { + this.content = content; + this.title = title; + this.lang = lang; + this.otherAttributes = otherAttributes; + } + + /** + * Gets the value of the content property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the content property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getContent().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * {@link Object } + * {@link Element } + * + * + */ + public List getContent() { + if (content == null) { + content = new ArrayList(); + } + return this.content; + } + + /** + * Gets the value of the title property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Sets the value of the title property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Doc withContent(Object... values) { + if (values!= null) { + for (Object value: values) { + getContent().add(value); + } + } + return this; + } + + public Doc withContent(Collection values) { + if (values!= null) { + getContent().addAll(values); + } + return this; + } + + public Doc withTitle(String value) { + setTitle(value); + return this; + } + + public Doc withLang(String value) { + setLang(value); + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Grammars.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Grammars.java new file mode 100644 index 0000000..ea300a1 --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Grammars.java @@ -0,0 +1,246 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}include" maxOccurs="unbounded" minOccurs="0"/>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc", + "include", + "any" +}) +@XmlRootElement(name = "grammars") +public class Grammars { + + protected List doc; + protected List include; + @XmlAnyElement(lax = true) + protected List any; + + /** + * Default no-arg constructor + * + */ + public Grammars() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Grammars(final List doc, final List include, final List any) { + this.doc = doc; + this.include = include; + this.any = any; + } + + /** + * Gets the value of the doc property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the doc property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getDoc().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Doc } + * + * + */ + public List getDoc() { + if (doc == null) { + doc = new ArrayList(); + } + return this.doc; + } + + /** + * Gets the value of the include property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the include property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getInclude().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Include } + * + * + */ + public List getInclude() { + if (include == null) { + include = new ArrayList(); + } + return this.include; + } + + /** + * Gets the value of the any property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the any property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getAny().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link Element } + * + * + */ + public List getAny() { + if (any == null) { + any = new ArrayList(); + } + return this.any; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Grammars withDoc(Doc... values) { + if (values!= null) { + for (Doc value: values) { + getDoc().add(value); + } + } + return this; + } + + public Grammars withDoc(Collection values) { + if (values!= null) { + getDoc().addAll(values); + } + return this; + } + + public Grammars withInclude(Include... values) { + if (values!= null) { + for (Include value: values) { + getInclude().add(value); + } + } + return this; + } + + public Grammars withInclude(Collection values) { + if (values!= null) { + getInclude().addAll(values); + } + return this; + } + + public Grammars withAny(Object... values) { + if (values!= null) { + for (Object value: values) { + getAny().add(value); + } + } + return this; + } + + public Grammars withAny(Collection values) { + if (values!= null) { + getAny().addAll(values); + } + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/HTTPMethods.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/HTTPMethods.java new file mode 100644 index 0000000..47dd87a --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/HTTPMethods.java @@ -0,0 +1,66 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for HTTPMethods. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="HTTPMethods">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}NMTOKEN">
+ *     <enumeration value="GET"/>
+ *     <enumeration value="POST"/>
+ *     <enumeration value="PUT"/>
+ *     <enumeration value="HEAD"/>
+ *     <enumeration value="DELETE"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "HTTPMethods") +@XmlEnum +public enum HTTPMethods { + + GET, + POST, + PUT, + HEAD, + DELETE; + + public String value() { + return name(); + } + + public static HTTPMethods fromValue(String v) { + return valueOf(v); + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Include.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Include.java new file mode 100644 index 0000000..33e2982 --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Include.java @@ -0,0 +1,206 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc" +}) +@XmlRootElement(name = "include") +public class Include { + + protected List doc; + @XmlAttribute(name = "href") + @XmlSchemaType(name = "anyURI") + protected String href; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Default no-arg constructor + * + */ + public Include() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Include(final List doc, final String href, final Map otherAttributes) { + this.doc = doc; + this.href = href; + this.otherAttributes = otherAttributes; + } + + /** + * Gets the value of the doc property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the doc property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getDoc().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Doc } + * + * + */ + public List getDoc() { + if (doc == null) { + doc = new ArrayList(); + } + return this.doc; + } + + /** + * Gets the value of the href property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getHref() { + return href; + } + + /** + * Sets the value of the href property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setHref(String value) { + this.href = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Include withDoc(Doc... values) { + if (values!= null) { + for (Doc value: values) { + getDoc().add(value); + } + } + return this; + } + + public Include withDoc(Collection values) { + if (values!= null) { + getDoc().addAll(values); + } + return this; + } + + public Include withHref(String value) { + setHref(value); + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Link.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Link.java new file mode 100644 index 0000000..5d05d0e --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Link.java @@ -0,0 +1,331 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="resource_type" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *       <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}token" />
+ *       <attribute name="rev" type="{http://www.w3.org/2001/XMLSchema}token" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc", + "any" +}) +@XmlRootElement(name = "link") +public class Link { + + protected List doc; + @XmlAnyElement(lax = true) + protected List any; + @XmlAttribute(name = "resource_type") + @XmlSchemaType(name = "anyURI") + protected String resourceType; + @XmlAttribute(name = "rel") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "token") + protected String rel; + @XmlAttribute(name = "rev") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "token") + protected String rev; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Default no-arg constructor + * + */ + public Link() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Link(final List doc, final List any, final String resourceType, final String rel, final String rev, final Map otherAttributes) { + this.doc = doc; + this.any = any; + this.resourceType = resourceType; + this.rel = rel; + this.rev = rev; + this.otherAttributes = otherAttributes; + } + + /** + * Gets the value of the doc property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the doc property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getDoc().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Doc } + * + * + */ + public List getDoc() { + if (doc == null) { + doc = new ArrayList(); + } + return this.doc; + } + + /** + * Gets the value of the any property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the any property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getAny().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link Element } + * + * + */ + public List getAny() { + if (any == null) { + any = new ArrayList(); + } + return this.any; + } + + /** + * Gets the value of the resourceType property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResourceType() { + return resourceType; + } + + /** + * Sets the value of the resourceType property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResourceType(String value) { + this.resourceType = value; + } + + /** + * Gets the value of the rel property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRel() { + return rel; + } + + /** + * Sets the value of the rel property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRel(String value) { + this.rel = value; + } + + /** + * Gets the value of the rev property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRev() { + return rev; + } + + /** + * Sets the value of the rev property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRev(String value) { + this.rev = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Link withDoc(Doc... values) { + if (values!= null) { + for (Doc value: values) { + getDoc().add(value); + } + } + return this; + } + + public Link withDoc(Collection values) { + if (values!= null) { + getDoc().addAll(values); + } + return this; + } + + public Link withAny(Object... values) { + if (values!= null) { + for (Object value: values) { + getAny().add(value); + } + } + return this; + } + + public Link withAny(Collection values) { + if (values!= null) { + getAny().addAll(values); + } + return this; + } + + public Link withResourceType(String value) { + setResourceType(value); + return this; + } + + public Link withRel(String value) { + setRel(value); + return this; + } + + public Link withRev(String value) { + setRev(value); + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Method.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Method.java new file mode 100644 index 0000000..fc4d704 --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Method.java @@ -0,0 +1,413 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}request" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}response" maxOccurs="unbounded" minOccurs="0"/>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
+ *       <attribute name="name" type="{http://wadl.dev.java.net/2009/02}Method" />
+ *       <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc", + "request", + "response", + "any" +}) +@XmlRootElement(name = "method") +public class Method { + + protected List doc; + protected Request request; + protected List response; + @XmlAnyElement(lax = true) + protected List any; + @XmlAttribute(name = "id") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlID + @XmlSchemaType(name = "ID") + protected String id; + @XmlAttribute(name = "name") + protected String name; + @XmlAttribute(name = "href") + @XmlSchemaType(name = "anyURI") + protected String href; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Default no-arg constructor + * + */ + public Method() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Method(final List doc, final Request request, final List response, final List any, final String id, final String name, final String href, final Map otherAttributes) { + this.doc = doc; + this.request = request; + this.response = response; + this.any = any; + this.id = id; + this.name = name; + this.href = href; + this.otherAttributes = otherAttributes; + } + + /** + * Gets the value of the doc property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the doc property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getDoc().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Doc } + * + * + */ + public List getDoc() { + if (doc == null) { + doc = new ArrayList(); + } + return this.doc; + } + + /** + * Gets the value of the request property. + * + * @return + * possible object is + * {@link Request } + * + */ + public Request getRequest() { + return request; + } + + /** + * Sets the value of the request property. + * + * @param value + * allowed object is + * {@link Request } + * + */ + public void setRequest(Request value) { + this.request = value; + } + + /** + * Gets the value of the response property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the response property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getResponse().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Response } + * + * + */ + public List getResponse() { + if (response == null) { + response = new ArrayList(); + } + return this.response; + } + + /** + * Gets the value of the any property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the any property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getAny().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link Element } + * + * + */ + public List getAny() { + if (any == null) { + any = new ArrayList(); + } + return this.any; + } + + /** + * Gets the value of the id property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getId() { + return id; + } + + /** + * Sets the value of the id property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setId(String value) { + this.id = value; + } + + /** + * Gets the value of the name property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getName() { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setName(String value) { + this.name = value; + } + + /** + * Gets the value of the href property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getHref() { + return href; + } + + /** + * Sets the value of the href property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setHref(String value) { + this.href = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Method withDoc(Doc... values) { + if (values!= null) { + for (Doc value: values) { + getDoc().add(value); + } + } + return this; + } + + public Method withDoc(Collection values) { + if (values!= null) { + getDoc().addAll(values); + } + return this; + } + + public Method withRequest(Request value) { + setRequest(value); + return this; + } + + public Method withResponse(Response... values) { + if (values!= null) { + for (Response value: values) { + getResponse().add(value); + } + } + return this; + } + + public Method withResponse(Collection values) { + if (values!= null) { + getResponse().addAll(values); + } + return this; + } + + public Method withAny(Object... values) { + if (values!= null) { + for (Object value: values) { + getAny().add(value); + } + } + return this; + } + + public Method withAny(Collection values) { + if (values!= null) { + getAny().addAll(values); + } + return this; + } + + public Method withId(String value) { + setId(value); + return this; + } + + public Method withName(String value) { + setName(value); + return this; + } + + public Method withHref(String value) { + setHref(value); + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/ObjectFactory.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/ObjectFactory.java new file mode 100644 index 0000000..2cba091 --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/ObjectFactory.java @@ -0,0 +1,166 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the net.java.dev.wadl._2009._02 package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: net.java.dev.wadl._2009._02 + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Resources } + * + */ + public Resources createResources() { + return new Resources(); + } + + /** + * Create an instance of {@link Doc } + * + */ + public Doc createDoc() { + return new Doc(); + } + + /** + * Create an instance of {@link Resource } + * + */ + public Resource createResource() { + return new Resource(); + } + + /** + * Create an instance of {@link Param } + * + */ + public Param createParam() { + return new Param(); + } + + /** + * Create an instance of {@link Option } + * + */ + public Option createOption() { + return new Option(); + } + + /** + * Create an instance of {@link Link } + * + */ + public Link createLink() { + return new Link(); + } + + /** + * Create an instance of {@link Method } + * + */ + public Method createMethod() { + return new Method(); + } + + /** + * Create an instance of {@link Request } + * + */ + public Request createRequest() { + return new Request(); + } + + /** + * Create an instance of {@link Representation } + * + */ + public Representation createRepresentation() { + return new Representation(); + } + + /** + * Create an instance of {@link Response } + * + */ + public Response createResponse() { + return new Response(); + } + + /** + * Create an instance of {@link Application } + * + */ + public Application createApplication() { + return new Application(); + } + + /** + * Create an instance of {@link Grammars } + * + */ + public Grammars createGrammars() { + return new Grammars(); + } + + /** + * Create an instance of {@link Include } + * + */ + public Include createInclude() { + return new Include(); + } + + /** + * Create an instance of {@link ResourceType } + * + */ + public ResourceType createResourceType() { + return new ResourceType(); + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Option.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Option.java new file mode 100644 index 0000000..85c4e0f --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Option.java @@ -0,0 +1,290 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="value" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="mediaType" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc", + "any" +}) +@XmlRootElement(name = "option") +public class Option { + + protected List doc; + @XmlAnyElement(lax = true) + protected List any; + @XmlAttribute(name = "value", required = true) + protected String value; + @XmlAttribute(name = "mediaType") + protected String mediaType; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Default no-arg constructor + * + */ + public Option() { + super(); + } + + /** + * Fully-initialising value constructor + * + */ + public Option(final List doc, final List any, final String value, final String mediaType, final Map otherAttributes) { + this.doc = doc; + this.any = any; + this.value = value; + this.mediaType = mediaType; + this.otherAttributes = otherAttributes; + } + + /** + * Gets the value of the doc property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the doc property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getDoc().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Doc } + * + * + */ + public List getDoc() { + if (doc == null) { + doc = new ArrayList(); + } + return this.doc; + } + + /** + * Gets the value of the any property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the any property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getAny().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link Element } + * + * + */ + public List getAny() { + if (any == null) { + any = new ArrayList(); + } + return this.any; + } + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the mediaType property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMediaType() { + return mediaType; + } + + /** + * Sets the value of the mediaType property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMediaType(String value) { + this.mediaType = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

+ * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(Object that) { + return EqualsBuilder.reflectionEquals(this, that); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + public Option withDoc(Doc... values) { + if (values!= null) { + for (Doc value: values) { + getDoc().add(value); + } + } + return this; + } + + public Option withDoc(Collection values) { + if (values!= null) { + getDoc().addAll(values); + } + return this; + } + + public Option withAny(Object... values) { + if (values!= null) { + for (Object value: values) { + getAny().add(value); + } + } + return this; + } + + public Option withAny(Collection values) { + if (values!= null) { + getAny().addAll(values); + } + return this; + } + + public Option withValue(String value) { + setValue(value); + return this; + } + + public Option withMediaType(String value) { + setMediaType(value); + return this; + } + +} diff --git a/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Param.java b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Param.java new file mode 100644 index 0000000..9e9f0db --- /dev/null +++ b/spring-wadl-generator/src/main/java/net/java/dev/wadl/_2009/_02/Param.java @@ -0,0 +1,658 @@ +/** + * Copyright 2013 Autentia Real Business Solution S.L. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.04.24 at 07:55:05 PM CEST +// + + +package net.java.dev.wadl._2009._02; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.w3c.dom.Element; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}doc" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}option" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element ref="{http://wadl.dev.java.net/2009/02}link" minOccurs="0"/>
+ *         <any processContents='lax' namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="href" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *       <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}NMTOKEN" />
+ *       <attribute name="style" type="{http://wadl.dev.java.net/2009/02}ParamStyle" />
+ *       <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
+ *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}QName" default="xs:string" />
+ *       <attribute name="default" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="required" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ *       <attribute name="repeating" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ *       <attribute name="fixed" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="path" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "doc", + "option", + "link", + "any" +}) +@XmlRootElement(name = "param") +public class Param { + + protected List doc; + protected List