protected Map<Class<?>, ResourceProvider> getResourceProviders(ServletConfig servletConfig, Map<Class<?>, Map<String, List<String>>> resourceClasses) throws ServletException { String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM); if (scope != null && !SERVICE_SCOPE_SINGLETON.equals(scope) && !SERVICE_SCOPE_REQUEST.equals(scope)) { throw new ServletException("Only singleton and prototype scopes are supported"); } boolean isPrototype = SERVICE_SCOPE_REQUEST.equals(scope); Map<Class<?>, ResourceProvider> map = new HashMap<>(); for (Map.Entry<Class<?>, Map<String, List<String>>> entry : resourceClasses.entrySet()) { Class<?> c = entry.getKey(); map.put(c, isPrototype ? new PerRequestResourceProvider(c) : new SingletonResourceProvider( createSingletonInstance(c, entry.getValue(), servletConfig), true)); } return map; }
protected List<?> getProviders(ServletConfig servletConfig, String splitChar) throws ServletException { String providersList = servletConfig.getInitParameter(PROVIDERS_PARAM); if (providersList == null) { return Collections.emptyList(); } String[] classNames = providersList.split(splitChar); List<Object> providers = new ArrayList<>(); for (String cName : classNames) { Map<String, List<String>> props = new HashMap<>(); String theName = getClassNameAndProperties(cName, props); if (!theName.isEmpty()) { Class<?> cls = loadClass(theName); providers.add(createSingletonInstance(cls, props, servletConfig)); } } return providers; }
protected Map<Class<?>, ResourceProvider> getResourceProviders(ServletConfig servletConfig, Map<Class<?>, Map<String, List<String>>> resourceClasses) throws ServletException { String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM); if (scope != null && !SERVICE_SCOPE_SINGLETON.equals(scope) && !SERVICE_SCOPE_REQUEST.equals(scope)) { throw new ServletException("Only singleton and prototype scopes are supported"); } boolean isPrototype = SERVICE_SCOPE_REQUEST.equals(scope); Map<Class<?>, ResourceProvider> map = new HashMap<Class<?>, ResourceProvider>(); for (Map.Entry<Class<?>, Map<String, List<String>>> entry : resourceClasses.entrySet()) { Class<?> c = entry.getKey(); map.put(c, isPrototype ? new PerRequestResourceProvider(c) : new SingletonResourceProvider( createSingletonInstance(c, entry.getValue(), servletConfig), true)); } return map; }
protected List<? extends Feature> getFeatures(ServletConfig servletConfig, String splitChar) throws ServletException { String featuresList = servletConfig.getInitParameter(FEATURES_PARAM); if (featuresList == null) { return Collections.< Feature >emptyList(); } String[] classNames = featuresList.split(splitChar); List< Feature > features = new ArrayList<>(); for (String cName : classNames) { Map<String, List<String>> props = new HashMap<>(); String theName = getClassNameAndProperties(cName, props); if (!theName.isEmpty()) { Class<?> cls = loadClass(theName); if (Feature.class.isAssignableFrom(cls)) { features.add((Feature)createSingletonInstance(cls, props, servletConfig)); } } } return features; }
protected Application createApplicationInstance(String appClassName, ServletConfig servletConfig) throws ServletException { Map<String, List<String>> props = new HashMap<String, List<String>>(); appClassName = getClassNameAndProperties(appClassName, props); Class<?> appClass = loadApplicationClass(appClassName); return (Application)createSingletonInstance(appClass, props, servletConfig); }
protected List<?> getProviders(ServletConfig servletConfig, String splitChar) throws ServletException { String providersList = servletConfig.getInitParameter(PROVIDERS_PARAM); if (providersList == null) { return Collections.EMPTY_LIST; } String[] classNames = StringUtils.split(providersList, splitChar); List<Object> providers = new ArrayList<Object>(); for (String cName : classNames) { Map<String, List<String>> props = new HashMap<String, List<String>>(); String theName = getClassNameAndProperties(cName, props); if (theName.length() != 0) { Class<?> cls = loadClass(theName); providers.add(createSingletonInstance(cls, props, servletConfig)); } } return providers; }
protected List<? extends Feature> getFeatures(ServletConfig servletConfig, String splitChar) throws ServletException { String featuresList = servletConfig.getInitParameter(FEATURES_PARAM); if (featuresList == null) { return Collections.< Feature >emptyList(); } String[] classNames = StringUtils.split(featuresList, splitChar); List< Feature > features = new ArrayList< Feature >(); for (String cName : classNames) { Map<String, List<String>> props = new HashMap<String, List<String>>(); String theName = getClassNameAndProperties(cName, props); if (theName.length() != 0) { Class<?> cls = loadClass(theName); if (Feature.class.isAssignableFrom(cls)) { features.add((Feature)createSingletonInstance(cls, props, servletConfig)); } } } return features; } protected String getParameterSplitChar(ServletConfig servletConfig) {
protected ApplicationInfo createApplicationInfo(String appClassName, ServletConfig servletConfig) throws ServletException { Application customApp = createApplicationInstance(appClassName, servletConfig); if (customApp != null) { return new ApplicationInfo(customApp, getBus()); } Map<String, List<String>> props = new HashMap<>(); appClassName = getClassNameAndProperties(appClassName, props); Class<?> appClass = loadApplicationClass(appClassName); ApplicationInfo appInfo = (ApplicationInfo)createSingletonInstance(appClass, props, servletConfig); Map<String, Object> servletProps = new HashMap<>(); ServletContext servletContext = servletConfig.getServletContext(); for (Enumeration<String> names = servletContext.getInitParameterNames(); names.hasMoreElements();) { String name = names.nextElement(); servletProps.put(name, servletContext.getInitParameter(name)); } for (Enumeration<String> names = servletConfig.getInitParameterNames(); names.hasMoreElements();) { String name = names.nextElement(); servletProps.put(name, servletConfig.getInitParameter(name)); } appInfo.setOverridingProps(servletProps); return appInfo; }