Example usage for javax.naming Name toString

List of usage examples for javax.naming Name toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Unbinds the named object. Removes the terminal atomic name in name 
 * from the target context--that named by all but the terminal atomic 
 * part of name.// w w  w.  j a v  a2 s .c o  m
 * <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. 
 * 
 * @param name the name to bind; may not be empty
 * @exception NameNotFoundException if an intermediate context does not 
 * exist
 * @exception NamingException if a naming exception is encountered
 */
public void unbind(Name nameObj) throws NamingException {
    if ("fs:".equals(nameObj.get(0).toString()))
        nameObj = nameObj.getSuffix(1);
    String name = nameObj.toString();
    if (log.isDebugEnabled())
        log.debug("unbind " + name);
    File file = file(name);

    if (file == null)
        throw new NamingException(sm.getString("resources.notFound", name));

    if (!file.delete())
        throw new NamingException(sm.getString("resources.unbindFailed", name));

}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Binds a new name to the object bound to an old name, and unbinds the 
 * old name. Both names are relative to this context. Any attributes 
 * associated with the old name become associated with the new name. 
 * Intermediate contexts of the old name are not changed.
 * /*from  w  w w . j a  v  a 2 s. co  m*/
 * @param oldName the name of the existing binding; may not be empty
 * @param newName the name of the new binding; may not be empty
 * @exception NameAlreadyBoundException if newName is already bound
 * @exception NamingException if a naming exception is encountered
 */
public void rename(Name oldNameO, Name newNameO) throws NamingException {
    String oldName = oldNameO.toString();
    String newName = newNameO.toString();
    File file = file(oldName);

    if (file == null)
        throw new NamingException(sm.getString("resources.notFound", oldName));

    File newFile = new File(base, newName);

    file.renameTo(newFile);
}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Enumerates the names bound in the named context, along with the class 
 * names of objects bound to them. The contents of any subcontexts are 
 * not included.//from  w  w  w .j a va 2s.c o  m
 * <p>
 * If a binding is added to or removed from this context, its effect on 
 * an enumeration previously returned is undefined.
 * 
 * @param name the name of the context to list
 * @return an enumeration of the names and class names of the bindings in 
 * this context. Each element of the enumeration is of type NameClassPair.
 * @exception NamingException if a naming exception is encountered
 */
public NamingEnumeration list(Name nameN) throws NamingException {
    String name = nameN.toString();
    if (log.isDebugEnabled())
        log.debug("list " + name);
    File file = file(name);

    if (file == null)
        throw new NamingException(sm.getString("resources.notFound", name));

    Vector entries = list(file);

    return new NamingContextEnumeration(entries.elements(), this, false);

}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Enumerates the names bound in the named context, along with the 
 * objects bound to them. The contents of any subcontexts are not 
 * included./*ww  w . jav a 2 s .  c o  m*/
 * <p>
 * If a binding is added to or removed from this context, its effect on 
 * an enumeration previously returned is undefined.
 * 
 * @param name the name of the context to list
 * @return an enumeration of the bindings in this context. 
 * Each element of the enumeration is of type Binding.
 * @exception NamingException if a naming exception is encountered
 */
public NamingEnumeration listBindings(Name nameN) throws NamingException {
    String name = nameN.toString();
    if (log.isDebugEnabled())
        log.debug("listBindings " + name);

    File file = file(name);

    if (file == null)
        throw new NamingException(sm.getString("resources.notFound", name));

    Vector entries = list(file);

    return new NamingContextEnumeration(entries.elements(), this, true);

}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Retrieves selected attributes associated with a named object. 
 * See the class description regarding attribute models, attribute type 
 * names, and operational attributes./*from  ww w .ja va 2  s .  c  om*/
 * 
 * @return the requested attributes; never null
 * @param name the name of the object from which to retrieve attributes
 * @param attrIds the identifiers of the attributes to retrieve. null 
 * indicates that all attributes should be retrieved; an empty array 
 * indicates that none should be retrieved
 * @exception NamingException if a naming exception is encountered
 */
public Attributes getAttributes(Name nameN, String[] attrIds) throws NamingException {
    String name = nameN.toString();
    if (log.isDebugEnabled())
        log.debug("getAttributes " + name);

    // Building attribute list
    File file = file(name);

    if (file == null)
        throw new NamingException(sm.getString("resources.notFound", name));

    return new FileAttributes(file);

}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Binds a name to an object, along with associated attributes. If attrs 
 * is null, the resulting binding will have the attributes associated 
 * with obj if obj is a DirContext, and no attributes otherwise. If attrs 
 * is non-null, the resulting binding will have attrs as its attributes; 
 * any attributes associated with obj are ignored.
 * //  w ww.j av  a 2s.  co m
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param attrs the attributes to associate with the binding
 * @exception NameAlreadyBoundException if name is already bound
 * @exception InvalidAttributesException if some "mandatory" attributes 
 * of the binding are not supplied
 * @exception NamingException if a naming exception is encountered
 */
