| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ServerContext; |
| | |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.opends.server.util.RemoveOnceSDKSchemaIsUsed; |
| | | |
| | | /** |
| | | * This class provides a utility for interacting with compressed representations |
| | |
| | | } |
| | | } |
| | | |
| | | private Mappings reloadMappingsIfSchemaChanged(boolean force) |
| | | private Mappings reloadMappingsIfSchemaChanged() |
| | | { |
| | | // @RemoveOnceSDKSchemaIsUsed remove the "force" parameter |
| | | sharedLock.lock(); |
| | | boolean shared = true; |
| | | try |
| | | { |
| | | Schema currentSchema = serverContext.getSchemaNG(); |
| | | if (force || schemaNG != currentSchema) |
| | | if (schemaNG != currentSchema) |
| | | { |
| | | sharedLock.unlock(); |
| | | exclusiveLock.lock(); |
| | | shared = false; |
| | | |
| | | currentSchema = serverContext.getSchemaNG(); |
| | | if (force || schemaNG != currentSchema) |
| | | if (schemaNG != currentSchema) |
| | | { |
| | | // build new maps from existing ones |
| | | Mappings newMappings = new Mappings(mappings.adEncodeMap.size(), mappings.ocEncodeMap.size()); |
| | |
| | | throws DirectoryException |
| | | { |
| | | // First decode the encoded attribute description id. |
| | | final int id = decodeId(reader); |
| | | final int adId = decodeId(reader); |
| | | |
| | | // Before returning the attribute, make sure that the attribute type is not stale. |
| | | final Mappings mappings = reloadMappingsIfSchemaChanged(false); |
| | | final AttributeDescription ad = mappings.adDecodeMap.get(id); |
| | | final Mappings mappings = reloadMappingsIfSchemaChanged(); |
| | | final AttributeDescription ad = mappings.adDecodeMap.get(adId); |
| | | if (ad == null) |
| | | { |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | ERR_COMPRESSEDSCHEMA_UNRECOGNIZED_AD_TOKEN.get(id)); |
| | | ERR_COMPRESSEDSCHEMA_UNRECOGNIZED_AD_TOKEN.get(adId)); |
| | | } |
| | | |
| | | AttributeType attrType = ad.getAttributeType(); |
| | |
| | | final ByteSequenceReader reader) throws DirectoryException |
| | | { |
| | | // First decode the encoded object class id. |
| | | final int id = decodeId(reader); |
| | | final int ocId = decodeId(reader); |
| | | |
| | | // Look up the object classes. |
| | | final Mappings mappings = getMappings(); |
| | | Map<ObjectClass, String> ocMap = mappings.ocDecodeMap.get(id); |
| | | // Before returning the object classes, make sure that none of them are stale. |
| | | final Mappings mappings = reloadMappingsIfSchemaChanged(); |
| | | Map<ObjectClass, String> ocMap = mappings.ocDecodeMap.get(ocId); |
| | | if (ocMap == null) |
| | | { |
| | | // @RemoveOnceSDKSchemaIsUsed remove this first check (check is performed again later) |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | ERR_COMPRESSEDSCHEMA_UNKNOWN_OC_TOKEN.get(id)); |
| | | } |
| | | // Before returning the object classes, make sure that none of them are stale. |
| | | boolean forceReload = isAnyObjectClassDirty(ocMap.keySet()); |
| | | final Mappings newMappings = reloadMappingsIfSchemaChanged(forceReload); |
| | | if (mappings != newMappings) |
| | | { |
| | | ocMap = newMappings.ocDecodeMap.get(id); |
| | | if (ocMap == null) |
| | | { |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | ERR_COMPRESSEDSCHEMA_UNKNOWN_OC_TOKEN.get(id)); |
| | | } |
| | | ERR_COMPRESSEDSCHEMA_UNKNOWN_OC_TOKEN.get(ocId)); |
| | | } |
| | | return ocMap; |
| | | } |
| | | |
| | | @RemoveOnceSDKSchemaIsUsed |
| | | private boolean isAnyObjectClassDirty(Set<ObjectClass> objectClasses) |
| | | { |
| | | for (final ObjectClass oc : objectClasses) |
| | | { |
| | | if (oc.isDirty()) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Encodes the information in the provided attribute to a byte array. |
| | | * |