Java Code Examples for org.apache.directory.api.ldap.model.schema.AttributeType#getOid()

The following examples show how to use org.apache.directory.api.ldap.model.schema.AttributeType#getOid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get the UpId if it is null.
 *
 * @param upId The ID
 * @param attributeType The AttributeType to retrieve
 * @return the retrieved ID
 */
private String getUpId( String upId, AttributeType attributeType )
{
    String normUpId = Strings.trim( upId );

    if ( attributeType == null )
    {
        if ( Strings.isEmpty( normUpId ) )
        {
            String message = I18n.err( I18n.ERR_13226_CANNOT_ADD_ATTRIBUTE_NO_ID );
            LOG.error( message );
            throw new IllegalArgumentException( message );
        }

        return upId;
    }
    else if ( Strings.isEmpty( normUpId ) )
    {
        String id = attributeType.getName();

        if ( Strings.isEmpty( id ) )
        {
            id = attributeType.getOid();
        }

        return id;
    }
    else
    {
        return upId;
    }
}
 
Example 2
Source File: DefaultAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean hasDescendants( AttributeType ancestor ) throws LdapException
{
    String oid = ancestor.getOid();
    Set<AttributeType> descendants = oidToDescendantSet.get( oid );
    return ( descendants != null ) && !descendants.isEmpty();
}
 
Example 3
Source File: DefaultAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addMappingFor( AttributeType attributeType ) throws LdapException
{
    MatchingRule equality = attributeType.getEquality();
    OidNormalizer oidNormalizer;
    String oid = attributeType.getOid();

    if ( equality == null )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_13703_AT_WITHOUT_EQ_MR, attributeType.getName() ) );
        }
        
        oidNormalizer = new OidNormalizer( oid, new NoOpNormalizer( attributeType.getOid() ) );
    }
    else
    {
        oidNormalizer = new OidNormalizer( oid, equality.getNormalizer() );
    }

    oidNormalizerMap.put( oid, oidNormalizer );

    // Also inject the attributeType's short names in the map
    for ( String name : attributeType.getNames() )
    {
        oidNormalizerMap.put( Strings.toLowerCaseAscii( name ), oidNormalizer );
    }
}
 
Example 4
Source File: ConcreteNameComponentNormalizer.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object normalizeByName( AttributeType attributeType, String value ) throws LdapException
{
    MatchingRule mrule = attributeType.getEquality();
    Normalizer normalizer;
        
    if ( mrule == null )
    {
        return new NoOpNormalizer( attributeType.getOid() );
    }
    else
    {
        normalizer = attributeType.getEquality().getNormalizer();
    }

    if ( attributeType.getSyntax().isHumanReadable() )
    {
        return normalizer.normalize( value );
    }
    else
    {
        String unescaped = unescape( value );

        return normalizer.normalize( unescaped );
    }
}
 
Example 5
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Get the UpId if it is null.
 * 
 * @param upId The ID
 */
private String getUpId( String upId, AttributeType attributeType )
{
    String normUpId = Strings.trim( upId );

    if ( ( attributeType == null ) )
    {
        if ( Strings.isEmpty( normUpId ) )
        {
            String message = I18n.err( I18n.ERR_04458 );
            LOG.error( message );
            throw new IllegalArgumentException( message );
        }

        return upId;
    }
    else if ( Strings.isEmpty( normUpId ) )
    {
        String id = attributeType.getName();

        if ( Strings.isEmpty( id ) )
        {
            id = attributeType.getOid();
        }

        return id;
    }
    else
    {
        return upId;
    }
}
 
Example 6
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the MUST attributes for an objectClass. This method gather all the
 * MUST from all the objectClass and its superors.
 *
 * @param atSeen ???
 * @param objectClass the object class to gather MUST attributes for
 * @throws Exception if there are problems resolving schema entitites
 */
private void computeMustAttributes( ObjectClass objectClass, Set<String> atSeen ) throws LdapException
{
    List<ObjectClass> parents = superiors.get( objectClass.getOid() );

    List<AttributeType> mustList = new ArrayList<AttributeType>();
    List<AttributeType> allowedList = new ArrayList<AttributeType>();
    Set<String> mustSeen = new HashSet<String>();

    allMust.put( objectClass.getOid(), mustList );
    allowed.put( objectClass.getOid(), allowedList );

    for ( ObjectClass parent : parents )
    {
        List<AttributeType> mustParent = parent.getMustAttributeTypes();

        if ( ( mustParent != null ) && ( mustParent.size() != 0 ) )
        {
            for ( AttributeType attributeType : mustParent )
            {
                String oid = attributeType.getOid();

                if ( !mustSeen.contains( oid ) )
                {
                    mustSeen.add( oid );
                    mustList.add( attributeType );
                    allowedList.add( attributeType );
                    atSeen.add( attributeType.getOid() );
                }
            }
        }
    }
}
 
