+

Search Tips   |   Advanced Search

 

Example: Setting the syntax used to parse name strings

 

JNDI clients that must interoperate with CORBA applications might need to use INS name syntax to represent names in string format.

The name syntax property can be passed to the InitialContext constructor through its parameter, in the System properties, or in a jndi.properties file. The initial context and any contexts looked up from that initial context parse name strings based on the specified syntax.

The following example shows how to set the name syntax to make the initial context parse name strings according to INS syntax.

... import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import com.ibm.websphere.naming.PROPS; // WebSphere naming constants
...
Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,
      "com.ibm.websphere.naming.WsnInitialContextFactory"); env.put(Context.PROVIDER_URL, ...); env.put(PROPS.NAME_SYNTAX, PROPS.NAME_SYNTAX_INS);
Context initialContext = new InitialContext(env);
// The following name maps to a CORBA name component as follows:
//    id = "a.name", kind = "in.INS.format"
// The unescaped dot is used as the delimiter.
// Escaped dots are interpreted literally. java.lang.Object o = initialContext.lookup("a\\.name.in\\.INS\\.format");
...

INS name syntax requires that embedded periods (.) in a name such as in.INS.format be escaped using a backslash character (\). In a Java String literal, a backslash character (\) must be escaped with another backslash character (\\).


 

Related tasks


Developing applications that use JNDI

 

Reference topic