/** * This method is used to initialize the OBJECT_CLASS_AT attributeType. * * We want to do it only once, so it's a synchronized method. Note that * the alternative would be to call the lookup() every time, but this won't * be very efficient, as it will get the AT from a map, which is also * synchronized, so here, we have a very minimal cost. * * We can't do it once as a static part in the body of this class, because * the access to the registries is mandatory to get back the AttributeType. */ private void initObjectClassAT( SchemaManager schemaManager ) { try { if ( OBJECT_CLASS_AT == null ) { synchronized ( MUTEX ) { OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ); } } } catch ( LdapException ne ) { // do nothing... } }
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
/** * Returns the attributeType from an Attribute ID. */ private AttributeType getAttributeType( String upId ) throws LdapException { if ( StringTools.isEmpty( StringTools.trim( upId ) ) ) { String message = I18n.err( I18n.ERR_04457 ); LOG.error( message ); throw new IllegalArgumentException( message ); } return schemaManager.lookupAttributeTypeRegistry( upId ); }
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
private final void injectNames( List<String> names, ServerEntry entry, SchemaManager schemaManager ) throws LdapException { if ( ( names == null ) || ( names.size() == 0 ) ) { return; } EntryAttribute attr = new DefaultServerAttribute( schemaManager.lookupAttributeTypeRegistry( MetaSchemaConstants.M_NAME_AT ) ); for ( String name:names ) { attr.add( name ); } entry.put( attr ); }
/** * Deserialize a ServerModification * * @param in The buffer containing the serialized value * @param atRegistry The AttributeType registry * @throws IOException If we weren't able to deserialize the data * @throws ClassNotFoundException if we weren't able to construct a Modification instance * @throws LdapException If we didn't found the AttributeType in the registries */ public void deserialize( ObjectInput in, SchemaManager schemaManager ) throws IOException, ClassNotFoundException, LdapException { // Read the operation int op = in.readInt(); operation = ModificationOperation.getOperation( op ); // Read the attribute OID String oid = in.readUTF(); // Lookup for tha associated AttributeType AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid ); attribute = new DefaultServerAttribute( attributeType ); // Read the attribute ((DefaultServerAttribute)attribute).deserialize( in ); }
/** * * Convert a list of ModificationItemImpl to a list of * * @param modificationImpls * @param atRegistry * @return * @throws LdapException */ public static List<Modification> convertToServerModification( List<ModificationItem> modificationItems, SchemaManager schemaManager ) throws LdapException { if ( modificationItems != null ) { List<Modification> modifications = new ArrayList<Modification>( modificationItems.size() ); for ( ModificationItem modificationItem: modificationItems ) { AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( modificationItem.getAttribute().getID() ); modifications.add( toServerModification( modificationItem, attributeType ) ); } return modifications; } else { return null; } }
private void setupUserIndices() throws Exception { if ( userIndices != null && userIndices.size() > 0 ) { Map<String, AvlIndex<? extends Object, E>> tmp = new HashMap<String, AvlIndex<? extends Object, E>>(); for ( AvlIndex<? extends Object, E> index : userIndices.values() ) { String oid = schemaManager.getAttributeTypeRegistry().getOidByName( index.getAttributeId() ); AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid ); // Check that the attributeType has an EQUALITY matchingRule MatchingRule mr = attributeType.getEquality(); if ( mr != null ) { index.initialize( schemaManager.lookupAttributeTypeRegistry( oid ) ); tmp.put( oid, index ); } else { LOG.error( I18n.err( I18n.ERR_4, attributeType.getName() ) ); } } userIndices = tmp; } else { userIndices = new HashMap<String, AvlIndex<? extends Object, E>>(); } }
/** * Normalize the ReturningAttributes. It reads all the String from the returningAttributesString, * and grab the associated AttributeType from the schema to store it into the returningAttributes * Set. * * @param schemaManager The schema manager */ public void normalize( SchemaManager schemaManager ) { for ( String returnAttribute : returningAttributesStr ) { try { String id = SchemaUtils.stripOptions( returnAttribute ); Set<String> options = SchemaUtils.getOptions( returnAttribute ); AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id ); AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options ); returningAttributes.add( attrOptions ); } catch ( LdapException ne ) { LOG.warn( "Requested attribute {} does not exist in the schema, it will be ignored", returnAttribute ); // Unknown attributes should be silently ignored, as RFC 2251 states } } }
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
/** * Looks up the Normalizer to use for a name component using the attributeId * for the name component. First the attribute is resolved, then its * equality matching rule is looked up. The normalizer of that matching * rule is returned. * * @param id the name or oid of the attribute in the name component to * normalize the value of * @return the Normalizer to use for normalizing the value of the attribute * @throws LdapException if there are failures resolving the Normalizer */ private Normalizer lookup( String id ) throws LdapException { AttributeType type = schemaManager.lookupAttributeTypeRegistry( id ); MatchingRule mrule = type.getEquality(); if ( mrule == null ) { return new NoOpNormalizer( id ); } return mrule.getNormalizer(); }
/** * <p> * Returns the attribute with the specified alias. The return value * is <code>null</code> if no match is found. * </p> * <p>An Attribute with an id different from the supplied alias may * be returned: for example a call with 'cn' may in some implementations * return an Attribute whose getId() field returns 'commonName'. * </p> * <p> * If the attributeType is not found, returns null. * </p> * * @param alias an aliased name of the attribute identifier * @return the attribute associated with the alias */ public EntryAttribute get( String alias ) { try { return get( schemaManager.lookupAttributeTypeRegistry( StringTools.trim( StringTools.toLowerCase( alias ) ) ) ); } catch ( LdapException ne ) { String message = ne.getLocalizedMessage(); LOG.error( message ); return null; } }
/** * {@inheritDoc} * TODO why this and initRegistries on Store interface ??? */ public void init( SchemaManager schemaManager ) throws Exception { this.schemaManager = schemaManager; OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ); ALIASED_OBJECT_NAME_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ALIASED_OBJECT_NAME_AT ); // Create the master table (the table containing all the entries) master = new AvlMasterTable<ServerEntry>( name, new LongComparator(), null, false ); suffixDn.normalize( schemaManager.getNormalizerMapping() ); // ------------------------------------------------------------------- // Initializes the user and system indices // ------------------------------------------------------------------- setupSystemIndices(); setupUserIndices(); // We are done ! initialized = true; }
public ServerModification( SchemaManager schemaManager, Modification modification ) { operation = modification.getOperation(); EntryAttribute modAttribute = modification.getAttribute(); try { AttributeType at = null; if ( modAttribute instanceof DefaultServerAttribute ) { at = ((EntryAttribute)modAttribute).getAttributeType(); } else { at = schemaManager.lookupAttributeTypeRegistry( modAttribute.getId() ); } attribute = new DefaultServerAttribute( at, modAttribute ); } catch ( LdapException ne ) { // The attributeType is incorrect. Log, but do nothing otherwise. LOG.error( I18n.err( I18n.ERR_04472, modAttribute.getId() ) ); } }
/** * @see NameComponentNormalizer#normalizeByName(String, String) */ public Object normalizeByName( String name, byte[] value ) throws LdapException { AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( name ); if ( !attributeType.getSyntax().isHumanReadable() ) { return lookup( name ).normalize( new BinaryValue( value ) ); } else { try { String valStr = new String( value, "UTF-8" ); return lookup( name ).normalize( valStr ); } catch ( UnsupportedEncodingException uee ) { String message = I18n.err( I18n.ERR_04223 ); LOG.error( message ); throw new LdapException( message ); } } }
/** * @see NameComponentNormalizer#normalizeByName(String, String) */ public Object normalizeByName( String name, String value ) throws LdapException { AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( name ); if ( attributeType.getSyntax().isHumanReadable() ) { return lookup( name ).normalize( value ); } else { try { String unescaped = unescape( value ); byte[] valBytes = unescaped.getBytes( "UTF-8" ); return lookup( name ).normalize( new BinaryValue( valBytes ) ); } catch ( UnsupportedEncodingException uee ) { String message = I18n.err( I18n.ERR_04222 ); LOG.error( message ); throw new LdapException( message ); } } }
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id ); modificationsList.add( toServerModification( (ModificationItem)modification, attributeType ) );
public ServerEntry getAttributes( Schema schema, SchemaManager schemaManager ) throws LdapException { ServerEntry entry = new DefaultServerEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SCHEMA_OC ); entry.put( SchemaConstants.CN_AT, schema.getSchemaName() ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() ); if ( schema.isDisabled() ) { entry.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" ); } String[] dependencies = schema.getDependencies(); if ( dependencies != null && dependencies.length > 0 ) { EntryAttribute attr = new DefaultServerAttribute( schemaManager.lookupAttributeTypeRegistry( MetaSchemaConstants.M_DEPENDENCIES_AT ) ); for ( String dependency:dependencies ) { attr.add( dependency ); } entry.put( attr ); } return entry; }
AttributeType attributeType = directoryService.getSchemaManager().lookupAttributeTypeRegistry( oid );