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

prompto.config.IRuntimeConfiguration Maven / Gradle / Ivy

The newest version!
package prompto.config;

import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.function.Supplier;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;
import com.esotericsoftware.yamlbeans.document.YamlSequence;

import prompto.intrinsic.PromptoVersion;
import prompto.runtime.Mode;

public interface IRuntimeConfiguration {
	Supplier> getRuntimeLibs();
	IStoreConfiguration getCodeStoreConfiguration();
	IStoreConfiguration getDataStoreConfiguration();
	IDebugConfiguration getDebugConfiguration();
	Mode getRuntimeMode();
	Map getArguments();
	String getApplicationName();
	PromptoVersion getApplicationVersion();
	URL[] getAddOnURLs();
	URL[] getResourceURLs();
	boolean isLoadRuntime();
	YamlMapping toYaml() throws YamlException;
	
	 T withRuntimeLibs(Supplier> supplier);
	 T withCodeStoreConfiguration(IStoreConfiguration supplier);
	 T withDataStoreConfiguration(IStoreConfiguration supplier);
	 T withAddOnURLs(URL[] addOnURLS);
	 T withApplicationName(String name);
	 T withApplicationVersion(PromptoVersion version);
	 T withResourceURLs(URL[] resourceURLs);
	 T withRuntimeMode(Mode mode);
	 T withLoadRuntime(boolean set);
	 T withDebugConfiguration(IDebugConfiguration config);


	@SuppressWarnings("unchecked")
	public static class Inline implements IRuntimeConfiguration {
		
		Supplier> runtimeLibs = null; // always passed from code
		Supplier> arguments = ()->Collections.emptyMap();
		Supplier debugConfiguration = ()->null;
		Supplier codeStoreConfiguration = ()->null;
		Supplier dataStoreConfiguration = ()->null;
		Supplier runtimeMode = ()->Mode.PRODUCTION;
		Supplier loadRuntime = ()->true;
		Supplier addOnURLs = ()->null;
		Supplier resourceURLs = ()->null;
		Supplier applicationName = ()->null;
		Supplier applicationVersion = ()->null;

		@Override public Supplier>getRuntimeLibs() { return runtimeLibs; }
		@Override public IStoreConfiguration getCodeStoreConfiguration() { return codeStoreConfiguration.get(); }
		@Override public IStoreConfiguration getDataStoreConfiguration() { return dataStoreConfiguration.get(); }
		@Override public IDebugConfiguration getDebugConfiguration() { return debugConfiguration.get(); }
		@Override public Map getArguments() { return arguments.get(); }
		@Override public String getApplicationName() { return applicationName.get(); }
		@Override public PromptoVersion getApplicationVersion() { return applicationVersion.get(); }
		@Override public Mode getRuntimeMode() { return runtimeMode.get(); }
		@Override public URL[] getAddOnURLs() { return addOnURLs.get(); }
		@Override public URL[] getResourceURLs() { return resourceURLs.get(); }
		@Override public boolean isLoadRuntime() { return loadRuntime.get(); }
		
		@Override 
		public  T withRuntimeLibs(Supplier> runtimeLibs) {
			this.runtimeLibs = runtimeLibs;
			return (T)this;
		}
		
		@Override
		public  T withCodeStoreConfiguration(IStoreConfiguration storeConfig) {
			this.codeStoreConfiguration = ()->storeConfig;
			return (T)this;
		}
		
		@Override
		public  T withDataStoreConfiguration(IStoreConfiguration storeConfig) {
			this.dataStoreConfiguration = ()->storeConfig;
			return (T)this;
		}
		
		@Override 
		public  T withAddOnURLs(URL[] urls) {
			this.addOnURLs = ()->urls;
			return (T)this;
		}

		@Override 
		public  T withApplicationName(String name) {
			this.applicationName = ()->name;
			return (T)this;
		}

		@Override 
		public  T withApplicationVersion(PromptoVersion version) {
			this.applicationVersion = ()->version;
			return (T)this;
		}
		
		@Override 
		public  T withResourceURLs(URL[] urls) {
			this.resourceURLs = ()->urls;
			return (T)this;
		}
		
		@Override
		public  T withRuntimeMode(Mode mode) {
			this.runtimeMode = ()->mode;
			return (T)this;
		}
		
		@Override
		public  T withLoadRuntime(boolean set) {
			this.loadRuntime = ()->set;
			return (T)this;
		}
		
		@Override
		public  T withDebugConfiguration(IDebugConfiguration config) {
			this.debugConfiguration = ()->config;
			return (T)this;
		}
		
		@Override
		public YamlMapping toYaml() throws YamlException {
			YamlMapping yaml = new YamlMapping();
			String value = applicationName.get();
			if(value!=null)
				yaml.setEntry("applicationName", value);
			if(applicationVersion.get()!=null)
				yaml.setEntry("applicationVersion", applicationVersion.get().toString());
			IStoreConfiguration config = codeStoreConfiguration.get();
			if(config!=null)
				yaml.setEntry("codeStore", config.toYaml());
			config = dataStoreConfiguration.get();
			if(config!=null)
				yaml.setEntry("dataStore", config.toYaml());
			Mode mode = runtimeMode.get();
			if(mode!=null)
				yaml.setEntry("runtimeMode", mode.name());
			URL[] urls = addOnURLs.get();
			if(urls!=null) {
				YamlSequence sequence = new YamlSequence();
				for(URL url : urls)
					sequence.addElement(url.toExternalForm());
				yaml.setEntry("addOnURLs", sequence);
			}
			urls = resourceURLs.get();
			if(urls!=null) {
				YamlSequence sequence = new YamlSequence();
				for(URL url : urls)
					sequence.addElement(url.toExternalForm());
				yaml.setEntry("resourceURLs", sequence);
			}
			return yaml;
		}
		
	}


	



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy