Search in sources :

Example 1 with NonSerializableFactory

use of org.jboss.util.naming.NonSerializableFactory 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 2 with NonSerializableFactory

use of org.jboss.util.naming.NonSerializableFactory 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)

Aggregations

Name (javax.naming.Name)2 NameNotFoundException (javax.naming.NameNotFoundException)2 Reference (javax.naming.Reference)2 StringRefAddr (javax.naming.StringRefAddr)2 NonSerializableFactory (org.jboss.util.naming.NonSerializableFactory)2