Example 7
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the MAY attributes for an objectClass. This method gather all the
 * MAY from all the objectClass and its superors.
 *
 * The allowed attributes is also computed, it's the union of MUST and MAY
 *
 * @param atSeen ???
 * @param objectClass the object class to get all the MAY attributes for
 * @throws Exception with problems accessing registries
 */
private void computeMayAttributes( ObjectClass objectClass, Set<String> atSeen ) throws LdapException
{
    List<ObjectClass> parents = superiors.get( objectClass.getOid() );

    List<AttributeType> mayList = new ArrayList<AttributeType>();
    Set<String> maySeen = new HashSet<String>();
    List<AttributeType> allowedList = allowed.get( objectClass.getOid() );

    allMay.put( objectClass.getOid(), mayList );

    for ( ObjectClass parent : parents )
    {
        List<AttributeType> mustParent = parent.getMustAttributeTypes();

        if ( ( mustParent != null ) && ( mustParent.size() != 0 ) )
        {
            for ( AttributeType attributeType : mustParent )
            {
                String oid = attributeType.getOid();

                if ( !maySeen.contains( oid ) )
                {
                    maySeen.add( oid );
                    mayList.add( attributeType );

                    if ( !atSeen.contains( oid ) )
                    {
                        allowedList.add( attributeType );
                    }
                }
            }
        }
    }
}
 
Example 8
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Set<String> getAllAllowed( Attribute objectClasses, Set<String> must ) throws LdapException
{
    Set<String> allowed = new HashSet<String>( must );

    // Add the 'ObjectClass' attribute ID
    allowed.add( SchemaConstants.OBJECT_CLASS_AT_OID );

    // Loop on all objectclasses
    for ( Value<?> objectClass : objectClasses )
    {
        String ocName = objectClass.getString();
        ObjectClass oc = schemaManager.lookupObjectClassRegistry( ocName );

        List<AttributeType> types = oc.getMayAttributeTypes();

        // For each objectClass, loop on all MAY attributeTypes, if any
        if ( ( types != null ) && ( types.size() > 0 ) )
        {
            for ( AttributeType type : types )
            {
                String oid = type.getOid();

                allowed.add( oid );
            }
        }
    }

    return allowed;
}
 
Example 9
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Get the UpId if it is null.
 * 
 * @param upId The ID
 */
private String getUpId( String upId, AttributeType attributeType )
{
    String normUpId = Strings.trim( upId );

    if ( ( attributeType == null ) )
    {
        if ( Strings.isEmpty( normUpId ) )
        {
            String message = I18n.err( I18n.ERR_04458 );
            LOG.error( message );
            throw new IllegalArgumentException( message );
        }

        return upId;
    }
    else if ( Strings.isEmpty( normUpId ) )
    {
        String id = attributeType.getName();

        if ( Strings.isEmpty( id ) )
        {
            id = attributeType.getOid();
        }

        return id;
    }
    else
    {
        return upId;
    }
}
 
Example 10
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the MUST attributes for an objectClass. This method gather all the
 * MUST from all the objectClass and its superors.
 *
 * @param atSeen ???
 * @param objectClass the object class to gather MUST attributes for
 * @throws Exception if there are problems resolving schema entitites
 */
private void computeMustAttributes( ObjectClass objectClass, Set<String> atSeen ) throws LdapException
{
    List<ObjectClass> parents = superiors.get( objectClass.getOid() );

    List<AttributeType> mustList = new ArrayList<AttributeType>();
    List<AttributeType> allowedList = new ArrayList<AttributeType>();
    Set<String> mustSeen = new HashSet<String>();

    allMust.put( objectClass.getOid(), mustList );
    allowed.put( objectClass.getOid(), allowedList );

    for ( ObjectClass parent : parents )
    {
        List<AttributeType> mustParent = parent.getMustAttributeTypes();

        if ( ( mustParent != null ) && ( mustParent.size() != 0 ) )
        {
            for ( AttributeType attributeType : mustParent )
            {
                String oid = attributeType.getOid();

                if ( !mustSeen.contains( oid ) )
                {
                    mustSeen.add( oid );
                    mustList.add( attributeType );
                    allowedList.add( attributeType );
                    atSeen.add( attributeType.getOid() );
                }
            }
        }
    }
}
 
Example 11
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the MAY attributes for an objectClass. This method gather all the
 * MAY from all the objectClass and its superors.
 *
 * The allowed attributes is also computed, it's the union of MUST and MAY
 *
 * @param atSeen ???
 * @param objectClass the object class to get all the MAY attributes for
 * @throws Exception with problems accessing registries
 */
private void computeMayAttributes( ObjectClass objectClass, Set<String> atSeen ) throws LdapException
{
    List<ObjectClass> parents = superiors.get( objectClass.getOid() );

    List<AttributeType> mayList = new ArrayList<AttributeType>();
    Set<String> maySeen = new HashSet<String>();
    List<AttributeType> allowedList = allowed.get( objectClass.getOid() );

    allMay.put( objectClass.getOid(), mayList );

    for ( ObjectClass parent : parents )
    {
        List<AttributeType> mustParent = parent.getMustAttributeTypes();

        if ( ( mustParent != null ) && ( mustParent.size() != 0 ) )
        {
            for ( AttributeType attributeType : mustParent )
            {
                String oid = attributeType.getOid();

                if ( !maySeen.contains( oid ) )
                {
                    maySeen.add( oid );
                    mayList.add( attributeType );

                    if ( !atSeen.contains( oid ) )
                    {
                        allowedList.add( attributeType );
                    }
                }
            }
        }
    }
}
 
