Apply class extensions


In this topic


About applying class extensions

After developing class extensions, they are deployed to the ArcGIS application (ArcGIS Engine, ArcGIS Server, ArcMap, or ArcCatalog) that accesses the data, by placing the class extension Java Archive (JAR) file in <ArcGIS Install Dir>\java\lib\ext.
The ArcGIS application recognizes the class extension when started by its @ArcGISExtension annotation. After deployment, the class extension can be applied programmatically using ArcObjects application programming interfaces (APIs) to one or more object or feature classes in the geodatabase.
The following illustration shows two essential steps for implementing custom data behavior (deploy and apply) that follows the development of class extensions:
Deploy the class extension JAR file to every ArcGIS application machine that accesses the table or feature class to which the class extension is applied.

Apply class extensions to object or feature classes

A class extension can be applied to more than one object or feature class. However, an object or feature class can have at least one class extension. There are different ways to apply an extension to a class, depending on whether the class exists.
 
Do the following to apply an extension to a class that does not exist:
  • Pass the class extension's unique identifier (UID) as the EXTCLSID parameter of the IFeatureWorkspace.createTable() and createFeatureClass() methods. The UID value of the class extension is the fully qualified Java class name of the class extension.
 
Do the following to apply an extension to a class that does exist:
  • Class extensions can be applied through the IClassSchemaEdit.alterClassExtensionCLSID() and IFeatureWorkspaceSchemaEdit.alterClassExtensionCLSID() methods. When using the alterClassExtensionCLSID methods to apply class extensions, acquire an exclusive schema lock using the ISchemaLock interface to ensure that another application or user does not access the object or feature class. The methods can also be used to remove a class extension by providing null values as both parameters.
 
Invoking the IClassSchemaEdit.alterClassExtensionCLSID() method should instantiate the provided class extension. If it does not instantiate it, the method fails; therefore, you must deploy the class extension on your ArcGIS application machine that invokes alterClassExtensionCLSID().
 
If your class extension failed, is flawed, or not deployed, the ArcGIS application will not access the corresponding object or feature class. In this case, if you want to remove the class extension applied to the object or feature class, use IFeatureWorkspaceSchemaEdit.alterClassExtensionCLSID() to alter the class extension's class identifier (CLSID).
 
The following code example shows how to alter the class extension of an object class:
 
[Java]
//Add the class extension JAR file to the compile path.
//Import the class extension package.
import arcgissample.classextension.relatedevents.*;

//...

public void changeClassExtension(IObjectClass objectClass, IPropertySet
    extensionProperties)throws IOException{
    ISchemaLock schemaLock = (ISchemaLock)objectClass;
    try{
        // Attempt to get an exclusive schema lock.
        schemaLock.changeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
        // Cast the object class to the IClassSchemaEdit2 interface.
        IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)objectClass;
        // Create a unique identifier. 
        (UID)object UID extUID = new UID();
        //Fully qualified Java class name of the extension is passed as the parameter.
        extUID.setValue(TransformerExtension.class.getName());
        //Alter the class extension.
        classSchemaEdit.alterClassExtensionCLSID(extUID, extensionProperties);
    }
    catch (IOException e){
        e.printStackTrace();
    }
    finally{
        //Release the lock.
        schemaLock.changeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
    }
}

//...