You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Ole Ersoy <ol...@gmail.com> on 2007/06/11 18:40:10 UTC

[JNDI] Getting the Directory Context From a Binding?

Hey Guys,

I'm trying to obtain a context from a binding.  I first create a L0 context, and then an L1 context that's a sub context of the L0 context.  I'm wondering whether the asserts below should pass (They do pass)?

NamingEnumeration<Binding> childEntryContexts = directoryContextL0.listBindings("");
assertTrue( childEntryContexts.hasMore() );
Binding binding = ( Binding ) childEntryContexts.next();
assertEquals( "cn=L1,cn=L0,ou=test", binding.getName() );
assertNull( binding.getObject() );

JGuru says this:

listBindings() attempts to return an enumeration of the Binding's of all of the objects in the current context. I.e., it's a listing of all of the objects in the current context with the object's name, its class name, and a reference to the object itself.


It seems like the reference to the L1 object (Context) is missing in this case, although we can see that it's there because binding returns its name.  Thoughts?

Thanks,
- Ole



Re: [JNDI] Getting the Directory Context From a Binding?

Posted by Ole Ersoy <ol...@gmail.com>.
Hi Stefan,

Super!  I thought they were a little magical :-)  I'll start getting cozy with search.  In this case I just wanted to get the Attributes of each entry, so that I can get the name of the entry, so that I can delete it.  BTW - I started reworking the ADS Testing Archetype.  Do you have any needs for a testing archetype in LS?  I know the DAS needs a separate one, because it has 10 or so different setups for tests to use, and I thought LS might have similar needs.  If you would like one, just let me know and I can work on them in parallel.

Thanks again,
- Ole



Stefan Seelmann wrote:
> Hi,
> 
> in Studio we don't use the
>  Context.list()
>  Context.listBindings()
>  Context.lookup()
>  Context.bind()
> methods. The reason is that JNDI performs magic LDAP request when using 
> this methods. JNDI tries to find out if the object in LDAP is a Java 
> object.
> 
> Instead we just use the
>  search(String name, String filter, SearchControls cons)
> method because it gives full control which LDAP request is performed 
> against the server. With the SearchControls you can exactly specify the 
> search scope (object, one level, subtree), the returned attributes, the 
> count and time limits. However with that method you just get the 
> SearchResult objects containing the LDAP attributes, there is no 
> LDAP->Object mapping when using this method.
> 
> You could take a look to the JNDIConnectionContext class, it does all 
> the I/O to the directory.
> http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIConnectionContext.java?view=markup 
> 
> (It is not documented yet and we are on the way to refactor the 
> connection part of the Studio)
> 
> Hope that help,
> StefanS
> 
> 
> Ole Ersoy wrote:
> 
>> OK Cool - I can always hunt through the LS code base and see how it's 
>> done there.  At least I know someone is doing it :-)
>>
>> Cheers,
>> - Ole
>>
>>
>>
>>
>>
> 

Re: [JNDI] Getting the Directory Context From a Binding?

Posted by Stefan Seelmann <ma...@stefan-seelmann.de>.
Hi,

in Studio we don't use the
  Context.list()
  Context.listBindings()
  Context.lookup()
  Context.bind()
methods. The reason is that JNDI performs magic LDAP request when using 
this methods. JNDI tries to find out if the object in LDAP is a Java object.

Instead we just use the
  search(String name, String filter, SearchControls cons)
method because it gives full control which LDAP request is performed 
against the server. With the SearchControls you can exactly specify the 
search scope (object, one level, subtree), the returned attributes, the 
count and time limits. However with that method you just get the 
SearchResult objects containing the LDAP attributes, there is no 
LDAP->Object mapping when using this method.

You could take a look to the JNDIConnectionContext class, it does all 
the I/O to the directory.
http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/JNDIConnectionContext.java?view=markup
(It is not documented yet and we are on the way to refactor the 
connection part of the Studio)

Hope that help,
StefanS


Ole Ersoy wrote:

> OK Cool - I can always hunt through the LS code base and see how it's 
> done there.  At least I know someone is doing it :-)
>
> Cheers,
> - Ole
>
>
>
>
>

Re: [JNDI] Getting the Directory Context From a Binding?

Posted by Ole Ersoy <ol...@gmail.com>.
OK Cool - I can always hunt through the LS code base and see how it's done there.  At least I know someone is doing it :-)

Cheers,
- Ole





