| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.plugin.PluginResult; |
| | |
| | | // Make a copy of the entry and pare it down to only include the set |
| | | // of requested attributes. |
| | | Entry entryToReturn; |
| | | boolean omitReal = isVirtualAttributesOnly(); |
| | | boolean omitVirtual = isRealAttributesOnly(); |
| | | if ((getAttributes() == null) || getAttributes().isEmpty()) |
| | | { |
| | | entryToReturn = entry.duplicateWithoutOperationalAttributes(typesOnly, |
| | | true); |
| | | entryToReturn = |
| | | entry.duplicateWithoutOperationalAttributes(typesOnly, |
| | | omitReal, omitVirtual); |
| | | } |
| | | else |
| | | { |
| | |
| | | { |
| | | // This is a special placeholder indicating that all user attributes |
| | | // should be returned. |
| | | if (typesOnly) |
| | | if (!omitReal) |
| | | { |
| | | // First, add the placeholder for the objectclass attribute. |
| | | AttributeType ocType = |
| | | DirectoryServer.getObjectClassAttributeType(); |
| | | List<Attribute> ocList = new ArrayList<Attribute>(1); |
| | | ocList.add(Attributes.empty(ocType)); |
| | | entryToReturn.putAttribute(ocType, ocList); |
| | | } |
| | | else |
| | | { |
| | | // First, add the objectclass attribute. |
| | | Attribute ocAttr = entry.getObjectClassAttribute(); |
| | | if (ocAttr != null) |
| | | if (typesOnly) |
| | | { |
| | | entryToReturn.replaceAttribute(ocAttr); |
| | | // First, add the placeholder for the objectclass |
| | | // attribute. |
| | | AttributeType ocType = |
| | | DirectoryServer.getObjectClassAttributeType(); |
| | | List<Attribute> ocList = new ArrayList<Attribute>(1); |
| | | ocList.add(Attributes.empty(ocType)); |
| | | entryToReturn.putAttribute(ocType, ocList); |
| | | } |
| | | else |
| | | { |
| | | // First, add the objectclass attribute. |
| | | Attribute ocAttr = entry.getObjectClassAttribute(); |
| | | if (ocAttr != null) |
| | | { |
| | | entryToReturn.replaceAttribute(ocAttr); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | for (AttributeType t : entry.getUserAttributes().keySet()) |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.duplicateUserAttribute(t, null, typesOnly); |
| | | entryToReturn.putAttribute(t, attrList); |
| | | duplicateUserAttribute(entry, t, null, typesOnly, |
| | | omitReal, omitVirtual); |
| | | if (attrList != null) |
| | | { |
| | | entryToReturn.putAttribute(t, attrList); |
| | | } |
| | | } |
| | | |
| | | continue; |
| | |
| | | for (AttributeType t : entry.getOperationalAttributes().keySet()) |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.duplicateOperationalAttribute(t, null, typesOnly); |
| | | entryToReturn.putAttribute(t, attrList); |
| | | duplicateOperationalAttribute(entry, t, null, |
| | | typesOnly, omitReal, omitVirtual); |
| | | if (attrList != null) |
| | | { |
| | | entryToReturn.putAttribute(t, attrList); |
| | | } |
| | | } |
| | | |
| | | continue; |
| | |
| | | semicolonPos = nextPos; |
| | | nextPos = attrName.indexOf(';', semicolonPos+1); |
| | | } |
| | | |
| | | options.add(attrName.substring(semicolonPos+1)); |
| | | } |
| | | else |
| | |
| | | options = null; |
| | | } |
| | | |
| | | |
| | | AttributeType attrType = DirectoryServer.getAttributeType(lowerName); |
| | | if (attrType == null) |
| | | { |
| | |
| | | if (t.hasNameOrOID(lowerName)) |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.duplicateUserAttribute(t, options, typesOnly); |
| | | duplicateUserAttribute(entry, t, options, typesOnly, |
| | | omitReal, omitVirtual); |
| | | if (attrList != null) |
| | | { |
| | | entryToReturn.putAttribute(t, attrList); |
| | | |
| | | added = true; |
| | | break; |
| | | } |
| | |
| | | if (t.hasNameOrOID(lowerName)) |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.duplicateOperationalAttribute(t, options, typesOnly); |
| | | duplicateOperationalAttribute(entry, t, options, |
| | | typesOnly, omitReal, omitVirtual); |
| | | if (attrList != null) |
| | | { |
| | | entryToReturn.putAttribute(t, attrList); |
| | | |
| | | break; |
| | | } |
| | | } |
| | |
| | | else |
| | | { |
| | | if (attrType.isObjectClassType()) { |
| | | if (typesOnly) |
| | | if (!omitReal) |
| | | { |
| | | AttributeType ocType = |
| | | DirectoryServer.getObjectClassAttributeType(); |
| | | List<Attribute> ocList = new ArrayList<Attribute>(1); |
| | | ocList.add(Attributes.empty(ocType)); |
| | | entryToReturn.putAttribute(ocType, ocList); |
| | | } |
| | | else |
| | | { |
| | | List<Attribute> attrList = new ArrayList<Attribute>(1); |
| | | attrList.add(entry.getObjectClassAttribute()); |
| | | entryToReturn.putAttribute(attrType, attrList); |
| | | if (typesOnly) |
| | | { |
| | | AttributeType ocType = |
| | | DirectoryServer.getObjectClassAttributeType(); |
| | | List<Attribute> ocList = new ArrayList<Attribute>(1); |
| | | ocList.add(Attributes.empty(ocType)); |
| | | entryToReturn.putAttribute(ocType, ocList); |
| | | } |
| | | else |
| | | { |
| | | List<Attribute> attrList = new ArrayList<Attribute>(1); |
| | | attrList.add(entry.getObjectClassAttribute()); |
| | | entryToReturn.putAttribute(attrType, attrList); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.duplicateOperationalAttribute(attrType, options, |
| | | typesOnly); |
| | | duplicateOperationalAttribute(entry, attrType, options, |
| | | typesOnly, omitReal, omitVirtual); |
| | | if (attrList == null) |
| | | { |
| | | attrList = entry.duplicateUserAttribute(attrType, options, |
| | | typesOnly); |
| | | attrList = |
| | | duplicateUserAttribute(entry, attrType, options, |
| | | typesOnly, omitReal, omitVirtual); |
| | | } |
| | | if (attrList != null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (isRealAttributesOnly()) |
| | | { |
| | | entryToReturn.stripVirtualAttributes(); |
| | | } |
| | | else if (isVirtualAttributesOnly()) |
| | | { |
| | | entryToReturn.stripRealAttributes(); |
| | | } |
| | | |
| | | // If there is a matched values control, then further pare down the entry |
| | | // based on the filters that it contains. |
| | | MatchedValuesControl matchedValuesControl = getMatchedValuesControl(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public final void run() |
| | | { |
| | | setResultCode(ResultCode.UNDEFINED); |
| | |
| | | appendErrorMessage(message); |
| | | } |
| | | |
| | | |
| | | // Copies non-empty attributes. |
| | | private List<Attribute> duplicateAttribute( |
| | | List<Attribute> attrList, |
| | | Set<String> options, |
| | | boolean omitValues, |
| | | boolean omitReal, |
| | | boolean omitVirtual) |
| | | { |
| | | if (attrList == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | ArrayList<Attribute> duplicateList = |
| | | new ArrayList<Attribute>(attrList.size()); |
| | | for (Attribute a : attrList) |
| | | { |
| | | if (a.hasAllOptions(options)) |
| | | { |
| | | if (omitReal && !a.isVirtual()) |
| | | { |
| | | continue; |
| | | } |
| | | else if (omitVirtual && a.isVirtual()) |
| | | { |
| | | continue; |
| | | } |
| | | else if (a.isEmpty()) |
| | | { |
| | | continue; |
| | | } |
| | | else if (omitValues) |
| | | { |
| | | duplicateList.add(Attributes.empty(a)); |
| | | } |
| | | else |
| | | { |
| | | duplicateList.add(a); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (duplicateList.isEmpty()) |
| | | { |
| | | return null; |
| | | } |
| | | else |
| | | { |
| | | return duplicateList; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // Copy a user attribute - may return null if the attribute was |
| | | // not found or if it was empty. |
| | | private List<Attribute> duplicateUserAttribute( |
| | | Entry entry, |
| | | AttributeType attributeType, |
| | | Set<String> options, |
| | | boolean omitValues, |
| | | boolean omitReal, |
| | | boolean omitVirtual) |
| | | { |
| | | List<Attribute> currentList = entry.getUserAttribute(attributeType); |
| | | return duplicateAttribute(currentList, options, omitValues, |
| | | omitReal, omitVirtual); |
| | | } |
| | | |
| | | |
| | | |
| | | // Copy an operational attribute - may return null if the |
| | | // attribute was not found or if it was empty. |
| | | private List<Attribute> duplicateOperationalAttribute( |
| | | Entry entry, |
| | | AttributeType attributeType, |
| | | Set<String> options, |
| | | boolean omitValues, |
| | | boolean omitReal, |
| | | boolean omitVirtual) |
| | | { |
| | | List<Attribute> currentList = |
| | | entry.getOperationalAttribute(attributeType); |
| | | return duplicateAttribute(currentList, options, omitValues, |
| | | omitReal, omitVirtual); |
| | | } |
| | | } |