aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes what kind of object can be bound to JNDI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "what kind of object can be bound to JNDI?" Watch "what kind of object can be bound to JNDI?" New topic
Author

what kind of object can be bound to JNDI?

Sean Li
Ranch Hand

Joined: Feb 27, 2002
Posts: 154
any object? or must have to be serialized? or other condition?
Just cannot find any answer from specification. Can anybody help me?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Any object that you bind to JNDI should be serializable.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Is DataSource serializable?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Originally posted by Jeanne Boyarsky:
Is DataSource serializable?

DataSource is an interface so it doesn't have to be Serializable. A vendor's implementation of DataSource should certainly be...
Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
JNDI imposes no such restriction. One is free to bind any object, including non-serializable objects, although there is no guarantee that the JNDI provider will accept it.
-Ade Barkah


-Ade<br /><a href="http://www.barkah.org" target="_blank" rel="nofollow">www.barkah.org</a>
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Originally posted by Ade Barkah:
JNDI imposes no such restriction. One is free to bind any object, including non-serializable objects, although there is no guarantee that the JNDI provider will accept it.
-Ade Barkah

Sure, but since JNDI can be clustered and accessed remotely... it is foolish to bind objects that are not Serializable.
Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
Originally posted by Chris Mathews:

Sure, but since JNDI can be clustered and accessed remotely... it is foolish to bind objects that are not Serializable.

There are many reasons to bind non-serializable objects.
1) Even within clusters, non-serializable objects can still be bound to to the context, whether locally or globally (ie. copies of the object can be replicated across the cluster.) In any case, a service provider is free to provide an implementation to bind non-serializable objects within a remote, clustered environment.
2) Serializable is a Java concept, but naming and directory services go beyond Java. Contents within a particular naming service might have been populated by a C, Perl, or even Visual Basic code with no concept of Serializable (or even of objects.) To require Serializable would prevent JNDI from working with non-Java services.
3) There's an implication that objects in the server are stored in their Serializable forms. However, it's common to store a reference to the object instead. For example, instead of binding an image, one can bind the image's url (which might be a simple ASCII string.) For Java objects, JNDI supports this approach through the Referenceable interface. A Referenceable object may be bound even if it is non-serializable.
4) There is no guarantee that even Serializable objects can be bound... a JNDI service provider is free to refuse them. Providers may also create "read-only" JNDI services, not supporting binding of any type at all.
5) When working with LDAP, it is common to bind non-serializable DirContext objects, for interoperability with non-Java LDAP servers. Not all providers support binding DirContext objects, but most do.
6) Also, JNDI provides the StateFactory interface to bind arbitrary types. Using this interface one can write custom code to convert any object into a form suitable to the JNDI service provider.
Anyway, to answer the original question, the JNDI specification does not restrict the type of objects which can be bound, instead providing a variety of mechanisms to work with non-serializable objects. These mechanisms are necessary to preserve interoperability with non-Java services and to allow provider-specific enhancements.
-Ade Barkah
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what kind of object can be bound to JNDI?