Example 12
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Set<String> getAllAllowed( Attribute objectClasses, Set<String> must ) throws LdapException
{
    Set<String> allowed = new HashSet<String>( must );

    // Add the 'ObjectClass' attribute ID
    allowed.add( SchemaConstants.OBJECT_CLASS_AT_OID );

    // Loop on all objectclasses
    for ( Value<?> objectClass : objectClasses )
    {
        String ocName = objectClass.getString();
        ObjectClass oc = schemaManager.lookupObjectClassRegistry( ocName );

        List<AttributeType> types = oc.getMayAttributeTypes();

        // For each objectClass, loop on all MAY attributeTypes, if any
        if ( ( types != null ) && ( types.size() > 0 ) )
        {
            for ( AttributeType type : types )
            {
                String oid = type.getOid();

                allowed.add( oid );
            }
        }
    }

    return allowed;
}
 
Example 13
Source File: DefaultAttribute.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
private void setUpIdInternal( String upId, String newId, AttributeType attributeType )
{
    if ( attributeType == null )
    {
        if ( this.attributeType == null )
        {
            this.upId = upId;
            this.id = newId;

            // Compute the hashCode
            rehash();

            return;
        }
        else
        {
            if ( areCompatible( newId, this.attributeType ) )
            {
                this.upId = upId;
                this.id = this.attributeType.getOid();

                // Compute the hashCode
                rehash();

                return;
            }
            else
            {
                return;
            }
        }
    }

    if ( Strings.isEmpty( newId ) )
    {
        this.attributeType = attributeType;
        this.upId = attributeType.getName();
        this.id = attributeType.getOid();

        // Compute the hashCode
        rehash();

        return;
    }

    if ( areCompatible( newId, attributeType ) )
    {
        this.upId = upId;
        this.id = attributeType.getOid();
        this.attributeType = attributeType;

        // Compute the hashCode
        rehash();

        return;
    }

    throw new IllegalArgumentException( I18n.err( I18n.ERR_13244_ID_AT_NOT_COMPATIBLE, id, attributeType.getName() ) );
}
 
Example 14
Source File: DefaultAttribute.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void apply( AttributeType attributeType ) throws LdapInvalidAttributeValueException
{
    if ( attributeType == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13245_AT_PARAMETER_NULL ) );
    }

    this.attributeType = attributeType;
    this.id = attributeType.getOid();

    if ( Strings.isEmpty( this.upId ) )
    {
        this.upId = attributeType.getName();
    }
    else
    {
        if ( !areCompatible( this.upId, attributeType ) )
        {
            this.upId = attributeType.getName();
        }
    }

    if ( values != null )
    {
        Set<Value> newValues = new LinkedHashSet<>( values.size() );

        for ( Value value : values )
        {
            if ( value.isSchemaAware() )
            {
                newValues.add( value );
            }
            else
            {
                if ( value.isHumanReadable() )
                {
                    newValues.add( new Value( attributeType, value.getString() ) );
                }
                else
                {
                    newValues.add( new Value( attributeType, value.getBytes() ) );
                }
            }
        }

        values = newValues;
    }

    isHR = attributeType.getSyntax().isHumanReadable();

    // Compute the hashCode
    rehash();
}
 
Example 15
Source File: Rdn.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Get the value of the Ava which type is given as an
 * argument.
 *
 * @param type the type of the NameArgument
 * @return the value to be returned, or null if none found.
 * @throws LdapInvalidDnException if the Rdn is invalid
 */
public Object getValue( String type ) throws LdapInvalidDnException
{
    // First, let's normalize the type
    String normalizedType = Strings.lowerCaseAscii( Strings.trim( type ) );

    if ( schemaManager != null )
    {
        AttributeType attributeType = schemaManager.getAttributeType( normalizedType );

        if ( attributeType != null )
        {
            normalizedType = attributeType.getOid();
        }
    }

    switch ( nbAvas )
    {
        case 0:
            return "";

        case 1:
            if ( ava.getNormType().equals( normalizedType ) )
            {
                if ( ava.getValue() != null )
                {
                    return ava.getValue().getString();
                }
                else
                {
                    return null;
                }
            }

            return "";

        default:
            List<Ava> avaList = avaTypes.get( normalizedType );
            
            if ( avaList != null )
            {
                for ( Ava elem : avaList )
                {
                    if ( elem.getNormType().equals( normalizedType ) )
                    {
                        if ( elem.getValue() != null )
                        {
                            return elem.getValue().getString();
                        }
                        else
                        {
                            return null;
                        }
                    }
                }

                return null;
            }

            return null;
    }
}