Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm new to Esri's Arc* interfaces, and trying to figure out how to register an existing table using the ArcObjects API. The following question answers this to some extent:

Is there any way to write a snipet of code with function of "SDELayer -o register" command

Maybe the IClassSchemaEdit.RegisterAsObjectClass method will help (see the GeoDatabase OMD). You should be able to QI it from an ITable, opened in the usual fashion (e.g. IFeatureWorkspace.OpenTable(in Name: String) since you've already built your GDB).

But there is some terminology used that I don't understand. Specifically, what does it mean to QI something, and how is it done?

This other question's answer defines QI, somewhat vaguely, as Query Interface (hopping) but goes no further.

How do you navigate the ArcObjects OMDS?

It really helps if you know UML. In the class that I had in college the professor called it QI (Query Interface) hopping. The Getting To Know ArcObjects book has a nice break down of how to work with the diagrams.

I'm using Java - is this a .net thing?

share|improve this question
    
I think it is an OOP thing. I cannot be certain, so do not take my words as facts, but as I understand it, when someone refers to QI hopping, they mean passing an object through the different interfaces that support it (such as with casting) to end up with an object type that can be used in a given method. That's my guess, anyway. –  Nathanus Jan 13 '12 at 19:50

2 Answers 2

up vote 5 down vote accepted

You can think of QueryInterface simply as a COM type-cast.

QI, or QueryInterface, is a term used by the Microsoft COM specification. The specification is a binary standard that is language agnostic (it can be implemented by various languages).

From Microsoft's documentation on COM:

The Microsoft Component Object Model (COM) is a platform-independent, distributed, object-oriented system for creating binary software components that can interact.

To understand COM (and therefore all COM-based technologies), it is crucial to understand that it is not an object-oriented language but a standard. Nor does COM specify how an application should be structured; language, structure, and implementation details are left to the application developer. Rather, COM specifies an object model and programming requirements that enable COM objects (also called COM components, or sometimes simply objects) to interact with other objects. These objects can be within a single process, in other processes, and can even be on remote computers. They can be written in different languages, and they may be structurally quite dissimilar, which is why COM is referred to as a binary standard; a standard that applies after a program has been translated to binary machine code.

In other words, as long as your compiler can produce binary objects that adhere to the COM binary standard, they can interact with each other, no matter what language they were originally written in. COM-compliant compilers exist for Java, C++, C#, VB.NET, and several other languages.

Anyway, you asked specifically what QueryInterface was. So at the root of all COM components, there is an interface called IUnknown, which has three methods: AddRef, QueryInterface and Release. When using most languages that do automatic garbage collection (such as languages based on the Java or .NET runtime), the developer does not need to interact with AddRef and Release – since the memory management is (most of the time) handled correctly by the proxies that get generated automatically by the language or IDE that is being used. I mentioned the proxies because this is relevant to you in Java.

So that leaves QueryInterface. QueryInterface is the method that is used to fetch another interface implemented by the same COM object.

QueryInterface has the following properties:

  1. The set of interfaces accessible on an object through QueryInterface must be static, not dynamic. This means that if a call to QueryInterface for a pointer to a specified interface succeeds the first time, it must succeed again, and if it fails the first time, it must fail on all subsequent queries.

  2. It must be reflexive – if a client holds a pointer to an interface on an object, and queries for that interface, the call must succeed.

  3. It must be symmetric – if a client holding a pointer to one interface queries successfully for another, a query through the obtained pointer for the first interface must succeed.

  4. It must be transitive – if a client holding a pointer to one interface queries successfully for a second, and through that pointer queries successfully for a third interface, a query for the first interface through the pointer for the third interface must succeed.

QueryInterface is the basic way that we navigate through all the objects that make up ArcObjects. You may also want to read the MS documentation that clarifies how to navigate COM Objects through QueryInterface.

If you look at the ESRI documentation, you will find that, for example, the FeatureClass co-class supports several COM interfaces. You can "hop" the different interfaces through QueryInterface.

In each language, the act of hopping interfaces or QI'ing, is done with different syntaxes, although semantically it is the same. For example, the C# and VB.NET compilers transform regular type-casts on a COM interface to the corresponding call to QueryInterface, e.g.:

IFeatureClass featureClass = someFeatureWorkspace.OpenFeatureClass(…);
IDataset dataset = (IDataset)featureClass;
                // ^^^^^^^^^^^^^^^^^^^^^^
                // the C# compiler turns this into a call to QueryInterface. 
share|improve this answer
    
This is an excellent write-up on the technicalities involved. –  Devdatta Tengshe Jan 15 '12 at 3:13

QI in simple words means to acess the same object via a different interface.

Suppose you have an ObjectClass object. In the COM world, you generally don't access it directly, but only Via interfaces. Hence you can access it from ITable, IClassSchemaEdit and many other interfaces.

When you call IFeatureWorkspace.OpenTable, It returns an ITable, and hence you will be accesing the ObjectClass object, via the ITable interface. Now if you want to register it with the geodatbase, you'll have to call IClassSchemaEdit.RegisterAsObjectClass.

But how do you go from ITable to IClassSchemaEdit? You just Query interface as shown in the following C# example:

//FeatWorkspace is of the type IFeatureWorkspace
ITable unRegisteredTable= FeatWorkspace.OpenTable ("TableName"); 
//Now you have the reference via an ITable.

IClassSchemaEdit unRegClassSchemaEdit=(IClassSchemaEdit)unRegisteredTable; //This is QI
share|improve this answer
    
Ideally, you would get a schema lock before you register it as version, but I am mentioning it here, since it's an aside from you question about QI –  Devdatta Tengshe Jan 14 '12 at 5:10
1  
Thanks, Devdatta, this helps a bunch too. It looks like the java equivalent is probably new IClassSchemaEditProxy(table). –  Chris Jan 16 '12 at 20:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.