For Programmers: Free Programming Magazines  


Home > Archive > Java Help > September 2004 > JNDI, DirContext.OBJECT_FACTORIES, and subclasses









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author JNDI, DirContext.OBJECT_FACTORIES, and subclasses
Steve Nakhla

2004-09-27, 4:02 pm

I'm trying to learn more about JNDI and LDAP by writing a simple
little program to create users in an LDAP directory. However, I'd
ideally like to be able to create users and subclasses of users using
DirObjectFactory objects.

For example, in OpenLDAP I can create a "person", or a "inetOrgPerson"
which is a subclass of "person". I've created 2 objects: Person,
which implements DirContext; and, InetOrgPerson which extends Person.
My problem comes when trying to do a lookup on the objects I've just
created. I've noticed if I put the InetOrgPersonFactory first in
Context.OBJECT_FACTORIES, it is able to read an InetOrgPerson object
with no problem. But, if I put PersonFactory first the cast fails.
Obviously, it is because it is using the PersonFactory to create the
object instead of the InetOrgPersonFactory.

My question is, what is the best way to handle these object factories
so that subclasses are created by the appropriate factory, and not by
the super class's factory? Is there a good strategy to use? Any
thoughts?

Steve
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com