Search in sources :

Example 21 with Name

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

the class JndiServiceImpl method addListener.

@Override
public void addListener(String jndiName, NamespaceChangeListener listener) {
    final InitialContext initialContext = buildInitialContext();
    final Name name = parseName(jndiName, initialContext);
    try {
        ((EventContext) initialContext).addNamingListener(name, EventContext.OBJECT_SCOPE, listener);
    } catch (Exception e) {
        throw new JndiException("Unable to bind listener to namespace [" + name + "]", e);
    } finally {
        cleanUp(initialContext);
    }
}
Also used : EventContext(javax.naming.event.EventContext) JndiException(org.hibernate.engine.jndi.JndiException) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) JndiNameException(org.hibernate.engine.jndi.JndiNameException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) Name(javax.naming.Name)

Example 22 with Name

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

the class JndiServiceImpl method locate.

@Override
public Object locate(String jndiName) {
    final InitialContext initialContext = buildInitialContext();
    final Name name = parseName(jndiName, initialContext);
    try {
        return initialContext.lookup(name);
    } catch (NamingException e) {
        throw new JndiException("Unable to lookup JNDI name [" + jndiName + "]", e);
    } finally {
        cleanUp(initialContext);
    }
}
Also used : NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) InitialContext(javax.naming.InitialContext) Name(javax.naming.Name)

Example 23 with Name

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

the class JndiServiceImpl method unbind.

@Override
public void unbind(String jndiName) {
    final InitialContext initialContext = buildInitialContext();
    final Name name = parseName(jndiName, initialContext);
    try {
        initialContext.unbind(name);
    } catch (Exception e) {
        throw new JndiException("Error performing unbind [" + name + "]", e);
    } finally {
        cleanUp(initialContext);
    }
}
Also used : JndiException(org.hibernate.engine.jndi.JndiException) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) JndiNameException(org.hibernate.engine.jndi.JndiNameException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) Name(javax.naming.Name)

Example 24 with Name

use of javax.naming.Name in project ACS by ACS-Community.

the class ManagerImpl method bind.

/**
	 * Bind object to remote directory.
	 *
	 * Use INS syntax specified in the INS specification.
	 * In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
	 * The id and kind of each component are separated by the period character ('.').
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	object	object to be binded
	 */
private void bind(Context remoteDirectory, String name, String type, Object object) {
    assert (name != null);
    // do not bind interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return;
    if (remoteDirectory != null) {
        try {
            // hierarchical name check
            int pos = name.indexOf('/');
            if (pos != -1) {
                if (pos == 0 || pos == name.length())
                    throw new IllegalArgumentException("Invalid hierarchical name '" + name + "'.");
                String parent = name.substring(0, pos);
                String child = name.substring(pos + 1);
                // lookup for subcontext, if not found create one
                Context parentContext = null;
                try {
                    parentContext = (Context) remoteDirectory.lookup(parent);
                } catch (NameNotFoundException nnfe) {
                // noop
                }
                if (parentContext == null) {
                    parentContext = remoteDirectory.createSubcontext(parent);
                /// @todo temp. commented out
                //generateHiearchyContexts(remoteDirectory, parent, parentContext);
                }
                // delegate
                bind(parentContext, child, type, object);
                return;
            }
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            // special case
            if (name.endsWith(".D")) {
                remoteDirectory.rebind(n, object);
            /// @todo temp. commented out
            //generateHiearchyContexts(remoteDirectory, name, (Context)remoteDirectory.lookup(name));
            } else
                remoteDirectory.bind(n, object);
        } catch (NameAlreadyBoundException nabe) {
            rebind(remoteDirectory, name, type, object);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to bind name '" + name + "' to the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) CoreException(com.cosylab.acs.maci.CoreException) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 25 with Name

use of javax.naming.Name in project ACS by ACS-Community.

the class ManagerImpl method lookup.

/**
	 * Lookups for an object in remote directory.
	 *
	 * Use INS syntax specified in the INS specification.
	 * In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
	 * The id and kind of each component are separated by the period character ('.').
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	type	type of the object
	 * @return	object	object found in the remote directory, <code>null<code> if nout found
	 */
private Object lookup(Context remoteDirectory, String name, String type) {
    assert (name != null);
    // do not look for interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return null;
    Object resolved = null;
    if (remoteDirectory != null) {
        try {
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            resolved = remoteDirectory.lookup(n);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to lookup name '" + name + "' in the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
    return resolved;
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) 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