<commit_before>package knorxx.framework.generator.springadapter;

import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import knorxx.framework.generator.GenerationResult;
import knorxx.framework.generator.GenerationRoots;
import knorxx.framework.generator.GenerationUnit;
import knorxx.framework.generator.library.LibraryDetector;
import knorxx.framework.generator.library.LibraryUrls;
import knorxx.framework.generator.reloading.annotation.Reloadable;
import knorxx.framework.generator.single.JavaScriptResult;
import static knorxx.framework.generator.springadapter.CacheRequestType.*;
import static knorxx.framework.generator.springadapter.KnorxxGeneratorCacheConfig.GENERATOR_CACHE_NAME;
import knorxx.framework.generator.web.KnorxxApplication;
import knorxx.framework.generator.web.WebJavaScriptGenerator;
import knorxx.framework.generator.web.client.ErrorHandler;
import knorxx.framework.generator.web.client.RpcService;
import knorxx.framework.generator.web.client.WebPage;
import knorxx.framework.generator.web.client.webpage.PageArranger;
import knorxx.framework.generator.web.client.webpage.annotation.WebPageArranger;
import knorxx.framework.generator.web.generator.CssResult;
import knorxx.framework.generator.web.server.json.JsonHelper;
import knorxx.framework.generator.web.server.rpc.ExceptionMarshaller;
import knorxx.framework.generator.web.server.rpc.RpcCall;
import knorxx.framework.generator.web.server.rpc.RpcCaller;
import knorxx.framework.generator.web.server.rpc.RpcResult;
import knorxx.framework.generator.web.server.rtti.RttiGenerationResult;
import knorxx.framework.generator.web.server.rtti.RttiGenerator;
import knorxx.framework.generator.web.server.rtti.UrlResolver;
import org.joda.time.DateTime;
import org.rendersnake.HtmlCanvas;
import org.rendersnake.Renderable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
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.servlet.ModelAndView;

/**
 *
 * @author sj
 */
public abstract class KnorxxController implements ApplicationContextAware {
    
    public final static String FRAMEWORK_URL_PREFIX = "knorxx";
    private final static String JSON_RPC_URL = "/" + FRAMEWORK_URL_PREFIX + "/rpc";
    
    private final Class<?> applicationRootClass;
    private final Class<?> javaScriptGenerationRoot;    
    private final Class<?> indexWebPageClass;
    private final Function<HttpServletRequest, GenerationRoots> generationRootsFunction;
    private GenerationRoots generationRoots;
    private final LibraryDetector libraryDetector;
    private final ExceptionMarshaller exceptionMarshaller;
    
    private final RpcCaller rpcCaller = new RpcCaller();
    private final UrlResolver urlResolver;
    
    @Autowired
    KnorxxApplication knorxxApplication;
    
    @Autowired
    Collection<RpcService> rpcServices;    
    
    ApplicationContext applicationContext;
    
    @Autowired
    Collection<WebPage> webPages;
    
    @Autowired
    CacheManager cacheManager;
    
    @Autowired
    JsonHelper jsonHelper;
    
    @Autowired
    knorxx.framework.generator.web.client.JsonHelper javaScriptJsonHelper;
    
    @Autowired
    ErrorHandler javaScriptErrorHandler;

