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

ca.uhn.hl7v2.hoh.api.AbstractReceivable Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
package ca.uhn.hl7v2.hoh.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractReceivable implements IReceivable {
	private final Map myMetadata = new HashMap();

	/**
	 * Add a metadata value
	 * 
	 * @param theKey The key
	 * @param theValue The value
	 * @throws NullPointerException If theKey is null
	 */
	public void addMetadata(String theKey, Object theValue) {
		if (theKey == null) {
			throw new NullPointerException("Key may not be null");
		}
		
		if (theValue != null) {
			if (MessageMetadataKeys.keyStringSet().contains(theKey)) {
				Class valueType = MessageMetadataKeys.valueOf(theKey).getValueType();
				if (!valueType.isAssignableFrom(theValue.getClass())) {
					throw new IllegalArgumentException("Value for key \"" + theKey + "\" must be of type: " + valueType.getName());
				}
			}
		}
		
		myMetadata.put(theKey, theValue);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public Map getMetadata() {
		return Collections.unmodifiableMap(myMetadata);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy