Java Code Examples for javax.naming.Name#size()

The following examples show how to use javax.naming.Name#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Removes name and its associated object from the context.
 * 
 * @param name name to remove
 * @throws NoPermissionException if this context has been destroyed.
 * @throws InvalidNameException if name is empty or is CompositeName that
 *           spans more than one naming system
 * @throws NameNotFoundException if intermediate context can not be found
 * @throws NotContextException if name has more than one atomic name and
 *           intermediate context is not found.
 * @throws NamingException if any other naming exception occurs
 *  
 */
public void unbind(Name name) throws NamingException {
  checkIsDestroyed();
  Name parsedName = getParsedName(name);
  if (parsedName.size() == 0 || parsedName.get(0).length() == 0) { throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString()); }
  String nameToRemove = parsedName.get(0);
  // scenerio unbind a
  // remove a and its associated object
  if (parsedName.size() == 1) {
    ctxMaps.remove(nameToRemove);
  }
  else {
    //        	 scenerio unbind a/b or a/b/c
    //        	 remove b and its associated object
    Object boundObject = ctxMaps.get(nameToRemove);
    if (boundObject instanceof Context) {
      //                remove b and its associated object
      ((Context) boundObject).unbind(parsedName.getSuffix(1));
    }
    else {
      // 			if the name is not found then throw exception
      if (!ctxMaps.containsKey(nameToRemove)) { throw new NameNotFoundException(LocalizedStrings.ContextImpl_CAN_NOT_FIND_0.toLocalizedString(name)); }
      throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
    }
  }
}
 
Example 2
Source File: NamingContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the parser associated with the named context. In a 
 * federation of namespaces, different naming systems will parse names 
 * differently. This method allows an application to get a parser for 
 * parsing names into their atomic components using the naming convention 
 * of a particular naming system. Within any single naming system, 
 * NameParser objects returned by this method must be equal (using the 
 * equals() test).
 * 
 * @param name the name of the context from which to get the parser
 * @return a name parser that can parse compound names into their atomic 
 * components
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NameParser getNameParser(Name name)
    throws NamingException {

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        return nameParser;

    if (name.size() > 1) {
        Object obj = bindings.get(name.get(0));
        if (obj instanceof Context) {
            return ((Context) obj).getNameParser(name.getSuffix(1));
        } else {
            throw new NotContextException
                (sm.getString("namingContext.contextExpected"));
        }
    }

    return nameParser;

}
 
Example 3
Source File: NamingContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Destroys the named context and removes it from the namespace. Any
 * attributes associated with the name are also removed. Intermediate
 * contexts are not destroyed.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic
 * name is not bound in the target context, but throws
 * NameNotFoundException if any of the intermediate contexts do not exist.
 *
 * In a federated naming system, a context from one naming system may be
 * bound to a name in another. One can subsequently look up and perform
 * operations on the foreign context using a composite name. However, an
 * attempt destroy the context using this composite name will fail with
 * NotContextException, because the foreign context is not a "subcontext"
 * of the context in which it is bound. Instead, use unbind() to remove
 * the binding of the foreign context. Destroying the foreign context
 * requires that the destroySubcontext() be performed on a context from
 * the foreign context's "native" naming system.
 *
 * @param name the name of the context to be destroyed; may not be empty
 * @exception NameNotFoundException if an intermediate context does not
 * exist
 * @exception NotContextException if the name is bound but does not name
 * a context, or does not name a context of the appropriate type
 */
@Override
public void destroySubcontext(Name name) throws NamingException {

    if (!checkWritable()) {
        return;
    }

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));

    NamingEntry entry = bindings.get(name.get(0));

    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }

    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).destroySubcontext(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).close();
            bindings.remove(name.get(0));
        } else {
            throw new NotContextException
                (sm.getString("namingContext.contextExpected"));
        }
    }

}
 
Example 4
Source File: LocalContext.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public Object lookup(Name name) throws NamingException {
	if (name.isEmpty())
		return cloneCtx();

	Name nm = getMyComponents(name);
	String atom = nm.get(0);
	Object inter = iBindings.get(atom);

	if (nm.size() == 1) {
		if (inter == null)
			throw new NameNotFoundException(name + " not found");

		try {
			return NamingManager.getObjectInstance(inter, new CompositeName().add(atom), this, iEnv);
		} catch (Exception e) {
			NamingException ne = new NamingException("getObjectInstance failed");
			ne.setRootCause(e);
			throw ne;
		}
	} else {
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		return ((Context) inter).lookup(nm.getSuffix(1));
	}
}
 
Example 5
Source File: NamingContext.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Unbinds the named object. Removes the terminal atomic name in name 
 * from the target context--that named by all but the terminal atomic 
 * part of name.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic 
 * name is not bound in the target context, but throws 
 * NameNotFoundException if any of the intermediate contexts do not exist. 
 * 
 * @param name the name to bind; may not be empty
 * @exception NameNotFoundException if an intermediate context does not 
 * exist
 * @exception NamingException if a naming exception is encountered
 */
@Override
public void unbind(Name name) throws NamingException {
    
    if (!checkWritable()) {
        return;
    }

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).unbind(name.getSuffix(1));
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        bindings.remove(name.get(0));
    }
    
}
 
Example 6
Source File: WARDirContext.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Entry tree lookup.
 */
protected Entry treeLookup(Name name) {
    if (name.isEmpty() || entries == null)
        return entries;
    Entry currentEntry = entries;
    for (int i = 0; i < name.size(); i++) {
        if (name.get(i).length() == 0)
            continue;
        currentEntry = currentEntry.getChild(name.get(i));
        if (currentEntry == null)
            return null;
    }
    return currentEntry;
}
 
Example 7
Source File: Util.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Bind val to name in ctx, and make sure that all intermediate contexts exist
 * @param ctx the parent JNDI Context under which value will be bound
 * @param name the name relative to ctx where value will be bound
 * @param value the value to bind.
 * @throws NamingException for any error
 */
private static void bind(Context ctx, Name name, Object value) throws NamingException
{
   int size = name.size();
   String atom = name.get(size - 1);
   Context parentCtx = createSubcontext(ctx, name.getPrefix(size - 1));
   parentCtx.bind(atom, value);
}
 
Example 8
Source File: OpenEjbContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(final Name name, final Object obj) throws NamingException {
    if (name.size() == 1 && "inject".equals(name.get(0))) {
        Injector.inject(obj);
    } else {
        super.bind(name, obj);
    }
}
 
Example 9
Source File: ContextImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates subcontext with name, relative to this Context.
 * 
 * @param name subcontext name.
 * @return new subcontext named name relative to this context.
 * @throws NoPermissionException if this context has been destroyed.
 * @throws InvalidNameException if name is empty or is CompositeName that
 *           spans more than one naming system.
 * @throws NameAlreadyBoundException if name is already bound in this Context
 * @throws NotContextException if any intermediate name from name is not bound
 *           to instance of javax.naming.Context.
 *  
 */
public Context createSubcontext(Name name) throws NamingException {
  checkIsDestroyed();
  Name parsedName = getParsedName(name);
  if (parsedName.size() == 0 || parsedName.get(0).length() == 0) { throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString()); }
  String subContextName = parsedName.get(0);
  Object boundObject = ctxMaps.get(parsedName.get(0));
  if (parsedName.size() == 1) {
    // Check if name is already in use
    if (boundObject == null) {
      Context subContext = new ContextImpl(this, subContextName);
      ctxMaps.put(subContextName, subContext);
      return subContext;
    }
    else {
      throw new NameAlreadyBoundException(LocalizedStrings.ContextImpl_NAME_0_IS_ALREADY_BOUND.toLocalizedString(subContextName));
    }
  }
  else {
    if (boundObject instanceof Context) {
      // Let the subcontext create new subcontext
      // lets consider a scenerio a/b/c
      // case a/b exists : c will be created
      // case a exists : b/c will not be created
      // an exception will be thrown in that case.
      return ((Context) boundObject)
          .createSubcontext(parsedName.getSuffix(1));
    }
    else {
      throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
    }
  }
}
 
Example 10
Source File: LdapName.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name ends with a specified
 * LDAP name suffix.
 * A name <tt>n</tt> is a suffix if it is equal to
 * <tt>getSuffix(size()-n.size())</tt>--in other words this LDAP
 * name ends with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return true if <tt>n</tt> is a suffix of this name, false otherwise.
 * @see #getSuffix(int posn)
 */
public boolean endsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(len1 - len2, len1, n));
}
 
Example 11
Source File: LdapName.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name starts with a specified LDAP name
 * prefix.
 * A name <tt>n</tt> is a prefix if it is equal to
 * <tt>getPrefix(n.size())</tt>--in other words this LDAP
 * name starts with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return  true if <tt>n</tt> is a prefix of this LDAP name,
 * false otherwise.
 * @see #getPrefix(int posn)
 */
