Example usage for javax.naming InitialContext InitialContext

List of usage examples for javax.naming InitialContext InitialContext

Introduction

In this page you can find the example usage for javax.naming InitialContext InitialContext.

Prototype

public InitialContext(Hashtable<?, ?> environment) throws NamingException 

Source Link

Document

Constructs an initial context using the supplied environment.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);
    Object obj = ctx.lookup("Sample");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);

    // Create a subcontext.
    Context childCtx = ctx.createSubcontext("child");

    // Destroy the subcontext.
    ctx.destroySubcontext("child");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);
    // Create a subcontext.
    Context childCtx = ctx.createSubcontext("child");

    // Destroy the subcontext.
    ctx.destroySubcontext("child");

    Context obj = (Context) childCtx.lookup("grandChild");
    String fullname = obj.getNameInNamespace();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);
    // Add a binding.
    ctx.bind("Name", null);

    // Replace a binding.
    ctx.rebind("Name", null);

    // Remove a binding.
    ctx.unbind("Name");

    // Rename a binding.
    ctx.rename("Name", "NewSample");
}

From source file:List.java

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

    Object item = null;/*from  w ww .j  a v  a  2  s. com*/

    Context initCtx = new InitialContext(env);
    NamingEnumeration nl = initCtx.list("reports");

    if (nl == null)
        System.out.println("\nNo items in name list");
    else
        while (nl.hasMore()) {
            item = nl.next();
            System.out.println("item's class is " + item.getClass().getName());
            System.out.println(item);
            System.out.println("");
        }
}

From source file:Print.java

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");

    env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

    Context initCtx = new InitialContext(env);
    File f = (File) initCtx.lookup("reports/report1.txt");
    if (f != null) {
        BufferedReader br = new BufferedReader(new FileReader(f));
        String l = null;//from  w  w w .  j  a  va 2s  .co m
        while ((l = br.readLine()) != null)
            System.out.println(l);
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);
    NameParser parser = ctx.getNameParser("");
    Name dn = parser.parse("cn=John, ou=People, o=JNDITutorial");

    dn.remove(1);//  w  w  w.j a  va 2 s .  c o m
    dn.add(0, "c=us");
    dn.add("cn=fs");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "iiop://localhost/";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    Context ctx = new InitialContext(env);

    NamingEnumeration e = ctx.list("child");
    while (e.hasMore()) {
        NameClassPair entry = (NameClassPair) e.next();
        System.out.println(entry.getName());
    }//from   ww  w . ja  v  a2  s .co m
}

From source file:Bind.java

License:asdf

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:/tmp");

    Context initCtx = new InitialContext(env);
    initCtx.rebind("Susan", new Car("Toyota", "Camry"));
    Car c = (Car) initCtx.lookup("Susan");
    System.out.println(c);//from  ww  w .j  ava2 s  .c o  m

}