| Summary | Orbix Java makes a remote _is_a() call to verify the type of derived objects during a narrow. This article details a way to avoid this for non-derived types. | 
|---|---|
| Article Number | 32392 | 
| Environment | Orbix Java 6.x All Supported Platforms OS: all | 
| Question/Problem Description | Is it possible to avoid a call to "_is_a()" on remote CORBA Object? There may be a use case where calls to such method cause problems in the construction of generic server gateways. | 
| Clarifying Information | |
| Error Message | |
| Defect/Enhancement Number | |
| Cause | |
| Resolution | When a request is received by an Orbix server, it reads the input and narrows to the expected type. As the input is an com.iona.corba.art.binding.ObjectImpl it invokes on the _is_a() operation on this object. The _is_a() delegates to the com.iona.corba.art.binding.IORProxy._is_a().This checks  to see if the type id contained in the CORBA proxy (IORProxy Object) matches the type id of the expected type. If it does not match then the IORProxy._is_a()  invokes _is_a() on the actual CORBA Object to identify if the CORBA object type is derived from the expected type. While this is the way it Orbix Java is designed, this behavior may be undesirable. In that case, there is a workaround that will work only on a limited number of cases. The workaround consists of changing the "read" method in the CORBA proxy class, to return directly an object of the specific type, rather than the generic type. | 
| Workaround | The following code illustrates the change that need to happen for the "SimpleObject", part of the "corba/standard/simple_persistent, as an example: Change the code inside "java_output/simple_persistent/simple/SimpleObjectHelper.java from: public static simple_persistent.Simple.SimpleObject read( org.omg.CORBA.portable.InputStream _stream ) { return (narrow(_stream.read_Object())); } to public static simple_persistent.Simple.SimpleObject read( org.omg.CORBA.portable.InputStream _stream ) { return (narrow(_stream.read_Object(simple_persistent.Simple._SimpleObjectStub.class))); } | 
| Notes | Note that this workaround can not apply to interfaces with multiple inheritance. This solution will work for simple IDL interfaces with no inheritance. However, if there was multiple inheritance, such change will cause other problems. For example, it will force design choices on a class at compile time, not run-time, which goes against the object polymorphism concept. As Orbix cannot know what the type of an Object is this is not a feature that will ever be added to the product and should only be used in extreme cases. | 
| Attachment | 
| Created date: | 06 June 2012 | 
|---|---|
| Last Modified: | 13 February 2013 | 
| Last Published: | 08 June 2012 | 
| First Published date: | 07 June 2012 | 
#Orbix
#KnowledgeDocs

