Search in sources :

Example 1 with Controller

use of com.iggroup.oss.restdoclet.doclet.type.Controller in project RESTdoclet by IG-Group.

the class XmlDoclet method controllerDocs.

/**
    * Generates Java documentation for controllers.
    * 
    * @param rootDoc the root Java documentation object.
    * @throws IoException
    * @throws JiBXException
    */
public static void controllerDocs(final RootDoc rootDoc) throws IOException, JiBXException {
    LOG.info("Finding controllers.....");
    Boolean found = false;
    for (ClassDoc classDoc : rootDoc.classes()) {
        LOG.debug("Controller? " + classDoc.qualifiedName() + ".java");
        if (isAnnotated(classDoc, org.springframework.stereotype.Controller.class)) {
            LOG.info("Found controller.  Generating javadoc xml for " + classDoc.qualifiedName() + ".java");
            marshallController(new ControllerBuilder().build(new Controller(), classDoc), DocletUtils.documentationFile(classDoc));
            found = true;
        }
    }
    if (!found) {
        throw new IllegalArgumentException("No controllers with Spring @Controller annotation found");
    }
    LOG.info("Done finding controllers.");
}
Also used : ControllerBuilder(com.iggroup.oss.restdoclet.doclet.type.builder.ControllerBuilder) Controller(com.iggroup.oss.restdoclet.doclet.type.Controller) JiBXUtils.marshallController(com.iggroup.oss.restdoclet.doclet.util.JiBXUtils.marshallController) ClassDoc(com.sun.javadoc.ClassDoc)

Example 2 with Controller

use of com.iggroup.oss.restdoclet.doclet.type.Controller in project RESTdoclet by IG-Group.

the class RestDocumentationMojo method services.

/**
    * Generates services from the documentation of controllers and
    * data-binders.
    * 
    * @throws BeansNotFoundException if a bean with an identifier or Java type
    *            can't be found.
    * @throws IOException if services can't be marshaled.
    * @throws JavadocNotFoundException if a controller's documentation can't be
    *            found.
    * @throws JiBXException if a JiBX exception occurs.
    */
private void services() throws IOException, JavadocNotFoundException, JiBXException {
    LOG.info("Generating services");
    DirectoryBuilder dirs = new DirectoryBuilder(baseDirectory, outputDirectory);
    int identifier = 1;
    List<Service> services = new ArrayList<Service>();
    LOG.info("Looking for mappings");
    HashMap<String, ArrayList<Method>> uriMethodMappings = new HashMap<String, ArrayList<Method>>();
    HashMap<String, Controller> uriControllerMappings = new HashMap<String, Controller>();
    HashMap<String, Collection<Uri>> multiUriMappings = new HashMap<String, Collection<Uri>>();
    for (Controller controller : controllers) {
        LOG.info(new StringBuilder().append("- Controller ").append(controller.getType()).toString());
        for (Method method : controller.getMethods()) {
            LOG.info(new StringBuilder().append("... for Method ").append(method.toString()));
            if (excludeMethod(method)) {
                continue;
            }
            // Collate multiple uris into one string key.
            Collection<Uri> uris = method.getUris();
            if (!uris.isEmpty()) {
                String multiUri = "";
                for (Uri uri : uris) {
                    multiUri = multiUri + ", " + uri;
                }
                multiUriMappings.put(multiUri, uris);
                ArrayList<Method> methodList = uriMethodMappings.get(multiUri);
                if (methodList == null) {
                    methodList = new ArrayList<Method>();
                    uriMethodMappings.put(multiUri, methodList);
                }
                methodList.add(method);
                uriControllerMappings.put(multiUri, controller);
            }
        }
    }
    LOG.info("Processing controllers...");
    for (String uri : uriControllerMappings.keySet()) {
        LOG.info(new StringBuilder().append("Processing controllers for ").append(uri).toString());
        Controller controller = uriControllerMappings.get(uri);
        LOG.info(new StringBuilder().append("Found controller ").append(uriControllerMappings.get(uri).getType()).toString());
        ArrayList<Method> matches = uriMethodMappings.get(uri);
        LOG.info(new StringBuilder().append("Found methods ").append(matches.toString()).append(" ").append(matches.size()).toString());
        Service service = new Service(identifier, multiUriMappings.get(uri), new Controller(controller.getType(), controller.getJavadoc(), matches));
        services.add(service);
        service.assertValid();
        JiBXUtils.marshallService(service, ServiceUtils.serviceFile(dirs, identifier));
        identifier++;
    }
    LOG.info("Processing services...");
    Services list = new Services();
    for (Service service : services) {
        org.apache.commons.collections.Predicate predicate = new ControllerTypePredicate(service.getController().getType());
        if (CollectionUtils.exists(list.getControllers(), predicate)) {
            ControllerSummary controller = (ControllerSummary) CollectionUtils.find(list.getControllers(), predicate);
            controller.addService(service);
        } else {
            ControllerSummary controller = new ControllerSummary(service.getController().getType(), service.getController().getJavadoc());
            controller.addService(service);
            list.addController(controller);
        }
    }
    LOG.info("Marshalling services...");
    list.assertValid();
    JiBXUtils.marshallServices(list, ServiceUtils.servicesFile(dirs));
}
Also used : HashMap(java.util.HashMap) ControllerTypePredicate(com.iggroup.oss.restdoclet.doclet.util.ControllerTypePredicate) ArrayList(java.util.ArrayList) Service(com.iggroup.oss.restdoclet.doclet.type.Service) Method(com.iggroup.oss.restdoclet.doclet.type.Method) Controller(com.iggroup.oss.restdoclet.doclet.type.Controller) DirectoryBuilder(com.iggroup.oss.restdoclet.plugin.io.DirectoryBuilder) Uri(com.iggroup.oss.restdoclet.doclet.type.Uri) Services(com.iggroup.oss.restdoclet.doclet.type.Services) Collection(java.util.Collection) ControllerSummary(com.iggroup.oss.restdoclet.doclet.type.ControllerSummary)

