Search in sources :

Example 11 with InvalidNameException

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));
            }
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 12 with InvalidNameException

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));
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 13 with InvalidNameException

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) {
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 14 with InvalidNameException

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;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName)

Example 15 with InvalidNameException

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());
    }
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) InvalidNameException(javax.naming.InvalidNameException) Town(com.palmergames.bukkit.towny.object.Town) TownyUniverse(com.palmergames.bukkit.towny.object.TownyUniverse) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)27 CompositeName (javax.naming.CompositeName)10 LdapName (javax.naming.ldap.LdapName)8 Name (javax.naming.Name)6 NameNotFoundException (javax.naming.NameNotFoundException)5 Rdn (javax.naming.ldap.Rdn)5 ArrayList (java.util.ArrayList)4 NotContextException (javax.naming.NotContextException)4 URISyntaxException (java.net.URISyntaxException)3 Context (javax.naming.Context)3 NamingException (javax.naming.NamingException)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 LinkedList (java.util.LinkedList)2 AuthenticationException (javax.naming.AuthenticationException)2 ConfigurationException (javax.naming.ConfigurationException)2 ContextNotEmptyException (javax.naming.ContextNotEmptyException)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)2