Alex Karasulu wrote:
> Guys I'm sorry trying to respond but a bit overloaded let me try to get
> back to this later.
> 
> Alex
> 
> On 6/11/07, *Ole Ersoy* < ole.ersoy@gmail.com 
> <ma...@gmail.com>> wrote:
> 
>     Just adding a little bit more of a scenario into the mix.  The
>     scenario is that I'll create a context L0, and it will have several
>     children that are directory entries, like L1A, L1B, L1C
>     etc.  Earlier Stefan gave me this code for iterating through the
>     children of a context and getting the context associated with each
>     child:
> 
>     NamingEnumeration enm = ctx.listBindings("");
>     while (enm.hasMore()) {
>     Binding b = (Binding) enm.next();
>     if (b.getObject() instanceof Context) {
>        Context child = (Context) b.getObject();
>     }
>     }
> 
>     So ctx in this case is the L0 context.  So at this point I am unable
>     to get the child contexts associated with the bindings that
>     represent the children of the L0 context.  I can look them up using
>     lookup() which will return a directory context instance.
> 
>     Anyone know of any other way to get a list of the child contexts?
> 
>     Thanks,
>     - Ole
> 
> 
> 
>     Emmanuel Lecharny wrote:
>      > Well, it's not really clear, but I think that a Binding, in a LDAP
>      > context, is just an Attributes, not a Context.
>      >
>      > It's a little bit different than a directory and a file. A LDAP entry
>      > is an entry and can be the father of others entries. This duality
>     does
>      > not exactly applies to other kind of directories...
>      >
>      > Alex, thougths ?
>      >
>      > On 6/11/07, Ole Ersoy <ole.ersoy@gmail.com
>     <ma...@gmail.com>> wrote:
>      >> Hey Guys,
>      >>
>      >> I'm trying to obtain a context from a binding.  I first create a L0
>      >> context, and then an L1 context that's a sub context of the L0
>      >> context.  I'm wondering whether the asserts below should pass
>     (They do
>      >> pass)?
>      >>
>      >> NamingEnumeration<Binding> childEntryContexts =
>      >> directoryContextL0.listBindings("");
>      >> assertTrue( childEntryContexts.hasMore() );
>      >> Binding binding = ( Binding ) childEntryContexts.next();
>      >> assertEquals( "cn=L1,cn=L0,ou=test", binding.getName() );
>      >> assertNull( binding.getObject() );
>      >>
>      >> JGuru says this:
>      >>
>      >> listBindings() attempts to return an enumeration of the Binding's of
>      >> all of the objects in the current context. I.e., it's a listing
>     of all
>      >> of the objects in the current context with the object's name, its
>      >> class name, and a reference to the object itself.
>      >>
>      >>
>      >> It seems like the reference to the L1 object (Context) is
>     missing in
>      >> this case, although we can see that it's there because binding
>     returns
>      >> its name.  Thoughts?
>      >>
>      >> Thanks,
>      >> - Ole
>      >>
>      >>
>      >>
>      >
>      >
> 
> 

Re: [JNDI] Getting the Directory Context From a Binding?

Posted by Alex Karasulu <ak...@apache.org>.
Guys I'm sorry trying to respond but a bit overloaded let me try to get
back to this later.

Alex

On 6/11/07, Ole Ersoy <ol...@gmail.com> wrote:
>
> Just adding a little bit more of a scenario into the mix.  The scenario is
> that I'll create a context L0, and it will have several children that are
> directory entries, like L1A, L1B, L1C etc.  Earlier Stefan gave me this code
> for iterating through the children of a context and getting the context
> associated with each child:
>
> NamingEnumeration enm = ctx.listBindings("");
> while (enm.hasMore()) {
> Binding b = (Binding) enm.next();
> if (b.getObject() instanceof Context) {
>    Context child = (Context) b.getObject();
> }
> }
>
> So ctx in this case is the L0 context.  So at this point I am unable to
> get the child contexts associated with the bindings that represent the
> children of the L0 context.  I can look them up using lookup() which will
> return a directory context instance.
>
> Anyone know of any other way to get a list of the child contexts?
>
> Thanks,
> - Ole
>
>
>
> Emmanuel Lecharny wrote:
> > Well, it's not really clear, but I think that a Binding, in a LDAP
> > context, is just an Attributes, not a Context.
> >
> > It's a little bit different than a directory and a file. A LDAP entry
> > is an entry and can be the father of others entries. This duality does
> > not exactly applies to other kind of directories...
> >
> > Alex, thougths ?
> >
> > On 6/11/07, Ole Ersoy <ol...@gmail.com> wrote:
> >> Hey Guys,
> >>
> >> I'm trying to obtain a context from a binding.  I first create a L0
> >> context, and then an L1 context that's a sub context of the L0
> >> context.  I'm wondering whether the asserts below should pass (They do
> >> pass)?
> >>
> >> NamingEnumeration<Binding> childEntryContexts =
> >> directoryContextL0.listBindings("");
> >> assertTrue( childEntryContexts.hasMore() );
> >> Binding binding = ( Binding ) childEntryContexts.next();
> >> assertEquals( "cn=L1,cn=L0,ou=test", binding.getName() );
> >> assertNull( binding.getObject() );
> >>
> >> JGuru says this:
> >>
> >> listBindings() attempts to return an enumeration of the Binding's of
> >> all of the objects in the current context. I.e., it's a listing of all
> >> of the objects in the current context with the object's name, its
> >> class name, and a reference to the object itself.
> >>
> >>
> >> It seems like the reference to the L1 object (Context) is missing in
> >> this case, although we can see that it's there because binding returns
> >> its name.  Thoughts?
> >>
> >> Thanks,
> >> - Ole
> >>
> >>
> >>
> >
> >
>
>