Example 3 with Controller

use of com.iggroup.oss.restdoclet.doclet.type.Controller in project RESTdoclet by IG-Group.

the class JiBXUtils method unmarshallController.

/**
    * Static method for unmarshalling a controller.
    * 
    * @param file the file the controller has to be unmarshalled from.
    * @return the unmarshalled controller.
    * @throws JiBXException if JiBX fails.
    * @throws FileNotFoundException if the input file can't be found.
    */
public static Controller unmarshallController(final File file) throws JiBXException, FileNotFoundException {
    final IBindingFactory factory = BindingDirectory.getFactory(Controller.class);
    final IUnmarshallingContext context = factory.createUnmarshallingContext();
    final InputStream stream = new FileInputStream(file);
    return (Controller) context.unmarshalDocument(stream, ENCODING);
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Controller(com.iggroup.oss.restdoclet.doclet.type.Controller) FileInputStream(java.io.FileInputStream)

Example 4 with Controller

use of com.iggroup.oss.restdoclet.doclet.type.Controller in project RESTdoclet by IG-Group.

the class RestDocumentationMojo method javadocs.

/**
    * Collects documentations of controllers and data-binders.
    * 
    * @throws CloneNotSupportedException if a data-binder's documentation can't
    *            be cloned.
    * @throws FileNotFoundException if the file containing documentation can't
    *            be found.
    * @throws JiBXException if a JiBX exception occurs.
    */
private void javadocs() throws CloneNotSupportedException, FileNotFoundException, JiBXException {
    LOG.info("Collecting controller javadocs");
    /* root directory */
    File root = baseDirectory;
    while (root.getParentFile() != null && new File(root.getParentFile(), MavenUtils.POM_FILE).exists()) {
        root = root.getParentFile();
    }
    /* collect controller javadocs */
    LOG.info("Collecting Controller javadocs");
    final Collection<File> cfiles = ServiceUtils.collectControllerJavadocs(root);
    if (cfiles.size() == 0) {
        throw new IllegalArgumentException("No controller javadoc found.  Is the javadoc plugin configured correctly?");
    }
    for (final File file : cfiles) {
        LOG.debug(file.getAbsolutePath() + File.separatorChar + file.getName());
        final Controller cntrl = JiBXUtils.unmarshallController(file);
        LOG.info(cntrl.getType());
        for (Method m : cntrl.getMethods()) {
            LOG.info(m.toString());
        }
        if (!controllers.contains(cntrl)) {
            controllers.add(cntrl);
        }
    }
}
Also used : Method(com.iggroup.oss.restdoclet.doclet.type.Method) Controller(com.iggroup.oss.restdoclet.doclet.type.Controller) File(java.io.File)

Aggregations

Controller (com.iggroup.oss.restdoclet.doclet.type.Controller)4 Method (com.iggroup.oss.restdoclet.doclet.type.Method)2 ControllerSummary (com.iggroup.oss.restdoclet.doclet.type.ControllerSummary)1 Service (com.iggroup.oss.restdoclet.doclet.type.Service)1 Services (com.iggroup.oss.restdoclet.doclet.type.Services)1 Uri (com.iggroup.oss.restdoclet.doclet.type.Uri)1 ControllerBuilder (com.iggroup.oss.restdoclet.doclet.type.builder.ControllerBuilder)1 ControllerTypePredicate (com.iggroup.oss.restdoclet.doclet.util.ControllerTypePredicate)1 JiBXUtils.marshallController (com.iggroup.oss.restdoclet.doclet.util.JiBXUtils.marshallController)1 DirectoryBuilder (com.iggroup.oss.restdoclet.plugin.io.DirectoryBuilder)1 ClassDoc (com.sun.javadoc.ClassDoc)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IBindingFactory (org.jibx.runtime.IBindingFactory)1 IUnmarshallingContext (org.jibx.runtime.IUnmarshallingContext)1