Search in sources :

Example 16 with NameParser

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

the class ManagerImpl method rebind.

/**
     * @param remoteDirectory	parent context of parentContext.
     * @param parent			name of context to bind.
     * @param parentContext		context to bind.
     * @throws NamingException
     *
    private void generateHiearchyContexts(Context remoteDirectory, String parent, Context parentContext) throws NamingException
    {
        /// @todo CORBA specific
        if (remoteDirectory instanceof com.sun.jndi.cosnaming.CNCtx)
        {
            boolean isParentDomain = remoteDirectory.getNameInNamespace().length() == 0 ||
            						 remoteDirectory.getNameInNamespace().endsWith(".D");

            org.omg.CORBA.Object parentRepresentation = ((com.sun.jndi.cosnaming.CNCtx)remoteDirectory)._nc;
            if (parent.endsWith(".D"))
            {
                // domain binding
                parentContext.rebind("Parent.D", parentRepresentation);
            }
            else if (parent.endsWith(".F"))
            {
                // hierarchical component binding
                if (isParentDomain)
                    parentContext.rebind("Domain.D", parentRepresentation);
                else
                    parentContext.rebind("Domain.D", remoteDirectory.lookup("Domain.D"));
                parentContext.rebind("Parent.F", parentRepresentation);
            }
        }
        else if (remoteDirectory instanceof InitialContext)
            generateHiearchyContexts((Context)((InitialContext)remoteDirectory).lookup(""), parent, parentContext);
        else
            new MessageLogEntry(this, "generateHiearchyContexts", "Unsupported remote directory, class '" + remoteDirectory.getClass().getName() + "'.", Level.WARNING).dispatch();
    }*/
/**
	 * Rebind object to the root of 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 ('.').
	 * NOTE: Does not support hierarchical names.
	 *
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	type	type of the object
	 * @param	object	object to be binded
	 *
	private void rebind(String name, String type, Object object)
	{
	    rebind(remoteDirectory, name, type, object);
	}*/
/**
	 * Rebind 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 ('.').
	 * NOTE: Does not support hierarchical names.
	 *
	 * @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
	 * @param	object	object to be binded
	 */
private void rebind(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 {
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            remoteDirectory.rebind(n, object);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to rebind name '" + name + "' to the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 17 with NameParser

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

the class ManagerImpl method unbind.

/**
	 * Unbind 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	type	type of the object
	 */
private void unbind(Context remoteDirectory, String name, String type) {
    assert (name != null);
    // do not unbind interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return;
    if (remoteDirectory != null) {
        try {
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            remoteDirectory.unbind(n);
            // NOTE: cleaning up the empty context nodes is not implemented
            // since access NS cannot provide quantum actions (transactions)
            // cleanup only empty ".F" contexts - only local manager
            // should modify local NS
            cleanupEmptyFContext(remoteDirectory, name);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to unbind name '" + name + "' from the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 18 with NameParser

use of javax.naming.NameParser in project deltaspike by apache.

the class JndiUtils method list.

/**
     * Resolves an instances for the given naming context.
     *
     * @param name       context name
     * @param type       target type
     * @param <T>        type
     * @return the found instances, null otherwise
     */
public static <T> Map<String, T> list(String name, Class<T> type) {
    Map<String, T> result = new HashMap<String, T>();
    try {
        NameParser nameParser = initialContext.getNameParser(name);
        NamingEnumeration<NameClassPair> enumeration = initialContext.list(name);
        while (enumeration.hasMoreElements()) {
            try {
                NameClassPair binding = enumeration.nextElement();
                Name bindingName = nameParser.parse(name).add(binding.getName());
                result.put(binding.getName(), lookup(bindingName, type));
            } catch (NamingException e) {
                if (LOG.isLoggable(Level.FINEST)) {
                    // this is expected if there is no entry in JNDI for the requested name or type
                    // so finest level is ok, if devs want to see it they can enable this logger level.
                    LOG.log(Level.FINEST, "InitialContext#list failed!", e);
                }
            }
        }
    } catch (NamingException e) {
        // this is fine at this point, since the individual lines will be caught currently.
        LOG.log(Level.WARNING, "Problem reading the name of the JNDI location " + name + " or failuring listing pairs.", e);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) NameClassPair(javax.naming.NameClassPair) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Aggregations

NameParser (javax.naming.NameParser)18 Name (javax.naming.Name)17 InitialContext (javax.naming.InitialContext)9 Context (javax.naming.Context)7 NamingException (javax.naming.NamingException)7 CoreException (com.cosylab.acs.maci.CoreException)4 HashMap (java.util.HashMap)3 CompositeName (javax.naming.CompositeName)3 NameNotFoundException (javax.naming.NameNotFoundException)3 Test (org.junit.Test)3 NamingEnumeration (javax.naming.NamingEnumeration)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 Session (javax.mail.Session)1 Binding (javax.naming.Binding)1 InvalidNameException (javax.naming.InvalidNameException)1