Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
This file is part of Graylog2. Graylog2 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Graylog2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Graylog2. If not, see <>.
package org.graylog2.restroutes.internal;

Dennis Oelkers <>
public class RouteClassGenerator {
    private final JCodeModel codeModel;
    private final String packagePrefix;
    public RouteClassGenerator(String packagePrefixJCodeModel codeModel) {
        this. = packagePrefix;
        this. = codeModel;
    public JDefinedClass generate(RouteClass routeClass) {
        JDefinedClass definedClass;
        try {
            definedClass = ._class( + "." + routeClass.getKlazz().getSimpleName());
        } catch (JClassAlreadyExistsException e) {
            ..println("Class " + routeClass.getKlazz().getSimpleName() + " already exists");
            return null;
        for (Route route : routeClass.getRoutes()) {
            JMethod method = definedClass.method(.PathMethod.classroute.getMethod().getName());
            String path = route.getPath();
            for (Map.Entry<PathParamClass<?>> entry : route.getPathParams().entrySet()) {
                String fieldName = entry.getKey().value();
                method.param(entry.getValue(), fieldName);
                path = path.replace("{" + fieldName + "}""\"+"+fieldName+"+\"");
            JBlock block = method.body();
            block.directStatement("return new PathMethod(\"" + route.getHttpMethod() + "\", \"" + path + "\");");
        return definedClass;
New to GrepCode? Check out our FAQ X