public void bind(Name nameN, Object obj, Attributes attrs) throws NamingException {

    String name = nameN.toString();
    // Note: No custom attributes allowed

    File file = new File(base, name);
    if (file.exists())
        throw new NameAlreadyBoundException(sm.getString("resources.alreadyBound", name));

    rebind(name, obj, attrs);
}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Binds a name to an object, along with associated attributes, 
 * overwriting any existing binding. If attrs is null and obj is a 
 * DirContext, the attributes from obj are used. If attrs is null and obj 
 * is not a DirContext, any existing attributes associated with the object
 * already bound in the directory remain unchanged. If attrs is non-null, 
 * any existing attributes associated with the object already bound in 
 * the directory are removed and attrs is associated with the named 
 * object. If obj is a DirContext and attrs is non-null, the attributes 
 * of obj are ignored./* www  . j a v a  2 s  .  c om*/
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param attrs the attributes to associate with the binding
 * @exception InvalidAttributesException if some "mandatory" attributes 
 * of the binding are not supplied
 * @exception NamingException if a naming exception is encountered
 */
public void rebind(Name nameN, Object obj, Attributes attrs) throws NamingException {
    String name = nameN.toString();

    // Note: No custom attributes allowed
    // Check obj type

    File file = new File(base, name);

    InputStream is = null;
    //         if (obj instanceof Resource) {
    //             try {
    //                 is = ((Resource) obj).streamContent();
    //             } catch (IOException e) {
    //             }
    //         } else

    // TODO support File, byte[], String
    if (obj instanceof InputStream) {
        is = (InputStream) obj;
    } else if (obj instanceof DirContext) {
        if (file.exists()) {
            if (!file.delete())
                throw new NamingException(sm.getString("resources.bindFailed", name));
        }
        if (!file.mkdir())
            throw new NamingException(sm.getString("resources.bindFailed", name));
    }
    if (is == null)
        throw new NamingException(sm.getString("resources.bindFailed", name));

    // Open os

    try {
        FileOutputStream os = null;
        byte buffer[] = new byte[BUFFER_SIZE];
        int len = -1;
        try {
            os = new FileOutputStream(file);
            while (true) {
                len = is.read(buffer);
                if (len == -1)
                    break;
                os.write(buffer, 0, len);
            }
        } finally {
            if (os != null)
                os.close();
            is.close();
        }
    } catch (IOException e) {
        throw new NamingException(sm.getString("resources.bindFailed", e));
    }
}

From source file:org.apache.naming.modules.fs.FileDirContext.java

/**
 * Creates and binds a new context, along with associated attributes. 
 * This method creates a new subcontext with the given name, binds it in 
 * the target context (that named by all but terminal atomic component of 
 * the name), and associates the supplied attributes with the newly 
 * created object. All intermediate and target contexts must already 
 * exist. If attrs is null, this method is equivalent to 
 * Context.createSubcontext().//from   w ww . j  a va2  s .  co  m
 * 
 * @param name the name of the context to create; may not be empty
 * @param attrs the attributes to associate with the newly created context
 * @return the newly created context
 * @exception NameAlreadyBoundException if the name is already bound
 * @exception InvalidAttributesException if attrs does not contain all 
 * the mandatory attributes required for creation
 * @exception NamingException if a naming exception is encountered
 */
public DirContext createSubcontext(Name nameN, Attributes attrs) throws NamingException {
    String name = nameN.toString();
    File file = new File(base, name);
    if (file.exists())
        throw new NameAlreadyBoundException(sm.getString("resources.alreadyBound", name));
    if (!file.mkdir())
        throw new NamingException(sm.getString("resources.bindFailed", name));
    return (DirContext) lookup(name);
}

From source file:org.ligoj.app.plugin.id.ldap.dao.UserLdapRepository.java

@Override
public UserOrg create(final UserOrg user) {
    // Build the DN
    final Name dn = buildDn(user);

    // Create the LDAP entry
    user.setDn(dn.toString());
    final DirContextAdapter context = new DirContextAdapter(dn);
    context.setAttributeValues(OBJECT_CLASS, new String[] { peopleClass });
    mapToContext(user, context);/*from  w  w w  . j  av  a2s.c  o  m*/
    template.bind(context);

    // Also, update the cache and return the original entry with updated DN
    return cacheRepository.create(user);
}

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

/**
 * @see javax.naming.directory.DirContext#getAttributes(Name)
 *//* w  w w.j a  va  2 s  .  c  o m*/
public Attributes getAttributes(Name name) throws NamingException {
    return getAttributes(name.toString());
}