当前位置: 首页>>代码示例>>Java>>正文


Java ModificationItem.getAttribute方法代码示例

本文整理汇总了Java中javax.naming.directory.ModificationItem.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ModificationItem.getAttribute方法的具体用法?Java ModificationItem.getAttribute怎么用?Java ModificationItem.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.directory.ModificationItem的用法示例。


在下文中一共展示了ModificationItem.getAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
/**
 * @param ctx
 * @param ouBase If organizational units are given by the given obj then this parameter will be ignored, otherwise this is the ou where
 *          the new object will be inserted.
 * @param obj
 * @param args
 * @throws NamingException
 */
public void create(final DirContext ctx, final String ouBase, final T obj, final Object... args) throws NamingException
{
  final String dn = buildDn(ouBase, obj);
  log.info("Create " + getObjectClass() + ": " + dn + ": " + getLogInfo(obj));
  final Attributes attrs = new BasicAttributes();
  final List<ModificationItem> modificationItems = getModificationItems(new ArrayList<ModificationItem>(), obj);
  modificationItems.add(createModificationItem(DirContext.ADD_ATTRIBUTE, "objectClass", getObjectClass()));
  final String[] additionalObjectClasses = getAdditionalObjectClasses(obj);
  if (additionalObjectClasses != null) {
    for (final String objectClass : additionalObjectClasses) {
      modificationItems.add(createModificationItem(DirContext.ADD_ATTRIBUTE, "objectClass", objectClass));
    }
  }
  for (final ModificationItem modItem : modificationItems) {
    final Attribute attr = modItem.getAttribute();
    LdapUtils.putAttribute(attrs, attr.getID(), (String) attr.get());
  }
  LdapUtils.putAttribute(attrs, "cn", LdapUtils.escapeCommonName(obj.getCommonName()));
  onBeforeBind(dn, attrs, args);
  ctx.bind(dn, null, attrs);
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:30,代码来源:LdapDao.java

示例2: testGetCompensatingModificationItem_RemoveFullExistingAttribute

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testGetCompensatingModificationItem_RemoveFullExistingAttribute()
        throws NamingException {
    BasicAttribute attribute = new BasicAttribute("someattr");
    attribute.add("value1");
    attribute.add("value2");
    Attributes attributes = new BasicAttributes();
    attributes.put(attribute);

    ModificationItem originalItem = new ModificationItem(
            DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("someattr"));

    // Perform test
    ModificationItem result = tested.getCompensatingModificationItem(
            attributes, originalItem);

    // Verify result
    assertThat(result.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE);
    Attribute resultAttribute = result.getAttribute();
    assertThat(resultAttribute.getID()).isEqualTo("someattr");
    Object object = resultAttribute.get(0);
    assertThat(object).isEqualTo("value1");
    assertThat(resultAttribute.get(1)).isEqualTo("value2");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:25,代码来源:ModifyAttributesOperationRecorderTest.java

示例3: testGetCompensatingModificationItem_ReplaceNonExistingAttribute

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testGetCompensatingModificationItem_ReplaceNonExistingAttribute()
        throws NamingException {
    Attributes attributes = new BasicAttributes();

    BasicAttribute modificationAttribute = new BasicAttribute("someattr");
    modificationAttribute.add("newvalue1");
    modificationAttribute.add("newvalue2");
    ModificationItem originalItem = new ModificationItem(
            DirContext.REPLACE_ATTRIBUTE, modificationAttribute);

    // Perform test
    ModificationItem result = tested.getCompensatingModificationItem(
            attributes, originalItem);

    // Verify result
    assertThat(result.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE);
    Attribute resultAttribute = result.getAttribute();
    assertThat(resultAttribute.getID()).isEqualTo("someattr");
    assertThat(resultAttribute.size()).isEqualTo(0);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:22,代码来源:ModifyAttributesOperationRecorderTest.java

示例4: testGetCompensatingModificationItem_AddNonExistingAttribute

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testGetCompensatingModificationItem_AddNonExistingAttribute()
        throws NamingException {
    Attributes attributes = new BasicAttributes();

    BasicAttribute modificationAttribute = new BasicAttribute("someattr");
    modificationAttribute.add("newvalue1");
    modificationAttribute.add("newvalue2");
    ModificationItem originalItem = new ModificationItem(
            DirContext.ADD_ATTRIBUTE, modificationAttribute);

    // Perform test
    ModificationItem result = tested.getCompensatingModificationItem(
            attributes, originalItem);

    // Verify result
    assertThat(result.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE);
    Attribute resultAttribute = result.getAttribute();
    assertThat(resultAttribute.getID()).isEqualTo("someattr");
    assertThat(resultAttribute.size()).isEqualTo(0);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:22,代码来源:ModifyAttributesOperationRecorderTest.java

示例5: testGetCompensatingModificationItem_AddExistingAttribute

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testGetCompensatingModificationItem_AddExistingAttribute()
        throws NamingException {
    BasicAttribute attribute = new BasicAttribute("someattr");
    attribute.add("value1");
    attribute.add("value2");
    Attributes attributes = new BasicAttributes();
    attributes.put(attribute);

    BasicAttribute modificationAttribute = new BasicAttribute("someattr");
    modificationAttribute.add("newvalue1");
    modificationAttribute.add("newvalue2");
    ModificationItem originalItem = new ModificationItem(
            DirContext.ADD_ATTRIBUTE, new BasicAttribute("someattr"));

    // Perform test
    ModificationItem result = tested.getCompensatingModificationItem(
            attributes, originalItem);

    // Verify result
    assertThat(result.getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE);
    Attribute resultAttribute = result.getAttribute();
    assertThat(resultAttribute.getID()).isEqualTo("someattr");
    assertThat(result.getAttribute().get(0)).isEqualTo("value1");
    assertThat(result.getAttribute().get(1)).isEqualTo("value2");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:27,代码来源:ModifyAttributesOperationRecorderTest.java

示例6: testGetCompensatingModificationItem_RemoveTwoAttributeValues

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testGetCompensatingModificationItem_RemoveTwoAttributeValues()
        throws NamingException {
    BasicAttribute attribute = new BasicAttribute("someattr");
    attribute.add("value1");
    attribute.add("value2");
    attribute.add("value3");
    Attributes attributes = new BasicAttributes();
    attributes.put(attribute);

    BasicAttribute modificationAttribute = new BasicAttribute("someattr");
    modificationAttribute.add("value1");
    modificationAttribute.add("value2");
    ModificationItem originalItem = new ModificationItem(
            DirContext.REMOVE_ATTRIBUTE, modificationAttribute);

    // Perform test
    ModificationItem result = tested.getCompensatingModificationItem(
            attributes, originalItem);

    // Verify result
    assertThat(result.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE);
    Attribute resultAttribute = result.getAttribute();
    assertThat(resultAttribute.getID()).isEqualTo("someattr");
    Object object = resultAttribute.get(0);
    assertThat(object).isEqualTo("value1");
    assertThat(resultAttribute.get(1)).isEqualTo("value2");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:29,代码来源:ModifyAttributesOperationRecorderTest.java

示例7: testGetCompensatingModificationItem_ReplaceExistingAttribute

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testGetCompensatingModificationItem_ReplaceExistingAttribute()
        throws NamingException {
    BasicAttribute attribute = new BasicAttribute("someattr");
    attribute.add("value1");
    attribute.add("value2");
    Attributes attributes = new BasicAttributes();
    attributes.put(attribute);

    BasicAttribute modificationAttribute = new BasicAttribute("someattr");
    modificationAttribute.add("newvalue1");
    modificationAttribute.add("newvalue2");
    ModificationItem originalItem = new ModificationItem(
            DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("someattr"));

    // Perform test
    ModificationItem result = tested.getCompensatingModificationItem(
            attributes, originalItem);

    // Verify result
    assertThat(result.getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE);
    Attribute resultAttribute = result.getAttribute();
    assertThat(resultAttribute.getID()).isEqualTo("someattr");
    Object object = resultAttribute.get(0);
    assertThat(object).isEqualTo("value1");
    assertThat(resultAttribute.get(1)).isEqualTo("value2");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:28,代码来源:ModifyAttributesOperationRecorderTest.java

示例8: dumpModificationItems

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
/**
 * Dumps the modifications
 */
private String dumpModificationItems()
{
    StringBuffer sb = new StringBuffer();

    for (ModificationItem modif : modificationList) {
        sb.append("            Operation: ");

        switch (modif.getModificationOp()) {
            case DirContext.ADD_ATTRIBUTE :
                sb.append("ADD\n");
                break;

            case DirContext.REMOVE_ATTRIBUTE :
                sb.append("REMOVE\n");
                break;

            case DirContext.REPLACE_ATTRIBUTE :
                sb.append("REPLACE \n");
                break;
        }

        Attribute attribute = modif.getAttribute();

        sb.append("                Attribute: ").append(attribute.getID()).append('\n');

        if (attribute.size() != 0) {
            try {
                for (NamingEnumeration values = attribute.getAll(); values.hasMoreElements();) {
                    Object value = values.nextElement();

                    if (value instanceof String) {
                        sb.append("                ").append((String) value).append('\n');
                    } else {
                        sb.append("                ").append(Utils.dumpBytes((byte[]) value)).append('\n');
                    }
                }
            }
            catch (NamingException ne) {
                return "";
            }
        }
    }

    return sb.toString();
}
 
开发者ID:scriptella,项目名称:scriptella-etl,代码行数:49,代码来源:Entry.java

示例9: getCompensatingModificationItem

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
/**
 * Get a ModificationItem to use for rollback of the supplied modification.
 * 
 * @param originalAttributes
 *            All Attributes of the target DN that are affected of any of
 *            the ModificationItems.
 * @param modificationItem
 *            the ModificationItem to create a rollback item for.
 * @return A ModificationItem to use for rollback of the supplied
 *         ModificationItem.
 */
protected ModificationItem getCompensatingModificationItem(
        Attributes originalAttributes, ModificationItem modificationItem) {
    Attribute modificationAttribute = modificationItem.getAttribute();
    Attribute originalAttribute = originalAttributes
            .get(modificationAttribute.getID());

    if (modificationItem.getModificationOp() == DirContext.REMOVE_ATTRIBUTE) {
        if (modificationAttribute.size() == 0) {
            // If the modification attribute size it means that the
            // Attribute should be removed entirely - we should store a
            // ModificationItem to restore all present values for rollback.
            return new ModificationItem(DirContext.ADD_ATTRIBUTE,
                    (Attribute) originalAttribute.clone());
        } else {
            // The rollback modification will be to re-add the removed
            // attribute values.
            return new ModificationItem(DirContext.ADD_ATTRIBUTE,
                    (Attribute) modificationAttribute.clone());
        }
    } else if (modificationItem.getModificationOp() == DirContext.REPLACE_ATTRIBUTE) {
        if (originalAttribute != null) {
            return new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
                    (Attribute) originalAttribute.clone());
        } else {
            // The attribute doesn't previously exist - the rollback
            // operation will be to remove the attribute.
            return new ModificationItem(DirContext.REMOVE_ATTRIBUTE,
                    new BasicAttribute(modificationAttribute.getID()));
        }
    } else {
        // An ADD_ATTRIBUTE operation
        if (originalAttribute == null) {
            // The attribute doesn't previously exist - the rollback
            // operation will be to remove the attribute.
            return new ModificationItem(DirContext.REMOVE_ATTRIBUTE,
                    new BasicAttribute(modificationAttribute.getID()));
        } else {
            // The attribute does exist before - we should store the
            // previous value and it should be used for replacing in
            // rollback.
            return new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
                    (Attribute) originalAttribute.clone());
        }
    }
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:57,代码来源:ModifyAttributesOperationRecorder.java

示例10: testAddReplaceAndChangeAttribute

import javax.naming.directory.ModificationItem; //导入方法依赖的package包/类
@Test
public void testAddReplaceAndChangeAttribute() throws Exception {
	final Attributes fixtureAttrs = new BasicAttributes();
	fixtureAttrs.put(new BasicAttribute("abc", "123"));
	fixtureAttrs.put(new BasicAttribute("qwe", "42"));
	class TestableDirContextAdapter extends DirContextAdapter {
		public TestableDirContextAdapter() {
			super(fixtureAttrs, null);
			setUpdateMode(true);
		}
	}
	tested = new TestableDirContextAdapter();
	assertThat(tested.isUpdateMode()).isTrue();
	tested.setAttributeValue("abc", "234"); // change
	tested.setAttributeValue("qwe", null); // remove
	tested.setAttributeValue("zzz", "new"); // new
	Attributes attrs = tested.getAttributes();
	Attribute attr = attrs.get("abc");
	assertThat((String) attr.get()).isEqualTo("123");
	assertThat(attrs.size()).isEqualTo(2);

	ModificationItem[] mods = tested.getModificationItems();
	assertThat(mods.length).isEqualTo(3);
	String[] modNames = tested.getNamesOfModifiedAttributes();
	assertThat(modNames.length).isEqualTo(3);

	ModificationItem mod = getModificationItem(mods,
			DirContext.REPLACE_ATTRIBUTE);
	assertThat(mod).isNotNull();
	attr = mod.getAttribute();
	assertThat((String) attr.getID()).isEqualTo("abc");
	assertThat((String) attr.get()).isEqualTo("234");

	mod = getModificationItem(mods, DirContext.REMOVE_ATTRIBUTE);
	assertThat(mod).isNotNull();
	attr = mod.getAttribute();
	assertThat((String) attr.getID()).isEqualTo("qwe");

	mod = getModificationItem(mods, DirContext.ADD_ATTRIBUTE);
	assertThat(mod).isNotNull();
	attr = mod.getAttribute();
	assertThat((String) attr.getID()).isEqualTo("zzz");
	assertThat((String) attr.get()).isEqualTo("new");

	tested.update();
	mods = tested.getModificationItems();
	assertThat(mods.length).isEqualTo(0);
	modNames = tested.getNamesOfModifiedAttributes();
	assertThat(modNames.length).isEqualTo(0);

	attrs = tested.getAttributes();
	assertThat(attrs.size()).isEqualTo(2);
	attr = attrs.get("abc");
	assertThat((String) attr.get()).isEqualTo("234");
	assertThat(tested.getStringAttribute("zzz")).isEqualTo("new");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:57,代码来源:DirContextAdapterTest.java


注:本文中的javax.naming.directory.ModificationItem.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。