javax.naming.NotContextException Java Examples

The following examples show how to use javax.naming.NotContextException. 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: 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 #2
Source File: HTTPContext.java    From oodt with Apache License 2.0 6 votes vote down vote up
public NamingEnumeration listBindings(String name) throws NamingException {
	if (name.length() > 0) {
	  throw new NotContextException("Subcontexts not supported");
	}
	return new NamingEnumeration() {
		public void close() {}
		public boolean hasMore() {
			return false;
		}
		public Object next() {
			throw new NoSuchElementException();
		}
		public boolean hasMoreElements() {
			return hasMore();
		}
		public Object nextElement() {
			return next();
		}
	};
}
 
Example #3
Source File: HTTPContext.java    From oodt with Apache License 2.0 6 votes vote down vote up
public NamingEnumeration list(String name) throws NamingException {
	if (name.length() > 0) {
	  throw new NotContextException("Subcontexts not supported");
	}
			
	return new NamingEnumeration() {
		public void close() {}
		public boolean hasMore() {
			return false;
		}
		public Object next() {
			throw new NoSuchElementException();
		}
		public boolean hasMoreElements() {
			return hasMore();
		}
		public Object nextElement() {
			return next();
		}
	};
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: NamingContext.java    From Tomcat8-Source-Read with MIT License 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 #12
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 #13
Source File: NamingContext.java    From Tomcat7.0.67 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 #14
Source File: LocalContext.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration listBindings(Name name) throws NamingException {
	if (name.isEmpty())
		return new ListOfBindings(iBindings.keys());

	Object target = lookup(name);
	if (target instanceof Context)
		return ((Context) target).listBindings("");

	throw new NotContextException(name + " cannot be listed");
}
 
Example #15
Source File: DefaultInitialContext.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Destroy the sub context.
 *
 * @param name the name.
 * @throws NamingException when a naming error occurs.
 */
@Override
public void destroySubcontext(String name) throws NamingException {
    if (name.contains("/")) {
        String[] names = name.split("/");
        DefaultInitialContext contextMap = this;
        try {
            for (int i = 0; i < names.length - 1; i++) {
                contextMap = (DefaultInitialContext) contextMap.lookup(names[i]);
            }
            contextMap.destroySubcontext(names[names.length - 1]);
        } catch (NameNotFoundException nnfe) {
            throw nnfe;
        }
    } else if (bindings.containsKey(name)) {
        if (bindings.get(name) instanceof DefaultInitialContext) {
            DefaultInitialContext subContext = (DefaultInitialContext) bindings.get(name);
            if (subContext.bindings.isEmpty()) {
                bindings.remove(name);
            } else {
                throw new ContextNotEmptyException("Context not empty: " + name);
            }
        } else {
            throw new NotContextException("Not a context: " + name);
        }
    } else {
        throw new NameNotFoundException("Unable to find name: " + name);
    }
}
 
Example #16
Source File: ReadOnlyContext.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration listBindings(String name) throws NamingException {
    Object o = lookup(name);
    if (o == this) {
        return new ListBindingEnumeration();
    } else if (o instanceof Context) {
        return ((Context) o).listBindings("");
    } else {
        throw new NotContextException();
    }
}
 
Example #17
Source File: ReadOnlyContext.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration list(String name) throws NamingException {
    Object o = lookup(name);
    if (o == this) {
        return new ListEnumeration();
    } else if (o instanceof Context) {
        return ((Context) o).list("");
    } else {
        throw new NotContextException();
    }
}
 
Example #18
Source File: right_LmiInitialContext_1.6.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public NamingEnumeration listBindings(String name) throws NamingException {
    if (TraceCarol.isDebugJndiCarol()) {
        TraceCarol.debugJndiCarol("LmiInitialContext.listBindings(\"" + name + "\")/rmi name=\"");
    }
    if (name.equals("")) {
        return new LmiBindings(bindings.keys());
    }
    Object target = lookup(name);
    if (target instanceof Context) {
        return ((Context) target).listBindings("");
    }
    throw new NotContextException(name + " cannot be listed");
}
 
Example #19
Source File: right_LmiInitialContext_1.6.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public NamingEnumeration list(String name) throws NamingException {
    if (TraceCarol.isDebugJndiCarol()) {
        TraceCarol.debugJndiCarol("LmiInitialContext.list(\"" + name + "\")");
    }
    if (name.equals("")) {
        return new LmiNames(bindings.keys());
    }

    Object target = lookup(name);
    if (target instanceof Context) {
        return ((Context) target).list("");
    }
    throw new NotContextException(name + " cannot be listed");
}
 
Example #20
Source File: left_LmiInitialContext_1.5.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public NamingEnumeration listBindings(String name) throws NamingException {
    if (TraceCarol.isDebugJndiCarol()) {
        TraceCarol.debugJndiCarol("LmiInitialContext.listBindings(\"" + name + "\")/rmi name=\"");
    }
    if (name.equals("")) {
        return new LmiBindings(bindings.keys());
    }
    Object target = lookup(name);
    if (target instanceof Context) {
        return ((Context) target).listBindings("");
    }
    throw new NotContextException(name + " cannot be listed");
}
 
Example #21
Source File: left_LmiInitialContext_1.5.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public NamingEnumeration list(String name) throws NamingException {
    if (TraceCarol.isDebugJndiCarol()) {
        TraceCarol.debugJndiCarol("LmiInitialContext.list(\"" + name + "\")");
    }
    if (name.equals("")) {
        return new LmiNames(bindings.keys());
    }

    Object target = lookup(name);
    if (target instanceof Context) {
        return ((Context) target).list("");
    }
    throw new NotContextException(name + " cannot be listed");
}
 
Example #22
Source File: ReadOnlyContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
   Object o = lookup(name);
   if (o == this) {
      return new ListBindingEnumeration();
   } else if (o instanceof Context) {
      return ((Context) o).listBindings("");
   } else {
      throw new NotContextException();
   }
}
 
Example #23
Source File: ReadOnlyContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
   Object o = lookup(name);
   if (o == this) {
      return new ListEnumeration();
   } else if (o instanceof Context) {
      return ((Context) o).list("");
   } else {
      throw new NotContextException();
   }
}
 
Example #24
Source File: TestContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
   Object o = lookup(name);
   if (o == this) {
      return new ListBindingEnumeration();
   } else if (o instanceof Context) {
      return ((Context) o).listBindings("");
   } else {
      throw new NotContextException();
   }
}
 
Example #25
Source File: TestContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
   Object o = lookup(name);
   if (o == this) {
      return new ListEnumeration();
   } else if (o instanceof Context) {
      return ((Context) o).list("");
   } else {
      throw new NotContextException();
   }
}
 
Example #26
Source File: DefaultInitialContextTest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test destroySubcontext method.
 *
 * @throws Exception when an error occurs.
 */
@Test
public void testDestroySubcontext3() throws Exception {
    DefaultInitialContext context = new DefaultInitialContext();
    context.bind("name", 12);
    assertThrows(NotContextException.class, () -> context.destroySubcontext("name"));
}
 
Example #27
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 #28
Source File: LocalContext.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration list(Name name) throws NamingException {
	if (name.isEmpty())
		return new ListOfNames(iBindings.keys());

	Object target = lookup(name);
	if (target instanceof Context)
		return ((Context) target).list("");


	throw new NotContextException(name + " cannot be listed");
}
 
Example #29
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 #30
Source File: NamingContext.java    From Tomcat7.0.67 with Apache License 2.0 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"));
        }
    }
    
}