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