Example usage for javax.naming Name clone

List of usage examples for javax.naming Name clone

Introduction

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

Prototype

public Object clone();

Source Link

Document

Generates a new copy of this name.

Usage

From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java

@Override
public void deleteActor(Organization organization) {
    Name dn = buildDn(organization);

    try {//w ww.  j  a  v a 2s.co  m
        for (ProductType o : getProductTypes(organization)) {
            removeProduct(organization, o);
        }

        DistinguishedName productTypesDn = (DistinguishedName) dn.clone();
        productTypesDn.add("ou", ShsLdapAttributes.OU_PRODUCT_TYPES);

        ldapTemplate.unbind(productTypesDn);
    } catch (Exception e) {
        log.warn("Error removing product types for organization: " + organization);
    }

    try {

        for (Agreement o : getAgreements(organization)) {
            removeAgreement(organization, o);
        }

        DistinguishedName agreementsDn = (DistinguishedName) dn.clone();
        agreementsDn.add("ou", ShsLdapAttributes.OU_AGREEMENTS);
        ldapTemplate.unbind(agreementsDn);

    } catch (Exception e) {
        log.warn("Error removing product types for organization: " + organization);
    }

    try {
        for (Address o : getAddresses(organization)) {
            removeAddress(organization, o);
        }

        DistinguishedName addressesDn = (DistinguishedName) dn.clone();
        addressesDn.add("ou", ShsLdapAttributes.OU_ADRESSES);

        ldapTemplate.unbind(addressesDn);

    } catch (Exception e) {
        log.warn("Error removing addresses for organization: " + organization);
    }

    try {
        ldapTemplate.unbind(dn);
        log.debug("organization {} deleted from directory", dn.toString());
    } catch (Exception e) {
        log.warn("Error removing organization: " + organization);
    }
}

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 ww  w . j  a  v  a2s.com*/

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

From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java

@Override
public void saveActor(Organization organization) {
    Name dn = buildDn(organization);
    boolean isNew = false;
    DirContextAdapter context = null;//from  w w w.j  a  v a  2 s  .c  o m
    try {
        context = (DirContextAdapter) ldapTemplate.lookupContext(dn);
    } catch (NameNotFoundException e) {
        isNew = true;
        context = new DirContextAdapter(dn);
    }

    OrganizationMapper.mapToContext(organization, context);

    if (isNew) {
        ldapTemplate.bind(context);
        DistinguishedName dn2 = (DistinguishedName) dn.clone();
        dn2.add("ou", ShsLdapAttributes.OU_PRODUCT_TYPES);
        context = new DirContextAdapter(dn2);
        context.setAttributeValues("objectClass", new String[] { "top", "organizationalUnit" });
        ldapTemplate.bind(context);

        dn2 = (DistinguishedName) dn.clone();
        dn2.add("ou", ShsLdapAttributes.OU_AGREEMENTS);
        context = new DirContextAdapter(dn2);
        context.setAttributeValues("objectClass", new String[] { "top", "organizationalUnit" });
        ldapTemplate.bind(context);

        dn2 = (DistinguishedName) dn.clone();
        dn2.add("ou", ShsLdapAttributes.OU_ADRESSES);
        context = new DirContextAdapter(dn2);
        context.setAttributeValues("objectClass", new String[] { "top", "organizationalUnit" });
        ldapTemplate.bind(context);

        log.debug("organization {} created in directory", dn.toString());
    } else {
        ldapTemplate.modifyAttributes(context);
        log.debug("organization {} updated in directory", dn.toString());
    }
}

From source file:naming.resources.ProxyDirContext.java

/**
 * Composes the name of this context with a name relative to this context.
 * <p>//ww  w. j  a  va  2s .  c  o m
 * Given a name (name) relative to this context, and the name (prefix) 
 * of this context relative to one of its ancestors, this method returns 
 * the composition of the two names using the syntax appropriate for the 
 * naming system(s) involved. That is, if name names an object relative 
 * to this context, the result is the name of the same object, but 
 * relative to the ancestor context. None of the names may be null.
 * 
 * @param name a name relative to this context
 * @param prefix the name of this context relative to one of its ancestors
 * @return the composition of prefix and name
 * @exception NamingException if a naming exception is encountered
 */
public Name composeName(Name name, Name prefix) throws NamingException {
    prefix = (Name) name.clone();
    return prefix.addAll(name);
}