Example usage for javax.naming InvalidNameException InvalidNameException

List of usage examples for javax.naming InvalidNameException InvalidNameException

Introduction

In this page you can find the example usage for javax.naming InvalidNameException InvalidNameException.

Prototype

public InvalidNameException(String explanation) 

Source Link

Document

Constructs an instance of InvalidNameException using an explanation of the problem.

Usage

From source file:Main.java

/**
 * Decodes values of attributes in the DN encoded in hex into a UTF-8 
 * String.  RFC2253 allows a DN's attribute to be encoded in hex.
 * The encoded value starts with a # then is followed by an even 
 * number of hex characters.  //from ww w.java  2 s. co  m
 */
public static final String decodeHexString(String str) throws InvalidNameException {
    if (str == null || str.length() == 0) {
        throw new InvalidNameException("Expected string to start with a '#' character.  "
                + "Invalid hex encoded string for empty or null string.");
    }

    char[] chars = str.toCharArray();
    if (chars[0] != '#') {
        throw new InvalidNameException(
                "Expected string to start with a '#' character.  " + "Invalid hex encoded string: " + str);
    }

    // the bytes representing the encoded string of hex
    // this should be ( length - 1 )/2 in size
    byte[] decoded = new byte[(chars.length - 1) >> 1];

    for (int ii = 1, jj = 0; ii < chars.length; ii += 2, jj++) {
        int ch = (HEX_VALUE[chars[ii]] << 4) + HEX_VALUE[chars[ii + 1]];
        decoded[jj] = (byte) ch;
    }

    return utf8ToString(decoded);
}

From source file:com.dattack.naming.AbstractContext.java

@Override
public void bind(final Name name, final Object object) throws NamingException {

    ensureContextNotClosed();//from   w  w w . ja  v a2  s  .c om

    if (object == null) {
        return;
    }

    if (name.isEmpty()) {
        throw new InvalidNameException("Cannot bind to an empty name");
    }

    final Name prefix = name.getPrefix(1);
    if (subContexts.containsKey(prefix)) {
        subContexts.get(prefix).bind(name.getSuffix(1), object);
        return;
    }

    if (objectTable.containsKey(name) || subContexts.containsKey(name) || env.containsKey(name.toString())) {
        throw new NameAlreadyBoundException(
                String.format("Name %s already bound. Use rebind() to override", name.toString()));
    }

    if (object instanceof Context) {
        subContexts.put(name, (Context) object);
    } else {
        objectTable.put(name, object);
    }
}

From source file:com.dattack.naming.AbstractContext.java

@Override
public Name composeName(final Name name, final Name prefix) throws NamingException {

    if (name == null || prefix == null) {
        throw new InvalidNameException(
                String.format("Unable to compose name with null values (prefix: %s, name: %s)", prefix, name));
    }/*from   w w  w.  j  a  v  a 2s.co  m*/

    final Name composeName = (Name) prefix.clone();
    composeName.addAll(name);
    return composeName;
}

From source file:de.xirp.io.comm.lowlevel.AbstractStreamCommunicationInterface.java

/**
 * Sends data periodically./* ww  w  .  j  a  va 2 s  .c o m*/
 * 
 * @param name
 *            the name to use for the send timer
 * @param time
 *            the time interval in milliseconds between two sends
 * @param data
 *            the data to send
 * @throws InvalidNameException
 *             if the name is already in use
 */
public void sendPeriodically(String name, int time, byte[] data) throws InvalidNameException {

    if (periodicSenders.get(name) != null) {
        throw new InvalidNameException(
                I18n.getString("AbstractCommunication.log.alreadyExcecutingThread") + name); //$NON-NLS-1$
    }

    Timer timer = new Timer(name);
    timer.schedule(getSendPeriodicTask(data), 0, time);
    periodicSenders.put(name, timer);
}

From source file:com.dattack.naming.AbstractContext.java

@Override
public void rebind(final Name name, final Object object) throws NamingException {

    ensureContextNotClosed();/*from w w  w .ja va2  s  .  c o m*/

    if (name.isEmpty()) {
        throw new InvalidNameException("Cannot rebind to empty name");
    }

    // the parent context must exists
    getParentContext(name);
    // final Object targetContext = lookup(name.getPrefix(name.size() - 1));
    // if (targetContext == null || !(targetContext instanceof Context)) {
    // throw new NamingException(
    // String.format("Cannot bind object due context does not exist (%s)", name.toString()));
    // }
    unbind(name);
    bind(name, object);
}

From source file:com.dattack.naming.AbstractContext.java