Re: [JNDI] Getting the Directory Context From a Binding?

Posted by Ole Ersoy <ol...@gmail.com>.
Just adding a little bit more of a scenario into the mix.  The scenario is that I'll create a context L0, and it will have several children that are directory entries, like L1A, L1B, L1C etc.  Earlier Stefan gave me this code for iterating through the children of a context and getting the context associated with each child:

NamingEnumeration enm = ctx.listBindings("");
while (enm.hasMore()) {
 Binding b = (Binding) enm.next();
 if (b.getObject() instanceof Context) {
   Context child = (Context) b.getObject();
 }
} 

So ctx in this case is the L0 context.  So at this point I am unable to get the child contexts associated with the bindings that represent the children of the L0 context.  I can look them up using lookup() which will return a directory context instance.

Anyone know of any other way to get a list of the child contexts?

Thanks,
- Ole



Emmanuel Lecharny wrote:
> Well, it's not really clear, but I think that a Binding, in a LDAP
> context, is just an Attributes, not a Context.
> 
> It's a little bit different than a directory and a file. A LDAP entry
> is an entry and can be the father of others entries. This duality does
> not exactly applies to other kind of directories...
> 
> Alex, thougths ?
> 
> On 6/11/07, Ole Ersoy <ol...@gmail.com> wrote:
>> Hey Guys,
>>
>> I'm trying to obtain a context from a binding.  I first create a L0 
>> context, and then an L1 context that's a sub context of the L0 
>> context.  I'm wondering whether the asserts below should pass (They do 
>> pass)?
>>
>> NamingEnumeration<Binding> childEntryContexts = 
>> directoryContextL0.listBindings("");
>> assertTrue( childEntryContexts.hasMore() );
>> Binding binding = ( Binding ) childEntryContexts.next();
>> assertEquals( "cn=L1,cn=L0,ou=test", binding.getName() );
>> assertNull( binding.getObject() );
>>
>> JGuru says this:
>>
>> listBindings() attempts to return an enumeration of the Binding's of 
>> all of the objects in the current context. I.e., it's a listing of all 
>> of the objects in the current context with the object's name, its 
>> class name, and a reference to the object itself.
>>
>>
>> It seems like the reference to the L1 object (Context) is missing in 
>> this case, although we can see that it's there because binding returns 
>> its name.  Thoughts?
>>
>> Thanks,
>> - Ole
>>
>>
>>
> 
> 


Re: [JNDI] Getting the Directory Context From a Binding?

Posted by Emmanuel Lecharny <el...@gmail.com>.
Well, it's not really clear, but I think that a Binding, in a LDAP
context, is just an Attributes, not a Context.

It's a little bit different than a directory and a file. A LDAP entry
is an entry and can be the father of others entries. This duality does
not exactly applies to other kind of directories...

Alex, thougths ?

On 6/11/07, Ole Ersoy <ol...@gmail.com> wrote:
> Hey Guys,
>
> I'm trying to obtain a context from a binding.  I first create a L0 context, and then an L1 context that's a sub context of the L0 context.  I'm wondering whether the asserts below should pass (They do pass)?
>
> NamingEnumeration<Binding> childEntryContexts = directoryContextL0.listBindings("");
> assertTrue( childEntryContexts.hasMore() );
> Binding binding = ( Binding ) childEntryContexts.next();
> assertEquals( "cn=L1,cn=L0,ou=test", binding.getName() );
> assertNull( binding.getObject() );
>
> JGuru says this:
>
> listBindings() attempts to return an enumeration of the Binding's of all of the objects in the current context. I.e., it's a listing of all of the objects in the current context with the object's name, its class name, and a reference to the object itself.
>
>
> It seems like the reference to the L1 object (Context) is missing in this case, although we can see that it's there because binding returns its name.  Thoughts?
>
> Thanks,
> - Ole
>
>
>


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com