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

org.apache.oodt.opendapps.config.ProcessingInstructions Maven / Gradle / Ivy

Go to download

A generic, configurable Apache OODT profile server implementation that easily connects to OPeNDAP data sources. Connections are configured via an XML configuration file, providing information on how to extract and translate datasets from OPeNDAP and THREDDS into OODT profiles.

There is a newer version: 1.0
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.oodt.opendapps.config;

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

import org.springframework.util.StringUtils;

/**
 * Class that holds special configuration instructions for generating an Opendap profile.
 * Instructions are stored as (name, values) pairs: each named instruction can have multiple values.
 * An instructions may be specified in the Opendap XML configuration file as a single element with comma-separated values,
 * or as multiple elements with the same name (and one or more values each).
 * 
 * @author Luca Cinquini
 *
 */
public class ProcessingInstructions {
	
	/**
	 * Local storage for processing instructions.
	 * Note that the order of the XML elements is not preserved (on purpose).
	 */
	private final Map> instructions = new HashMap>();
	
	/**
	 * Returns all values for a named instruction,
	 * or an empty set if the instruction was not specified.
	 * @param key
	 * @return
	 */
	public Set getInstructionValues(String key) {
		if (instructions.containsKey(key)) {
			return Collections.unmodifiableSet( instructions.get(key) );
		} else {
			return Collections.unmodifiableSet( new HashSet() );
		}
	}
	
	/**
	 * If an instruction contains a single value, it is returned.
	 * If the instruction has no values or multiple values, returns null instead.
	 * @param key
	 * @return
	 */
	public String getInstructionValue(String key) {
		if (instructions.get(key)!=null &&  instructions.get(key).size()==1) {
			for (String value : instructions.get(key)) {
				return value;
			}
		}
		return null;
	}
	
	/**
	 * Returns all instructions.
	 * @return
	 */
	public Map> getInstructions() {
		return Collections.unmodifiableMap(instructions);
	}
	
	/**
	 * Method to add a value to a named instruction.
	 * Value can be a comma separated list of values.
	 * Leading and trailing spaces for each value are removed.
	 * @param key
	 * @param value
	 */
	public void addInstruction(String key, String value) {
		if (StringUtils.hasText(key)) {
			if (!instructions.containsKey(key)) {
				instructions.put(key, new HashSet());
			}
			String[] vals = value.split(",");
			for (String val : vals) {
				if (StringUtils.hasText(val)) {
					instructions.get(key).add(val.trim());
				}
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy