Search in sources :

Example 71 with Name

use of javax.naming.Name in project hibernate-orm by hibernate.

the class JndiRegionFactoryTest method bind.

/**
	 * Helper method that binds the a non serializable object to the JNDI tree.
	 *
	 * @param jndiName Name under which the object must be bound
	 * @param who Object to bind in JNDI
	 * @param classType Class type under which should appear the bound object
	 * @param ctx Naming context under which we bind the object
	 * @throws Exception Thrown if a naming exception occurs during binding
	 */
private void bind(String jndiName, Object who, Class<?> classType, Context ctx) throws Exception {
    // Ah ! This service isn't serializable, so we use a helper class
    NonSerializableFactory.bind(jndiName, who);
    Name n = ctx.getNameParser("").parse(jndiName);
    while (n.size() > 1) {
        String ctxName = n.get(0);
        try {
            ctx = (Context) ctx.lookup(ctxName);
        } catch (NameNotFoundException e) {
            log.debug("creating Subcontext " + ctxName);
            ctx = ctx.createSubcontext(ctxName);
        }
        n = n.getSuffix(1);
    }
    // The helper class NonSerializableFactory uses address type nns, we go on to
    // use the helper class to bind the service object in JNDI
    StringRefAddr addr = new StringRefAddr("nns", jndiName);
    Reference ref = new Reference(classType.getName(), addr, NonSerializableFactory.class.getName(), null);
    ctx.rebind(n.get(0), ref);
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NonSerializableFactory(org.jboss.util.naming.NonSerializableFactory) Name(javax.naming.Name)

Example 72 with Name

use of javax.naming.Name in project hibernate-orm by hibernate.

the class JBossStandaloneJtaExampleTest method bind.

/**
	 * Helper method that binds the a non serializable object to the JNDI tree.
	 *
	 * @param jndiName  Name under which the object must be bound
	 * @param who       Object to bind in JNDI
	 * @param classType Class type under which should appear the bound object
	 * @param ctx       Naming context under which we bind the object
	 * @throws Exception Thrown if a naming exception occurs during binding
	 */
private void bind(String jndiName, Object who, Class classType, Context ctx) throws Exception {
    // Ah ! This service isn't serializable, so we use a helper class
    NonSerializableFactory.bind(jndiName, who);
    Name n = ctx.getNameParser("").parse(jndiName);
    while (n.size() > 1) {
        String ctxName = n.get(0);
        try {
            ctx = (Context) ctx.lookup(ctxName);
        } catch (NameNotFoundException e) {
            System.out.println("Creating subcontext:" + ctxName);
            ctx = ctx.createSubcontext(ctxName);
        }
        n = n.getSuffix(1);
    }
    // The helper class NonSerializableFactory uses address type nns, we go on to
    // use the helper class to bind the service object in JNDI
    StringRefAddr addr = new StringRefAddr("nns", jndiName);
    Reference ref = new Reference(classType.getName(), addr, NonSerializableFactory.class.getName(), null);
    ctx.rebind(n.get(0), ref);
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NonSerializableFactory(org.jboss.util.naming.NonSerializableFactory) Name(javax.naming.Name)

Example 73 with Name

use of javax.naming.Name in project quickstarts by jboss-switchyard.

the class CamelJpaBindingTest method bind.

private static void bind(InitialContext initialContext, String name, Object object) throws NamingException {
    Name jndiName = initialContext.getNameParser("").parse(name);
    initialContext.bind(jndiName, object);
}
Also used : Name(javax.naming.Name)

Example 74 with Name

use of javax.naming.Name in project camel by apache.

the class JndiContext method composeName.

public Name composeName(Name name, Name prefix) throws NamingException {
    Name result = (Name) prefix.clone();
    result.addAll(name);
    return result;
}
Also used : CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 75 with Name

use of javax.naming.Name in project camel by apache.

the class JndiContext method composeName.

public Name composeName(Name name, Name prefix) throws NamingException {
    Name result = (Name) prefix.clone();
    result.addAll(name);
    return result;
}
Also used : CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

Name (javax.naming.Name)107 CompositeName (javax.naming.CompositeName)48 NamingException (javax.naming.NamingException)38 Context (javax.naming.Context)37 InitialContext (javax.naming.InitialContext)36 NameNotFoundException (javax.naming.NameNotFoundException)34 Test (org.junit.Test)32 Reference (javax.naming.Reference)24 NotContextException (javax.naming.NotContextException)22 Binding (javax.naming.Binding)19 CompoundName (javax.naming.CompoundName)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NameParser (javax.naming.NameParser)17 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 InvalidNameException (javax.naming.InvalidNameException)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)10 IOException (java.io.IOException)8 LinkRef (javax.naming.LinkRef)7 ServiceName (org.jboss.msc.service.ServiceName)7 Referenceable (javax.naming.Referenceable)6