Skip to content

Instantly share code, notes, and snippets.

@jeanouii
Created February 9, 2014 23:15
Show Gist options
  • Select an option

  • Save jeanouii/8907586 to your computer and use it in GitHub Desktop.

Select an option

Save jeanouii/8907586 to your computer and use it in GitHub Desktop.
/*
* Tomitribe Confidential
*
* Copyright Tomitribe Corporation. 2014
*
* The source code for this program is not published or otherwise divested
* of its trade secrets, irrespective of what has been deposited with the
* U.S. Copyright Office.
*/
package com.tomitribe.wadler.twitter;
import com.tomitribe.wadler.codegen.service.AccountResource;
import com.tomitribe.wadler.codegen.service.ApplicationResource;
import com.tomitribe.wadler.xml.Jaxb;
import com.tomitribe.wadler.xml.StaxCompare;
import com.tomitribe.wadler.xml.fluent.Application;
import com.tomitribe.wadler.xml.fluent.Resource;
import com.tomitribe.wadler.xml.fluent.Resources;
import org.apache.openejb.loader.IO;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.archive.ClassesArchive;
import javax.ws.rs.Path;
import java.io.File;
import java.util.List;
public class GenerateWadl {
public static void main(String[] args) throws Exception {
final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(AccountResource.class, ApplicationResource.class));
List<Class<?>> classes = finder.findAnnotatedClasses(Path.class);
// we should find also the applications, to create REST Application and all resources
// let's assume we have only one application and one resource
Application application = new Application();
Resources resources = new Resources();
for (Class<?> aClass : classes) {
addResourceForClass(resources, aClass);
}
application.withResources(resources);
String sourceApplication = IO.readString(classLoader().getResource("twitter/wadl/1.1/_docs_api_1_1_get_account_settings.xml"));
String targetApplication = Jaxb.toString(Application.class, application);
StaxCompare.compare(sourceApplication, targetApplication);
}
private static void addResourceForClass(final Resources resources, final Class<?> aClass) {
Resource resource = new Resource();
Path path = aClass.getAnnotation(Path.class);
resource.setPath(path.value());
resources.withResource(resource);
}
private static ClassLoader classLoader() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = GenerateWadl.class.getClassLoader();
}
return loader;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment