//
// DataMap.java - Data Mapper base class
//

package nyangau.jmsadapter;

//...simports:0:
import java.util.Set;
import java.util.Map;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
//...e

public class DataMap
  {
  protected static int unnamed = 0;
  protected String name;
//...sDataMap:2:
public DataMap(Node eMap)
  throws FlowProcessorException
  {
  NamedNodeMap nnmDataMap = eMap.getAttributes();
  Node aName = nnmDataMap.getNamedItem("name");
  name = ( aName != null )
    ? aName.getNodeValue()
    : ( "__unnamedDataMap"+unnamed++ );

  // Opportunity to pull out things which make sense for every DataMap.
  // eg: we could enable debugging on each one.
  // At the moment, we don't do this.
  }
//...e
//...sgetName:2:
public String getName()
  { return name; }
//...e
//...smap:2:
public void map(Set<String> unmapped, Map<String,String> mapped)
  throws FlowProcessorException
  {
  }
//...e
//...snewDataMap:2:
public static DataMap newDataMap(Node eDataMap)
  throws FlowProcessorException
  {
  String datamapName = eDataMap.getNodeName();
  if ( datamapName.equals("mapdefault") )
    return new DataMapDefault(eDataMap);
  if ( datamapName.equals("mapinline") )
    return new DataMapInline(eDataMap);
  if ( datamapName.equals("mapprops") )
    return new DataMapProperties(eDataMap);
  if ( datamapName.equals("mapdb") )
    return new DataMapDatabase(eDataMap);
  if ( datamapName.equals("mapws") )
    return new DataMapWebService(eDataMap);
  if ( datamapName.equals("mapcache") )
    return new DataMapCache(eDataMap);
  if ( datamapName.equals("maplist") )
    return new DataMapList(eDataMap);
  if ( datamapName.equals("mapuser") )
//...suse Class\46\forName:6:
{
NamedNodeMap nnmDataMap = eDataMap.getAttributes();
Node aClass = nnmDataMap.getNamedItem("class");
if ( aClass == null )
  throw new FlowProcessorException("unexpected missing class in mapuser, bad jmsadapter.xsd?");
String className = aClass.getNodeValue();
Class<?> c;
try
  {
  c = Class.forName(className);
  }
catch ( ClassNotFoundException e )
  {
  throw new FlowProcessorException("ClassNotFoundException loading "+className, e);
  }
Constructor ctor;
try
  {
  ctor = c.getConstructor(new Class[]{Node.class});
  }
catch ( NoSuchMethodException e )
  {
  throw new FlowProcessorException("named class "+className+" doesn't have an appropriate constructor", e);
  }
catch ( SecurityException e )
  {
  throw new FlowProcessorException("named class "+className+" constructor can't be called", e);
  }
try
  {
  return (DataMap) ctor.newInstance(new Object[]{eDataMap});
  }
catch ( InstantiationException e )
  {
  throw new FlowProcessorException("InstantiationException creating a newInstance of "+className, e);
  }
catch ( IllegalAccessException e )
  {
  throw new FlowProcessorException("IllegalAccessException creating a newInstance of "+className, e);
  }
catch ( IllegalArgumentException e )
  {
  throw new FlowProcessorException("IllegalArgumentException creating a newInstance of "+className, e);
  }
catch ( InvocationTargetException e )
  {
  throw new FlowProcessorException("InvocationTargetException creating a newInstance of "+className, e);
  }
}
//...e
  throw new FlowProcessorException("unknown data map type "+datamapName+", bad jmsadapter.xsd?");
  }
//...e
  }
