Hi Ivan,

 

I’ve double-checked the javadoc for javax.naming.spi.ObjectFactory, and I 
believe that the JNDI Services Specification is correct in requiring that any 
exceptions thrown by an ObjectFactory should be returned to the caller.  

 

The javadoc for ObjectFactory, found at:

 

http://download.oracle.com/javase/6/docs/api/javax/naming/spi/ObjectFactory.html

 

mentions that an ObjectFactory’s getObjectInstance() method must return null if 
the factory cannot resolve the object.  An Exception thrown from an 
ObjectFactory indicates that an error occurred while trying to create an object 
based on the object information, and that no other factories are to be tried.  
It is up to the ObjectFactory implementation to handle the fact that the first 
argument in getObjectInstance() may or may not be of type 
javax.naming.Reference.  

 

Hope this helps…

 

Bob

 

 

From: Ivan Dubrov [mailto:[email protected]] 
Sent: Thursday, September 16, 2010 12:41 AM
To: OSGi Developer Mail List
Subject: [osgi-dev] JNDI Services Specification, faulty (?) object factories

 

Hi,

I have a question about the correct behaviour of the JNDI Services 
Specification implementation.


Sometimes JNDI provider calls getObjectInstance providing "resolved" object 
(not a reference, javax.naming.Reference), for example instance of JMS 
javax.jms.ConnectionFactory. According to the 126.4/6 [1], my implementation of 
JNDIProviderAdmin tries to convert object with all possible factories. The 
problem is that most JBoss factories expect object passed to be 
javax.naming.Reference, so ClassCastException is thrown. According to the 
specification (see the end of the 126.4 [2]), the exception must be propagated 
to the caller, breaking the JNDI resolution rules.

The question is how to behave correctly in that case? Should I ignore exception 
in my JNDI Services implementation? Should I consult factories only if object 
is reference?

As a workaround, I have implemented property "<someprefix>.refOnly" that means 
factory should be consulted only if object passed is a javax.naming.Reference, 
which works, but I'm afraid I have missed something in the spec.


[1] Snippet from the OSGi Service Platform Release 4, Enterprise Specification 
4.2, section 126.4/6:

>If the description was a Reference and without a factory class name specified, 
>or if the description was not of type Reference, then attempt to convert the 
>object with each Object Factory service (or Dir Object Factory service for 
>directories) service in ranking order until a non-null value is returned.

[2] Exceptions handling:

>If an Exception occurs during the use of an Object Factory Builder service 
>then this exception should be logged but must be ignored. If, however, an 
>Exception occurs during the calling of a found ObjectFactory or 
>DirObjecFactory object then this Exception must be re-thrown to the caller of 
>the JNDI Provider Admin service.





-- 
WBR,
Ivan S. Dubrov
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to