Java Code Examples for org.apache.directory.api.ldap.model.name.Dn#size()
The following examples show how to use
org.apache.directory.api.ldap.model.name.Dn#size() .
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: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException { Dn base = searchContext.getDn(); // TODO since we're handling the *, and + in the EntryFilteringCursor // we may not need this code: we need see if this is actually the // case and remove this code. if ( base.size() == 0 ) { return searchFromRoot( searchContext ); } // Not sure we need this code... base.apply( schemaManager ); // Normal case : do a search on the specific partition Partition backend = getPartition( base ); return backend.search( searchContext ); }
Example 2
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException { Dn base = searchContext.getDn(); // TODO since we're handling the *, and + in the EntryFilteringCursor // we may not need this code: we need see if this is actually the // case and remove this code. if ( base.size() == 0 ) { return searchFromRoot( searchContext ); } // Not sure we need this code... base.apply( schemaManager ); // Normal case : do a search on the specific partition Partition backend = getPartition( base ); return backend.search( searchContext ); }
Example 3
Source File: LdifRevertor.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Compute a reverse LDIF for a forward change which if in LDIF format * would represent a Move operation. Hence there is no newRdn in the * picture here. * * @param newSuperiorDn the new parent dn to be (must not be null) * @param modifiedDn the dn of the entry being moved (must not be null) * @return a reverse LDIF * @throws LdapException if something went wrong */ public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifiedDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) ); } if ( modifiedDn.size() == 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) ); } currentParent = modifiedDn; currentRdn = currentParent.getRdn(); currentParent = currentParent.getParent(); newDn = newSuperiorDn; newDn = newDn.add( modifiedDn.getRdn() ); entry.setChangeType( ChangeType.ModDn ); entry.setDn( newDn ); entry.setNewRdn( currentRdn.getName() ); entry.setNewSuperior( currentParent.getName() ); entry.setDeleteOldRdn( false ); return entry; }
Example 4
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * @return True if one of the node below the current node has one element, * False otherwise * @param dn The Dn we want to get the element for */ public synchronized boolean hasDescendantElement( Dn dn ) { DnNode<N> node = getNode( dn ); if ( node == null ) { return false; } // We must be at the right place in the tree if ( node.getDn().size() != dn.size() ) { return false; } if ( node.hasChildren() ) { for ( DnNode<N> child : node.getChildren().values() ) { if ( hasDescendantElement( child ) ) { return true; } } } return false; }
Example 5
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * @return True if one of the node below the current node has one element, * False otherwise * @param dn The Dn we want to get the element for */ public synchronized List<N> getDescendantElements( Dn dn ) { List<N> descendants = new ArrayList<>(); DnNode<N> node = getNode( dn ); if ( node == null ) { return descendants; } // We must be at the right place in the tree if ( node.getDn().size() != dn.size() ) { return descendants; } if ( node.hasChildren() ) { for ( DnNode<N> child : node.getChildren().values() ) { getDescendantElements( child, descendants ); } } return descendants; }
Example 6
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Removes a node from the tree. * * @param dn the node's Dn * @throws LdapException if the Dn is null or empty */ public synchronized void remove( Dn dn ) throws LdapException { checkDn( dn ); // Find the parent first : we won't be able to remove // a node if it's not present in the tree ! DnNode<N> parentNode = getNode( dn ); if ( parentNode == null ) { return; } // Now, check that this parent has the same Dn than the one // we gave and that there is no children if ( ( dn.size() != parentNode.depth ) || parentNode.hasChildren() ) { return; } // Ok, no children, same Dn, let's remove what we can. parentNode = parentNode.getParent(); for ( Rdn rdn : dn.getRdns() ) { parentNode.children.remove( rdn.getNormName() ); if ( parentNode.children.size() > 0 ) { // We have to stop here, because the parent's node is shared with other Node. break; } parentNode = parentNode.getParent(); } }
Example 7
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Get the Node for a given Dn, if present in the tree.<br> * For instance, if we have stored dc=acme, dc=org into the tree, * the Dn: ou=example, dc=acme, dc=org will have a parent, and * dc=acme, dc=org will be returned. * <br>For the Dn ou=apache, dc=org, there is no parent, so null will be returned. * * @param dn the normalized distinguished name to resolve to a parent * @return the Node associated with the normalized dn */ public synchronized DnNode<N> getNode( Dn dn ) { DnNode<N> currentNode = this; DnNode<N> parentNode = null; // Iterate through all the Rdn until we find the associated partition for ( int i = dn.size() - 1; i >= 0; i-- ) { Rdn rdn = dn.getRdn( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() ); if ( currentNode == null ) { break; } parentNode = currentNode; } else { break; } } return parentNode; }
Example 8
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
private String getSchemaName( Dn dn ) throws LdapException { int size = dn.size(); if ( size < 2 ) { throw new LdapException( I18n.err( I18n.ERR_276 ) ); } Rdn rdn = dn.getRdn( size - 2 ); return rdn.getNormValue().getString(); }
Example 9
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
private String getSchemaName( Dn dn ) throws LdapException { int size = dn.size(); if ( size < 2 ) { throw new LdapException( I18n.err( I18n.ERR_276 ) ); } Rdn rdn = dn.getRdn( size - 2 ); return rdn.getNormValue().getString(); }
Example 10
Source File: LdifAnonymizer.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Anonymize the entry's DN * * @param entryDn The DN to anonymize * @return The anonymized DN * @throws LdapException If the anonymization failed */ private Dn anonymizeDn( Dn entryDn ) throws LdapException { // Search for the naming context Dn descendant = entryDn; Dn namingContext = null; for ( Dn nc : namingContexts ) { if ( entryDn.isDescendantOf( nc ) ) { descendant = entryDn.getDescendantOf( nc ); namingContext = nc; break; } } Rdn[] anonymizedRdns = new Rdn[entryDn.size()]; int rdnPos = entryDn.size() - 1; if ( namingContext != null ) { // Copy the naming contex for ( Rdn ncRdn : namingContext ) { anonymizedRdns[rdnPos] = ncRdn; rdnPos--; } } // Iterate on all the RDN for ( Rdn rdn : descendant ) { Ava[] anonymizedAvas = new Ava[rdn.size()]; int pos = 0; // Iterate on the AVAs for ( Ava ava : rdn ) { Ava anonymizedAva = anonymizeAva( ava ); anonymizedAvas[pos] = anonymizedAva; pos++; } Rdn anonymizedRdn = new Rdn( schemaManager, anonymizedAvas ); anonymizedRdns[rdnPos] = anonymizedRdn; rdnPos--; } return new Dn( schemaManager, anonymizedRdns ); }
Example 11
Source File: DnNode.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * move the DnNode's Dn * * @param newParent the new parent Dn * @throws LdapException If the move failed */ public synchronized void move( Dn newParent ) throws LdapException { DnNode<N> tmp = null; Dn tmpDn = null; // check if the new parent Dn is child of the parent if ( newParent.isDescendantOf( parent.nodeDn ) ) { tmp = parent; tmpDn = parent.nodeDn; } // if yes, then drill for the new parent node if ( tmpDn != null ) { int parentNodeSize = tmpDn.size(); int count = newParent.size() - parentNodeSize; while ( count-- > 0 ) { tmp = tmp.getChild( newParent.getRdn( parentNodeSize++ ) ); } } // if not, we have to traverse all the way up to the // root node and then find the new parent node if ( tmp == null ) { tmp = this; while ( tmp.parent != null ) { tmp = tmp.parent; } tmp = tmp.getNode( newParent ); } nodeDn = newParent.add( nodeRdn ); updateAfterModDn( nodeDn ); if ( parent != null ) { parent.children.remove( nodeRdn.getNormName() ); } parent = tmp; parent.children.put( nodeRdn.getNormName(), this ); }