// Path: JMSPerfHarness/src/com/ibm/uk/hursley/perfharness/jms/DestinationWrapper.java
// public final class DestinationWrapper<E extends Destination> {
// 	
// 	public E destination;
// 	public String name;
// 	
// 	public DestinationWrapper( String name, E destination ) {
// 		this.destination = destination;
// 		this.name = name;
// 	}
// 	
// }


import java.io.File;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import com.ibm.uk.hursley.perfharness.Config;
import com.ibm.uk.hursley.perfharness.Log;
import com.ibm.uk.hursley.perfharness.jms.DestinationWrapper;
/********************************************************* {COPYRIGHT-TOP} ***
* Copyright 2016 IBM Corporation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the MIT License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/MIT
********************************************************** {COPYRIGHT-END} **/

package com.ibm.uk.hursley.perfharness.jms.providers;




/**
 * Provider independent access to JMS resources.  All destination names will be
 * interpreted as the lookup name rather than the absolute name.
 * <p>This class also provides a base on which to build vendor-specific JMSProvider
 * implementations which may also use JNDI. 
 */
public class JNDI extends AbstractJMSProvider {

	@SuppressWarnings("unused")
	private static final String c = com.ibm.uk.hursley.perfharness.Copyright.COPYRIGHT; // IGNORE compiler warning

	public static final String PSMODE = "PUBSUBMODE";
	public static final String PSMODE_PUB = "PUB";
	public static final String PSMODE_SUB = "SUB";
	
	protected static boolean usingJNDI;	

	/**
	 * Validate parameters.  The contents of <code>-ii</code> and <code>-iu</code> are not checked at this stage.
	 */
	public static void registerConfig() {

		Config.registerSelf( JNDI.class );
		usingJNDI = ! "".equals( Config.parms.getString("cf") ) || Config.parms.getString("pc").equalsIgnoreCase("jndi");
		
	}
	
	protected InitialContext initialContext = null;

	
	//
	// JMS 1.0.2 Methods
	//

	/**
	 * Return a Queue object from JNDI
	 */
// Path: JMSPerfHarness/src/com/ibm/uk/hursley/perfharness/jms/DestinationWrapper.java
// public final class DestinationWrapper<E extends Destination> {
// 	
// 	public E destination;
// 	public String name;
// 	
// 	public DestinationWrapper( String name, E destination ) {
// 		this.destination = destination;
// 		this.name = name;
// 	}
// 	
// }


// Path: JMSPerfHarness/src/com/ibm/uk/hursley/perfharness/jms/providers/JNDI.java
import java.io.File;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import com.ibm.uk.hursley.perfharness.Config;
import com.ibm.uk.hursley.perfharness.Log;
import com.ibm.uk.hursley.perfharness.jms.DestinationWrapper;

/********************************************************* {COPYRIGHT-TOP} ***
* Copyright 2016 IBM Corporation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the MIT License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/MIT
********************************************************** {COPYRIGHT-END} **/

package com.ibm.uk.hursley.perfharness.jms.providers;




/**
 * Provider independent access to JMS resources.  All destination names will be
 * interpreted as the lookup name rather than the absolute name.
 * <p>This class also provides a base on which to build vendor-specific JMSProvider
 * implementations which may also use JNDI. 
 */
public class JNDI extends AbstractJMSProvider {

	@SuppressWarnings("unused")
	private static final String c = com.ibm.uk.hursley.perfharness.Copyright.COPYRIGHT; // IGNORE compiler warning

	public static final String PSMODE = "PUBSUBMODE";
	public static final String PSMODE_PUB = "PUB";
	public static final String PSMODE_SUB = "SUB";
	
	protected static boolean usingJNDI;	

	/**
	 * Validate parameters.  The contents of <code>-ii</code> and <code>-iu</code> are not checked at this stage.
	 */
	public static void registerConfig() {

		Config.registerSelf( JNDI.class );
		usingJNDI = ! "".equals( Config.parms.getString("cf") ) || Config.parms.getString("pc").equalsIgnoreCase("jndi");
		
	}
	
	protected InitialContext initialContext = null;

	
	//
	// JMS 1.0.2 Methods
	//

	/**
	 * Return a Queue object from JNDI
	 */
	protected DestinationWrapper<Queue> lookupQueueFromJNDI(String uri)	throws NamingException {