18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

JAVA APPLICATION PROGRAMMING INTERFACE<br />

ArcObjects Struct<br />

enum esri3DAxis<br />

esriXAxis = 0<br />

esriYAxis = 1<br />

esriZAxis = 2<br />

}<br />

Java Representation<br />

public interface esri3DAxis {<br />

public static final int esriXAxis = 0;<br />

public static final int esriYAxis = 1;<br />

public static final int esriZAxis = 2;<br />

}<br />

You can now refer to the esriXAxis constant using the following notation:<br />

esri3DAxis.esriXAxis;<br />

Variants<br />

The variant data type can contain a wide array of subtypes. With variants all<br />

types can be contained within a single type variant. Everything in the Java programming<br />

language is an object. Even primitive data types can be encapsulated<br />

inside objects if required. Every class in Java extends java.lang.Object; consequently,<br />

methods in ArcObjects that take variants as parameters can be passed any<br />

object type in the <strong>ArcGIS</strong> API for Java.<br />

Calling methods with “variant” objects as parameters<br />

For methods that take variants as parameters, any object types can be passed, as<br />

all objects derive from java.lang.Object. As this is considered a “widening cast,” an<br />

explicit cast to Object is not needed. If you want to pass primitives as parameters<br />

to methods, when variants are required, the corresponding primitive wrapper<br />

class can be used.<br />

Using methods that return variants<br />

When using variant objects returned by methods, explicitly “downcast” those<br />

objects to the corresponding wrapper object. For example, if expecting a String,<br />

downcast to java.lang.String; if expecting a short, downcast to short’s wrapper<br />

class, that is, java.lang.Short, as shown in the code below.<br />

ICursor spCursor = spTable.ITable_search(spQueryFilter, false);<br />

/* Iterate over the rows. */<br />

IRow spRow = spCursor.nextRow();<br />

while (spRow != null) {<br />

Short ID = (Short) (spRow.getValue(1));<br />

String name = (String) (spRow.getValue(2));<br />

Short baseID = (Short) (spRow.getValue(3));<br />

188 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong><br />

System.out.println("ID="+ ID +"\t name="+ name +"\tbaseID="+ baseID);<br />

/* Move to the next row. */<br />

spRow = spCursor.nextRow();<br />

}<br />

IRowBuffer is a superinterface of IRow and defines the getValue(int) method as:<br />

public Object getValue(int index)<br />

throws IOException,<br />

AutomationException<br />

The value of the field with the specified index.<br />

Parameters:<br />

index - The index (in)<br />

Returns:<br />

return value. A Variant

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!