use of javax.naming.InvalidNameException in project geode by apache.
the class ContextImpl method rebind.
/**
* 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));
}
}
}
}
use of javax.naming.InvalidNameException in project geode by apache.
the class ContextImpl method createSubcontext.
/**
* 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) {
// 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));
}
}
}
use of javax.naming.InvalidNameException in project wildfly by wildfly.
the class InMemoryNamingStoreTestCase method testRebindEmptyName.
@Test
public void testRebindEmptyName() throws Exception {
try {
nameStore.rebind(new CompositeName(), new Object(), Object.class);
fail("Should have thrown and InvalidNameException");
} catch (InvalidNameException expected) {
}
try {
nameStore.rebind(new CompositeName(""), new Object(), Object.class);
fail("Should have thrown and InvalidNameException");
} catch (InvalidNameException expected) {
}
}
use of javax.naming.InvalidNameException in project wildfly by wildfly.
the class ServiceBasedNamingStore method convert.
private Name convert(ServiceName serviceName) {
String[] c = serviceName.toArray();
CompositeName name = new CompositeName();
int baseIndex = serviceNameBase.toArray().length;
for (int i = baseIndex; i < c.length; i++) {
try {
name.add(c[i]);
} catch (InvalidNameException e) {
throw new IllegalStateException(e);
}
}
return name;
}
use of javax.naming.InvalidNameException in project Towny by ElgarL.
the class NationCommand method newNation.
/**
* Create a new nation. Command: /nation new [nation] *[capital]
*
* @param player
*/
public void newNation(Player player, String name, String capitalName) {
TownyUniverse universe = plugin.getTownyUniverse();
try {
Town town = TownyUniverse.getDataSource().getTown(capitalName);
if (town.hasNation())
throw new TownyException(TownySettings.getLangString("msg_err_already_nation"));
// Check the name is valid and doesn't already exist.
String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(name);
} catch (InvalidNameException e) {
filteredName = null;
}
if ((filteredName == null) || TownyUniverse.getDataSource().hasNation(filteredName))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
if (TownySettings.isUsingEconomy() && !town.pay(TownySettings.getNewNationPrice(), "New Nation Cost"))
throw new TownyException(TownySettings.getLangString("msg_no_funds_new_nation"));
newNation(universe, name, town);
/*
* universe.newNation(name); Nation nation =
* universe.getNation(name); nation.addTown(town);
* nation.setCapital(town);
*
* universe.getDataSource().saveTown(town);
* universe.getDataSource().saveNation(nation);
* universe.getDataSource().saveNationList();
*/
TownyMessaging.sendGlobalMessage(TownySettings.getNewNationMsg(player.getName(), name));
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
// TODO: delete town data that might have been done
} catch (EconomyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
Aggregations