decodes.comp.ComputationProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opendcs Show documentation
Show all versions of opendcs Show documentation
A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.
The newest version!
/*
* $Id$
*
* $Log$
* Revision 1.1.1.1 2014/05/19 15:28:59 mmaloney
* OPENDCS 6.0 Initial Checkin
*
* Revision 1.2 2009/06/18 18:01:56 mjmaloney
* Run computations from HTML display in dcp monitor
*
* Revision 1.1 2008/04/04 18:20:59 cvs
* Added legacy code to repository
*
* Revision 1.6 2007/06/27 20:57:36 mmaloney
* dev
*
* Revision 1.5 2004/08/24 14:31:28 mjmaloney
* Added javadocs
*
* Revision 1.4 2004/08/11 21:40:57 mjmaloney
* Improved javadocs
*
* Revision 1.3 2004/08/11 21:17:17 mjmaloney
* dev
*
* Revision 1.2 2004/06/24 18:36:06 mjmaloney
* Preliminary working version.
*
* Revision 1.1 2004/06/24 14:29:53 mjmaloney
* Created.
*
*/
/**
* @(#) ComputationProcessor.java
*/
package decodes.comp;
import decodes.comp.CompResolver;
import decodes.db.RoutingSpec;
//import decodes.decoder.DecodedMessage;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Element;
import ilex.util.EnvExpander;
import ilex.util.Logger;
import ilex.util.ErrorException;
import ilex.xml.DomHelper;
/**
* Handles the set of classes used for performing computations on
* decoded messages. An application should have one instance of this
* class.
*/
public class ComputationProcessor
{
/**
* Set of known resolvers, populated from configuration file.
*/
private ArrayList compResolvers;
/**
* Module name required by DOM reader.
*/
public static final String module = "ComputationProcessor";
/**
* Configuration file being read, used in warning messages.
*/
private String configFile;
private RoutingSpec routingSpec = null;
/**
* Resolve and execute all relavent computations for the passed
* DecodedMessage.
* @param msg the data collection
*/
public synchronized void applyComputations( IDataCollection msg )
{
for(CompResolver cr : compResolvers)
{
Computation comps[] = cr.resolve(msg);
if (comps != null)
for(int i=0; i< comps.length; i++)
comps[i].apply(msg);
}
}
/**
* Construct new ComputationProcessor.
*/
public ComputationProcessor( )
{
compResolvers = new ArrayList();
}
/**
* Initialize the computation processor from the named configuraiton file.
* @param configFile name of configuration file to use.
* @param routingSpec The routing spec that we're running under, or null
* if this is for the DCP Monitor.
*/
public synchronized void init( String configFile, RoutingSpec routingSpec )
throws BadConfigException
{
Logger.instance().debug1(module + " initializing with config file '"
+ configFile + "' for routing spec '" + routingSpec.getName() + "'");
this.configFile = configFile;
this.routingSpec = routingSpec;
// MJM 6/18/2009 - Allow init to be called multiple times. Each time
// It throws away anything it had before.
compResolvers = new ArrayList();
Document doc;
try
{
doc = DomHelper.readFile(module, EnvExpander.expand(configFile));
}
catch(ilex.util.ErrorException ex)
{
throw new BadConfigException(ex.toString());
}
Node element = doc.getDocumentElement();
if (!element.getNodeName().equalsIgnoreCase("ComputationProcessor"))
{
String s = module
+ ": Wrong type of configuration file -- Cannot initialize. "
+ "Root element is not 'ComputationProcessor'.";
Logger.instance().failure(s);
throw new BadConfigException(s);
}
NodeList children = element.getChildNodes();
if (children != null)
{
int length = children.getLength();
for(int i=0; i