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

net.anotheria.anoprise.metafactory.AbstractParameterizedServiceFactory Maven / Gradle / Ivy

Go to download

Collection of utils for different enterprise class projects. Among other stuff contains Caches, Mocking, DualCrud, MetaFactory and SessionDistributorService. Visit https://opensource.anotheria.net for details.

There is a newer version: 4.0.0
Show newest version
package net.anotheria.anoprise.metafactory;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Abstract {@link ParameterizedServiceFactory} implementation.
 * 
 * @author Alexandr Bolbat
 * 
 * @param 
 */
public abstract class AbstractParameterizedServiceFactory implements ParameterizedServiceFactory {

	/**
	 * Factory parameters.
	 */
	private Map parameters;

	@Override
	public void setParameters(final Map aParameters) {
		this.parameters = aParameters;
	}

	/**
	 * Add parameter.
	 * 
	 * @param parameterName
	 *            parameter name
	 * @param parameterValue
	 *            parameter value
	 */
	public void addParameter(final String parameterName, final Serializable parameterValue) {
		if (parameterName == null || parameterName.trim().isEmpty() || parameterValue == null)
			return;

		if (parameters == null)
			synchronized (this) {
				if (parameters == null)
					parameters = new HashMap();
			}

		parameters.put(parameterName, parameterValue);
	}

	/**
	 * Get all parameters map.
	 * 
	 * @return {@link Map}
	 */
	protected Map getParameters() {
		return parameters != null ? new HashMap(parameters) : new HashMap();
	}

	/**
	 * Get all parameters names.
	 * 
	 * @return {@link List} of {@link String}
	 */
	protected List getParametersNames() {
		return parameters != null ? new ArrayList(parameters.keySet()) : new ArrayList();
	}

	/**
	 * Get parameter value.
	 * 
	 * @param parameterName
	 *            parameter name
	 * @return {@link Serializable} value or empty {@link String} if parameter not exist
	 */
	protected Serializable getParameterValue(final String parameterName) {
		if (parameterName == null || parameterName.trim().isEmpty() || parameters == null)
			return "";

		Serializable value = parameters.get(parameterName);
		return value != null ? value : "";
	}

	/**
	 * Get parameter value as {@link String}.
	 * 
	 * @param parameterName
	 *            parameter name
	 * @return {@link Serializable} value or empty {@link String} if parameter not exist
	 */
	protected String getParameterValueAsString(final String parameterName) {
		return String.valueOf(getParameterValue(parameterName));
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy