All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.micro.server.module.ConfigurableModule Maven / Gradle / Ivy

package com.aol.micro.server.module;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestListener;

import org.glassfish.grizzly.http.server.HttpServer;

import lombok.AllArgsConstructor;
import lombok.experimental.Builder;
import lombok.experimental.Wither;

import com.aol.micro.server.servers.model.ServerData;
import com.aol.micro.server.utility.HashMapBuilder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;


@Builder
@AllArgsConstructor
@Wither
public class ConfigurableModule implements Module{
	
	private final List restResourceClasses;
	private final List defaultResources;
	private final List listeners;
	private final List requestListeners;
	private final Map filters;
	private final Map servlets;
	private final String jaxWsRsApplication;
	private final String providers;
	private final String context;
	private final Set springConfigurationClasses;
	private final Map propertyOverrides;
	private final List defaultJaxRsPackages;
	private final Consumer serverConfigManager;
	private final boolean resetAll;
	
	@Override
	public Consumer getServerConfigManager(){
		if(serverConfigManager!=null)
			return serverConfigManager;
		
		return Module.super.getServerConfigManager();
	}
	
	@Override
	public List getDefaultJaxRsPackages() {
		if(defaultJaxRsPackages!=null)
			return ImmutableList.copyOf(Iterables.concat(defaultJaxRsPackages,extract(()->Module.super.getDefaultJaxRsPackages())));
		
		return Module.super.getDefaultJaxRsPackages();
	}
	private  Collection extract(Supplier> s) {
		if(!resetAll)
			return s.get();
		return ImmutableList.of();
	}
	private  Map extractMap(Supplier> s) {
		if(!resetAll)
			return s.get();
		return ImmutableMap.of();
	}
	@Override
	public List getRestResourceClasses() {
		if(restResourceClasses!=null)
			return  ImmutableList.copyOf(Iterables.concat(restResourceClasses, extract(() -> Module.super.getRestResourceClasses())));
		
		return Module.super.getRestResourceClasses();
	}
	
	@Override
	public List getDefaultResources() {
		if(this.defaultResources!=null)
			return  ImmutableList.copyOf(Iterables.concat(this.defaultResources, extract(()->Module.super.getDefaultResources())));
			
		return Module.super.getDefaultResources();
	}

	@Override
	public List getListeners(ServerData data) {
		if(listeners!=null)
			return  ImmutableList.copyOf(Iterables.concat(this.listeners, extract(()->Module.super.getListeners(data))));
		
		return Module.super.getListeners(data);
	}

	@Override
	public List getRequestListeners(ServerData data) {
		if(requestListeners!=null)
			return  ImmutableList.copyOf(Iterables.concat(this.requestListeners,
					                                      extract(()->Module.super.getRequestListeners(data))));

		return Module.super.getRequestListeners(data);
	}

	@Override
	public Map getFilters(ServerData data) {
		if(filters!=null)
			return  HashMapBuilder.from(filters).putAll(extractMap(()->Module.super.getFilters(data))).build();
			
		return Module.super.getFilters(data);
	}

	@Override
	public Map getServlets(ServerData data) {
		if(servlets!=null)
			return  HashMapBuilder.from(servlets).putAll(extractMap(()->Module.super.getServlets(data))).build();
			
		return Module.super.getServlets(data);
	}

	@Override
	public String getJaxWsRsApplication() {
		if(this.jaxWsRsApplication!=null)
			return jaxWsRsApplication;
		return Module.super.getJaxWsRsApplication();
	}

	@Override
	public String getProviders() {
		if(providers!=null)
			return providers;
		return Module.super.getProviders();
	}

	@Override
	public String getContext() {
		
		return context;
	}

	@Override
	public Set getSpringConfigurationClasses() {
		if(this.springConfigurationClasses!=null)
			return ImmutableSet.copyOf(Iterables.concat(this.springConfigurationClasses, extract(()->Module.super.getSpringConfigurationClasses())));
			
		return Module.super.getSpringConfigurationClasses();
	}

	

	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy