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

The following examples show how to use javax.naming.Name#get() . 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: LdapName.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 2
Source File: LocalContext.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public void bind(Name name, Object obj) throws NamingException {
	if (name.isEmpty()) {
		throw new InvalidNameException("Cannot bind empty name");
	}

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

	if (nm.size() == 1) {
		if (inter != null)
			throw new NameAlreadyBoundException("Use rebind to override");

		obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);

		iBindings.put(atom, obj);
	} else {
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		((Context) inter).bind(nm.getSuffix(1), obj);
	}
}
 
Example 3
Source File: ContextImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Destroys subcontext with name name. The subcontext must be empty otherwise
 * ContextNotEmptyException is thrown. Once a context is destroyed, the
 * instance should not be used.
 * 
 * @param name subcontext to destroy
 * @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 ContextNotEmptyException if Context name is not empty.
 * @throws NameNotFoundException if subcontext with name name can not be
 *           found.
 * @throws NotContextException if name is not bound to instance of
 *           ContextImpl.
 *  
 */
public void destroySubcontext(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(subContextName);
  if (boundObject == null) { throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT.toLocalizedString(subContextName)); }
  if (!(boundObject instanceof ContextImpl)) { throw new NotContextException(); }
  ContextImpl contextToDestroy = (ContextImpl) boundObject;
  if (parsedName.size() == 1) {
    // Check if the Context to be destroyed is empty. Can not destroy
    // non-empty Context.
    if (contextToDestroy.ctxMaps.size() == 0) {
      ctxMaps.remove(subContextName);
      contextToDestroy.destroyInternal();
    }
    else {
      throw new ContextNotEmptyException(LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString());
    }
  }
  else {
    // Let the subcontext destroy the context
    ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1));
  }
}
 
Example 4
Source File: LdapName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 5
Source File: LdapName.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 6
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 7
Source File: LdapName.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 8
Source File: LdapName.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 9
Source File: LocalContext.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public void unbind(Name name) throws NamingException {
	if (name.isEmpty())
		throw new InvalidNameException("Cannot unbind empty name");

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

	if (nm.size() == 1) {
		iBindings.remove(atom);
	} else {
		Object inter = iBindings.get(atom);
		
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		((Context) inter).unbind(nm.getSuffix(1));
	}
}
 
Example 10
Source File: LdapName.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 11
Source File: LdapName.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 12
Source File: LocalContext.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public void rebind(Name name, Object obj) throws NamingException {
	if (name.isEmpty())
		throw new InvalidNameException("Cannot bind empty name");

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

	if (nm.size() == 1) {
		obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);

		iBindings.put(atom, obj);
	} else {
		Object inter = iBindings.get(atom);
		
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		((Context) inter).rebind(nm.getSuffix(1), obj);
	}
}
 
Example 13
Source File: LocalContext.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public Context createSubcontext(Name name) throws NamingException {
	if (name.isEmpty())
		throw new InvalidNameException("Cannot bind empty name");

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

	if (nm.size() == 1) {
		if (inter != null)
			throw new NameAlreadyBoundException("Use rebind to override");

		Context child = createCtx(this, atom, iEnv);

		iBindings.put(atom, child);

		return child;
	} else {
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		return ((Context) inter).createSubcontext(nm.getSuffix(1));
	}
}
 
Example 14
Source File: LdapName.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean matches(int beg, int end, Name n) {
    if (n instanceof LdapName) {
        LdapName ln = (LdapName) n;
        return doesListMatch(beg, end, ln.rdns);
    } else {
        for (int i = beg; i < end; i++) {
            Rdn rdn;
            String rdnString = n.get(i - beg);
            try {
                rdn = (new Rfc2253Parser(rdnString)).parseRdn();
            } catch (InvalidNameException e) {
                return false;
            }
            if (!rdn.equals(rdns.get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 15
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 16
Source File: LocalContext.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void rename(Name oldname, Name newname) throws NamingException {
	if (oldname.isEmpty() || newname.isEmpty())
		throw new InvalidNameException("Cannot rename empty name");

	Name oldnm = getMyComponents(oldname);
	Name newnm = getMyComponents(newname);

	if (oldnm.size() != newnm.size())
		throw new OperationNotSupportedException("Do not support rename across different contexts");

	String oldatom = oldnm.get(0);
	String newatom = newnm.get(0);

	if (oldnm.size() == 1) {
		if (iBindings.get(newatom) != null)
			throw new NameAlreadyBoundException(newname.toString() + " is already bound");

		Object oldBinding = iBindings.remove(oldatom);
		if (oldBinding == null)
			throw new NameNotFoundException(oldname.toString() + " not bound");

		iBindings.put(newatom, oldBinding);
	} else {
		if (!oldatom.equals(newatom))
			throw new OperationNotSupportedException("Do not support rename across different contexts");

		Object inter = iBindings.get(oldatom);
		
		if (!(inter instanceof Context))
			throw new NotContextException(oldatom + " does not name a context");

		((Context) inter).rename(oldnm.getSuffix(1), newnm.getSuffix(1));
	}
}
 
Example 17
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 18
Source File: ContextImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Rebinds object obj to name name . If there is existing binding it will be
 * overwritten.
 * 
 * @param name name of the object to rebind.
 * @param obj object to add. Can be null.
 * @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 NotContextException if name has more than one atomic name and
 *           intermediate context is not found
 * @throws NamingException if any other naming error occurs
 *  
 */
public void rebind(Name name, Object obj) 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 nameToBind = parsedName.get(0);
  if (parsedName.size() == 1) {
    ctxMaps.put(nameToBind, obj);
  }
  else {
    Object boundObject = ctxMaps.get(nameToBind);
    if (boundObject instanceof Context) {
      /*
       * Let the subcontext bind the object.
       */
      ((Context) boundObject).bind(parsedName.getSuffix(1), obj);
    }
    else {
      if (boundObject == null) {
        // Create new subcontext and let it do the binding
        Context sub = createSubcontext(nameToBind);
        sub.bind(parsedName.getSuffix(1), obj);
      }
      else {
        throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
      }
    }
  }
}
 
Example 19
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 20
Source File: NamingContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Binds a name to an object. All intermediate contexts and the target
 * context (that named by all but terminal atomic component of the name)
 * must already exist.
 *
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param rebind if true, then perform a rebind (ie, overwrite)
 * @exception NameAlreadyBoundException if name is already bound
 * @exception javax.naming.directory.InvalidAttributesException if object
 * did not supply all mandatory attributes
 * @exception NamingException if a naming exception is encountered
 */
protected void bind(Name name, Object obj, boolean rebind)
    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 (name.size() > 1) {
        if (entry == null) {
            throw new NameNotFoundException(sm.getString(
                    "namingContext.nameNotBound", name, name.get(0)));
        }
        if (entry.type == NamingEntry.CONTEXT) {
            if (rebind) {
                ((Context) entry.value).rebind(name.getSuffix(1), obj);
            } else {
                ((Context) entry.value).bind(name.getSuffix(1), obj);
            }
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if ((!rebind) && (entry != null)) {
            throw new NameAlreadyBoundException
                (sm.getString("namingContext.alreadyBound", name.get(0)));
        } else {
            // Getting the type of the object and wrapping it within a new
            // NamingEntry
            Object toBind =
                NamingManager.getStateToBind(obj, name, this, env);
            if (toBind instanceof Context) {
                entry = new NamingEntry(name.get(0), toBind,
                                        NamingEntry.CONTEXT);
            } else if (toBind instanceof LinkRef) {
                entry = new NamingEntry(name.get(0), toBind,
                                        NamingEntry.LINK_REF);
            } else if (toBind instanceof Reference) {
                entry = new NamingEntry(name.get(0), toBind,
                                        NamingEntry.REFERENCE);
            } else if (toBind instanceof Referenceable) {
                toBind = ((Referenceable) toBind).getReference();
                entry = new NamingEntry(name.get(0), toBind,
                                        NamingEntry.REFERENCE);
            } else {
                entry = new NamingEntry(name.get(0), toBind,
                                        NamingEntry.ENTRY);
            }
            bindings.put(name.get(0), entry);
        }
    }

}