//
// SetupJNDI.java - Register things in JNDI to support App.java sample code
//

import java.util.*;
import javax.jms.*;
import javax.naming.*;
// import com.tibco.tibjms.naming.*;
import nyangau.jmsadapter.*;

public class SetupJNDI
  {
  public static void main(String[] args)
    {
    try
      {
      // The JNDI we're going to store Jmsa AOs into
      InitialContext ic = new InitialContext(
        new Hashtable<String,Object>()
          {{
          // We're going to use the cheap and cheerful filesystem based JNDI
          put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
          put(Context.PROVIDER_URL, "file:fs");
/*
          // Other vendor unique parameters used to talk to JNDI,
          // such as LDAP specific or SSL specific ones, would be added here
          put(...);
*/        
          }}
        );

      // The properties used to reach the underlying JNDI implementation
      Hashtable<String,Object> ht = new Hashtable<String,Object>()
        {{
        // We're hosting queues on a local Tibco EMS and using its JNDI
        put(Context.INITIAL_CONTEXT_FACTORY, "com.tibco.tibjms.naming.TibjmsInitialContextFactory");
        put(Context.PROVIDER_URL, "tcp://localhost:7222");
/*
        // Other vendor unique parameters used to talk to JNDI,
        // such as SSL ones, would be added here
        put(Context.SECURITY_PRINCIPAL, "admin");
        put(Context.SECURITY_CREDENTIALS, "password");
        put(TibjmsContext.SSL_ENABLE_VERIFY_HOST, new Boolean(false));
        put(TibjmsContext.SSL_ENABLE_VERIFY_HOST_NAME, new Boolean(false));
        put(TibjmsContext.SSL_TRUSTED_CERTIFICATES,
          new Vector<String>()
            {{
            add("root1.cert.pem");
            add("root2.cert.pem");
            }}
          );
*/
        }};

      // We're going to need a QCF
      ic.rebind(
        "qcf",
        new JmsaQueueConnectionFactory(
          ht,
          new Hashtable<String,Object>()
            {{
            put(Jmsa.UNDERLYING_CONNECTION_FACTORY, "QueueConnectionFactory");
            put(Jmsa.CONFIG, "file:appstd.xml");
            put(Jmsa.PROPERTIES, "file:appstd.properties");
            }}
          )
        );

      // Lets create a Q for deals
      ic.rebind(
        "appdealq",
        new JmsaQueue(
          ht,
          new Hashtable<String,Object>()
            {{
            put(Jmsa.UNDERLYING_DESTINATION, "stddealq");
            }}
          )
        );

      // Lets create a Q for confirmations
      ic.rebind(
        "appconfirmq",
        new JmsaQueue(
          ht,
          new Hashtable<String,Object>()
            {{
            put(Jmsa.UNDERLYING_DESTINATION, "stdconfirmq");
            }}
          )
        );

      }
    catch ( NamingException e )
      {
      e.printStackTrace();
      }
    }
  }