    public KnorxxController(Class<?> applicationRootClass, Class<?> javaScriptGenerationRoot, Class<?> indexWebPageClass, 
            Function<HttpServletRequest, GenerationRoots> generationRootsFunction,
            LibraryDetector libraryDetector, ExceptionMarshaller exceptionMarshaller) {
        this.applicationRootClass = applicationRootClass;
        this.indexWebPageClass = indexWebPageClass;
        this.javaScriptGenerationRoot = javaScriptGenerationRoot;
        this.generationRootsFunction = generationRootsFunction;
        this.libraryDetector = libraryDetector;
        this.exceptionMarshaller = exceptionMarshaller;
        <commit_msg>resolves #9 "Error in Spring adapter when having a project without RPC services"<commit_after>package knorxx.framework.generator.springadapter;

import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import knorxx.framework.generator.GenerationResult;
import knorxx.framework.generator.GenerationRoots;
import knorxx.framework.generator.GenerationUnit;
import knorxx.framework.generator.library.LibraryDetector;
import knorxx.framework.generator.library.LibraryUrls;
import knorxx.framework.generator.reloading.annotation.Reloadable;
import knorxx.framework.generator.single.JavaScriptResult;
import static knorxx.framework.generator.springadapter.CacheRequestType.*;
import static knorxx.framework.generator.springadapter.KnorxxGeneratorCacheConfig.GENERATOR_CACHE_NAME;
import knorxx.framework.generator.web.KnorxxApplication;
import knorxx.framework.generator.web.WebJavaScriptGenerator;
import knorxx.framework.generator.web.client.ErrorHandler;
import knorxx.framework.generator.web.client.RpcService;
import knorxx.framework.generator.web.client.WebPage;
import knorxx.framework.generator.web.client.webpage.PageArranger;
import knorxx.framework.generator.web.client.webpage.annotation.WebPageArranger;
import knorxx.framework.generator.web.generator.CssResult;
import knorxx.framework.generator.web.server.json.JsonHelper;
import knorxx.framework.generator.web.server.rpc.ExceptionMarshaller;
import knorxx.framework.generator.web.server.rpc.RpcCall;
import knorxx.framework.generator.web.server.rpc.RpcCaller;
import knorxx.framework.generator.web.server.rpc.RpcResult;
import knorxx.framework.generator.web.server.rtti.RttiGenerationResult;
import knorxx.framework.generator.web.server.rtti.RttiGenerator;
import knorxx.framework.generator.web.server.rtti.UrlResolver;
import org.joda.time.DateTime;
import org.rendersnake.HtmlCanvas;
import org.rendersnake.Renderable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
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.servlet.ModelAndView;

/**
 *
 * @author sj
 */
public abstract class KnorxxController implements ApplicationContextAware {
    
    public final static String FRAMEWORK_URL_PREFIX = "knorxx";
    private final static String JSON_RPC_URL = "/" + FRAMEWORK_URL_PREFIX + "/rpc";
    
    private final Class<?> applicationRootClass;
    private final Class<?> javaScriptGenerationRoot;    
    private final Class<?> indexWebPageClass;
    private final Function<HttpServletRequest, GenerationRoots> generationRootsFunction;
    private GenerationRoots generationRoots;
    private final LibraryDetector libraryDetector;
    private final ExceptionMarshaller exceptionMarshaller;
    
    private final RpcCaller rpcCaller = new RpcCaller();
    private final UrlResolver urlResolver;
    
    @Autowired
    KnorxxApplication knorxxApplication;
    
    @Autowired(required = false)
    Collection<RpcService> rpcServices = new ArrayList<>();
    
    ApplicationContext applicationContext;
    
    @Autowired
    Collection<WebPage> webPages;
    
    @Autowired
    CacheManager cacheManager;
    
    @Autowired
    JsonHelper jsonHelper;
    
    @Autowired
    knorxx.framework.generator.web.client.JsonHelper javaScriptJsonHelper;
    
    @Autowired
    ErrorHandler javaScriptErrorHandler;

    public KnorxxController(Class<?> applicationRootClass, Class<?> javaScriptGenerationRoot, Class<?> indexWebPageClass, 
            Function<HttpServletRequest, GenerationRoots> generationRootsFunction,
            LibraryDetector libraryDetector, ExceptionMarshaller exceptionMarshaller) {
        this.applicationRootClass = applicationRootClass;
        this.indexWebPageClass = indexWebPageClass;
        this.javaScriptGenerationRoot = javaScriptGenerationRoot;
        this.generationRootsFunction = generationRootsFunction;
        this.libraryDetector = libraryDetector;
        this.exceptionMarshaller = exceptionMarshaller;
        
{'fraction_non_alphanumeric': 0.08206875193558377, 'fraction_numerical': 0.00010323113451016826, 'mean_word_length': 5.519515477792732, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7064987', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2656, 'n_words': 459}