@Override
public void rename(final Name oldName, final Name newName) throws NamingException {

    ensureContextNotClosed();//from w w  w.j  a  v a 2 s.c o m

    if (newName.isEmpty()) {
        throw new InvalidNameException("Cannot bind to empty name");
    }

    final Object oldValue = lookup(oldName);
    if (oldValue == null) {
        throw new NamingException(String.format("Cannot rename object: name not found (%s)", oldName));
    }

    if (lookup(newName) != null) {
        throw new NameAlreadyBoundException(
                String.format("Cannot rename object: name already bound (%s)", newName));
    }

    unbind(oldName);
    unbind(newName);
    bind(newName, oldValue);
}

From source file:com.dattack.naming.AbstractContext.java

@Override
public void unbind(final Name name) throws NamingException {

    ensureContextNotClosed();//www.  j  av  a  2 s  .c o m

    if (name.isEmpty()) {
        throw new InvalidNameException("Cannot unbind to empty name");
    }

    if (name.size() == 1) {
        if (objectTable.containsKey(name)) {
            objectTable.remove(name);
        }
        return;
    }

    final Context parentContext = getParentContext(name);

    parentContext.unbind(name.getSuffix(name.size() - 1));
}

From source file:org.apache.ambari.server.serveraction.kerberos.ADKerberosOperationHandler.java

/**
 * Iterates through the characters of the given distinguished name to escape special characters
 *
 * @param dn the distinguished name to process
 * @return the distinguished name with escaped characters
 * @see #escapeCharacters(String, java.util.Set, Character)
 *//*w w  w.  j av a 2  s  .c o m*/
protected String escapeDNCharacters(String dn) throws InvalidNameException {
    if ((dn == null) || dn.isEmpty()) {
        return dn;
    } else {
        LdapName name = new LdapName(dn);
        List<Rdn> rdns = name.getRdns();

        if ((rdns == null) || rdns.isEmpty()) {
            throw new InvalidNameException(String.format("One or more RDNs are expected for a DN of %s", dn));
        }

        StringBuilder builder = new StringBuilder();
        for (Rdn rdn : rdns) {
            builder.insert(0, String.format(",%s=%s", rdn.getType(),
                    escapeCharacters((String) rdn.getValue(), SPECIAL_DN_CHARACTERS, DN_ESCAPE_CHARACTER)));
        }

        return builder.substring(1);
    }
}

From source file:org.openflexo.foundation.wkf.FlexoProcess.java

@Override
public void setName(String newName) throws DuplicateResourceException, InvalidNameException {
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("FlexoProcess.setName() with " + newName + " was: " + _name);
    }// w ww . jav a 2  s  .c  om
    if (!newName.equals(_name) || _name == null) {
        if (processWithSimilarNameExists(getWorkflow(), this, ToolBox.getJavaName(newName))) {
            throw new InvalidNameException("A process with similar name exists");
        }
        if (getProject() != null && getFlexoResource() != null && !isDeserializing()) {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("renameResource() with " + newName);
            }
            try {
                getProject().renameResource(getFlexoResource(), newName);
            } catch (DuplicateResourceException e) {
                if (!isImported()) {
                    setChanged(false);
                    notifyObserversAsReentrantModification(new NameChanged(_name, _name));
                    throw e;
                } else if (logger.isLoggable(Level.WARNING)) {
                    logger.warning("Duplicate resource thrown on imported process: " + newName);
                }
            }
            if (getProcessNode() != null) {
                getProcessNode().setChanged();// Workflow needs to be saved
                // again
            }
        }
        if (!isDeserializing() && getProcessDMEntity() != null) {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("rename process entity with " + getProcessInstanceEntityName(newName));
            }
            getProcessDMEntity().setName(getProcessInstanceEntityName(newName));
        }
        String oldName = _name;
        _name = newName;
        /*
         * if (getProcessNode() != null) { if
         * (logger.isLoggable(Level.FINE))
         * logger.fine("rename process node with " + newName);
         * getProcessNode().setName(newName); }
         */
        setChanged();
        notifyObservers(new NameChanged(oldName, newName));
    } else {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("setName() ignored");
        }
    }
}

From source file:org.springframework.ldap.core.DistinguishedName.java

public Name addAll(int arg0, Name name) throws InvalidNameException {
    DistinguishedName distinguishedName = null;
    try {//from  w w w  . j  a va2 s .  c  o m
        distinguishedName = (DistinguishedName) name;
    } catch (ClassCastException e) {
        throw new InvalidNameException("Invalid name type");
    }

    names.addAll(arg0, distinguishedName.getNames());
    return this;
}