public boolean startsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(0, len2, n));
}
 
Example 12
Source File: LdapName.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name ends with a specified
 * LDAP name suffix.
 * A name <tt>n</tt> is a suffix if it is equal to
 * <tt>getSuffix(size()-n.size())</tt>--in other words this LDAP
 * name ends with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return true if <tt>n</tt> is a suffix of this name, false otherwise.
 * @see #getSuffix(int posn)
 */
public boolean endsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(len1 - len2, len1, n));
}
 
Example 13
Source File: LdapName.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name starts with a specified LDAP name
 * prefix.
 * A name <tt>n</tt> is a prefix if it is equal to
 * <tt>getPrefix(n.size())</tt>--in other words this LDAP
 * name starts with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return  true if <tt>n</tt> is a prefix of this LDAP name,
 * false otherwise.
 * @see #getPrefix(int posn)
 */
public boolean startsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(0, len2, n));
}
 
Example 14
Source File: LdapName.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Determines whether this LDAP name starts with a specified LDAP name
 * prefix.
 * A name <tt>n</tt> is a prefix if it is equal to
 * <tt>getPrefix(n.size())</tt>--in other words this LDAP
 * name starts with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return  true if <tt>n</tt> is a prefix of this LDAP name,
 * false otherwise.
 * @see #getPrefix(int posn)
 */
public boolean startsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(0, len2, n));
}
 
Example 15
Source File: LdapName.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name starts with a specified LDAP name
 * prefix.
 * A name <tt>n</tt> is a prefix if it is equal to
 * <tt>getPrefix(n.size())</tt>--in other words this LDAP
 * name starts with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return  true if <tt>n</tt> is a prefix of this LDAP name,
 * false otherwise.
 * @see #getPrefix(int posn)
 */
public boolean startsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(0, len2, n));
}
 
Example 16
Source File: LdapName.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name starts with a specified LDAP name
 * prefix.
 * A name <tt>n</tt> is a prefix if it is equal to
 * <tt>getPrefix(n.size())</tt>--in other words this LDAP
 * name starts with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return  true if <tt>n</tt> is a prefix of this LDAP name,
 * false otherwise.
 * @see #getPrefix(int posn)
 */
public boolean startsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(0, len2, n));
}
 
Example 17
Source File: LdapName.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name ends with a specified
 * LDAP name suffix.
 * A name <tt>n</tt> is a suffix if it is equal to
 * <tt>getSuffix(size()-n.size())</tt>--in other words this LDAP
 * name ends with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return true if <tt>n</tt> is a suffix of this name, false otherwise.
 * @see #getSuffix(int posn)
 */
public boolean endsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(len1 - len2, len1, n));
}
 
Example 18
Source File: LdapName.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name ends with a specified
 * LDAP name suffix.
 * A name <tt>n</tt> is a suffix if it is equal to
 * <tt>getSuffix(size()-n.size())</tt>--in other words this LDAP
 * name ends with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return true if <tt>n</tt> is a suffix of this name, false otherwise.
 * @see #getSuffix(int posn)
 */
public boolean endsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(len1 - len2, len1, n));
}
 
Example 19
Source File: LdapName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name starts with a specified LDAP name
 * prefix.
 * A name <tt>n</tt> is a prefix if it is equal to
 * <tt>getPrefix(n.size())</tt>--in other words this LDAP
 * name starts with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return  true if <tt>n</tt> is a prefix of this LDAP name,
 * false otherwise.
 * @see #getPrefix(int posn)
 */
public boolean startsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(0, len2, n));
}
 
Example 20
Source File: LdapName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether this LDAP name ends with a specified
 * LDAP name suffix.
 * A name <tt>n</tt> is a suffix if it is equal to
 * <tt>getSuffix(size()-n.size())</tt>--in other words this LDAP
 * name ends with 'n'. If n is null or not a RFC2253 formatted name
 * as described in the class description, false is returned.
 *
 * @param n The LDAP name to check.
 * @return true if <tt>n</tt> is a suffix of this name, false otherwise.
 * @see #getSuffix(int posn)
 */
public boolean endsWith(Name n) {
    if (n == null) {
        return false;
    }
    int len1 = rdns.size();
    int len2 = n.size();
    return (len1 >= len2 &&
            matches(len1 - len2, len1, n));
}