Version 2

    The org.jnp.interfaces.LocalOnlyContextFactory is an javax.naming.spi.InitialContextFactory implementation which connects to the JVM local JBossNS server without any transport. It uses direct acess to NamingContex.getLocalServer() naming server org.jnp.interfaces.Naming implementation, which has to have been set previously via the NamingContext.setLocalServer() method.

     

    Components in the same JVM as the JBossNS server can use this to connect to the naming server. It cannot be used by external clients.

     

    Microcontainer Deployment Example

    Here is an mc jboss-beans.xml that shows the use of the LocalOnlyContextFactory as a pojo for injecting an InitialContextFactory into the JndiBindings bean:

     

    <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
        xmlns="urn:jboss:bean-deployer:2.0">
    
        <bean name="InitialContextFactory" class="org.jboss.naming.InitialContextFactoryBean">
            <property name="env">
                <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
                    <entry>
                        <key>java.naming.factory.initial</key>
                        <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                    </entry>
                    <entry>
                        <key>java.naming.factory.url</key>
                        <value>org.jboss.naming:org.jnp.interfaces</value>
                    </entry>
                </map>
            </property>
            <depends>testLocaNamingBeanImpl</depends>
        </bean>
        <bean name="JndiBindings" class="org.jboss.naming.BindingsInitializer">
            <property name="ctx">
                <inject bean="InitialContextFactory" property="ctx"/>
            </property>
            <property name="bindings">
                <map keyClass="java.lang.String">
                    <entry>
                        <key>ints/1</key>
                        <value class="java.lang.Integer">1</value>
                    </entry>
                    <entry>
                        <key>strings/1</key>
                        <value class="java.lang.String">String1</value>
                    </entry>
                    <entry>
                        <key>bigint/1</key>
                        <value class="java.math.BigInteger">123456789</value>
                    </entry>
                    <entry>
                        <key>env-props</key>
                        <value>
                            <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
                            <entry>
                                <key>java.naming.factory.initial</key>
                                <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                            </entry>
                            <entry>
                                <key>java.naming.factory.url</key>
                                <value>org.jboss.naming:org.jnp.interfaces</value>
                            </entry>
                            </map>
                        </value>
                    </entry>
                </map>
            </property>
        </bean>
        <bean name="testLocaNamingBeanImpl" class="org.jnp.server.NamingBeanImpl">
            <!-- Install this bean as the global JVM NamingServer -->
            <property name="installGlobalService">true</property>
            
            <property name="useGlobalService">false</property>
        </bean>
    
    </deployment>
    
    

    Programatic Example

       /**
        * Validate that the NamingBeanImpl mc bean is accessible via the
        * InitialContext(env) using the LocalOnlyContextFactory
        * @throws Exception
        */
       public void testLocaNamingBeanImplViaInitialContextFactory()
          throws Exception
       {
          Properties env = new Properties();
          env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
          env.setProperty("java.naming.factory.url", "org.jboss.naming:org.jnp.interfaces");
          InitialContext ic = new InitialContext(env);
          validateCtx(ic);
       }