Parsing a JNDI Composite Name - Java JNDI

Java examples for JNDI:Name

Description

Parsing a JNDI Composite Name

Demo Code

import javax.naming.CompositeName;
import javax.naming.NamingException;

public class Main {
  public static void main(String[] args) throws Exception {
    try {/*from www .j ava  2  s  .c o m*/
      CompositeName composite = new CompositeName(
          "cn=YourName,o=hits/report/summary.txt");
      String first = composite.get(0); // cn=YourName,o=hits
      String last = composite.get(composite.size() - 1); // summary.txt

      composite.add(0, "wiz.com"); // wiz.com/cn=YourName,o=hits/report/summary.txt
      composite.remove(2); // wiz.com/cn=YourName,o=hits/summary.txt
    } catch (NamingException e) {
    }
  }
}

Related Tutorials