Implementing the IObjectClassValidation Class Extension Interface

Created:11/8/1999
Last Modified:03/24/2003
Description:

Implementing a class extension is an ideal way to extend the default geodatabase behavior. By implementing the IObjectClassValidation interface you can extend the validation rules that are assigned to a spatial or non-spatial table. This example demonstrates how to create a custom validation rule to make sure that pipes connected to each other are of the same diameter. This sample will use three feature classes all of which are part of the same geometric network. In this sample we will be validating the relationship between several features in the geodatabase. Specifically, we will verify that the diameter attribute of a Lateral and Main are the same when connected by a junction feature.

How to use:
  1. Open and view the database design using Visio Enterprise (validation.vsd) or Adobe Acrobat (validation.pdf).
  2. View the source code to see how the class extension was implemented. There are three alternative implementations: Visual Basic 6, C# .NET and Visual Basic .NET.
  3. Before running the Visual Basic 6 implementation, first execute the batch file called '_INSTALL.bat' - this will register the dll and register the class extension to the appropriate component category.
  4. Before running the C# .NET or Visual Basic .NET implementations, first build the provided solution (requires the .NET Framework).
  5. Before running the C# .NET or Visual Basic .NET implementations, you will need to apply the class extension to the Main and Lateral feature classes. In the sample geodatabase, these two feature classes have already been configured with the Visual Basic 6 implementation. Execute '_INSTALL.bat' from the Visual Basic 6 solution so that the class extensions can be changed. Paste the VBA code below into the ArcCatalog VBA environment. Using ArcCatalog, select the 'data' feature dataset from the provided 'data' personal geodatabase, then run either the 'ValidationSampleCSharp' macro or the 'ValidationSampleVBNet' macro.
  6. In Arcmap open the 'data' personal geodatabase and add all of the feature classes.
  7. In Arcmap, start editing, select a few features, and using the editor pulldown menu on the editor toolbar choose validate features.
  8. Notice how some features were not valid. Use the property inspector to view the properties of the invalid features. Validating just one feature will give the reason for validation failure.
' Use this VBA code to set the class extensions on the Lateral and Main feature classes.
' For the VB6 implementation this has already been done for you in the sample geodatabase.
Public Sub ValidationSampleCSharp()
  Call SetClassExtensions("{3b08f710-4b96-4314-b674-b8f5242c6890}")
End Sub

Public Sub ValidationSampleVBNet()
  Call SetClassExtensions("{1EA56444-8AF8-4F64-857D-31C38F31273E}")
End Sub

Public Sub ValidationSampleVB6()
  Call SetClassExtensions("{9EB0D64B-5A7A-11D3-B858-0080C7A90270}")
End Sub

Public Sub ValidationSampleClear()
  Call SetClassExtensions("")
End Sub

Private Sub SetClassExtensions(sGUID As String)
  
  Dim pUID As IUID
  If Len(sGUID) > 0 Then
    Set pUID = New esriCore.UID
    pUID.Value = sGUID
  End If
    
  Dim pGxApp As IGxApplication
  Set pGxApp = Application
  
  Dim pGxObject As IGxObject
  Set pGxObject = pGxApp.SelectedObject
  
  If Not (TypeOf pGxObject Is IGxDataset) Then
    MsgBox "Select the feature dataset of the sample data"
    Exit Sub
  End If
    
  Dim pGxDataset As IGxDataset
  Set pGxDataset = pGxObject ' QI
  
  If Not (TypeOf pGxDataset.Dataset Is IFeatureDataset) Then
    MsgBox "Select the feature dataset of the sample data"
    Exit Sub
  End If
  
  Dim pFeatDataset As IFeatureDataset
  Set pFeatDataset = pGxDataset.Dataset
  Dim pFeatWorkspace As IFeatureWorkspace
  Set pFeatWorkspace = pFeatDataset.Workspace
  
  Dim pFeatClass1 As IFeatureClass
  Dim pFeatClass2 As IFeatureClass
  Set pFeatClass1 = pFeatWorkspace.OpenFeatureClass("Main")
  Set pFeatClass2 = pFeatWorkspace.OpenFeatureClass("Lateral")

  Call ApplyClassExtension(pUID, pFeatClass1)
  Call ApplyClassExtension(pUID, pFeatClass2)
  
  MsgBox "Class extensions successfully altered"
End Sub

Private Sub ApplyClassExtension(pUID As IUID, pClass As IClass)
  Dim pClassSchemaEdit As IClassSchemaEdit
  Set pClassSchemaEdit = pClass
  Dim pSchemaLock As ISchemaLock
  Set pSchemaLock = pClassSchemaEdit
  pSchemaLock.ChangeSchemaLock esriExclusiveSchemaLock
  pClassSchemaEdit.AlterClassExtensionCLSID pUID, Nothing
  pSchemaLock.ChangeSchemaLock esriSharedSchemaLock
End Sub
Application: ArcMap

Difficulty: Intermediate


Visual Basic C# Visual Basic.NET
File Description
CObjectClassValidation.cls Class file.
databaseSamples.vbp Visual Basic project that implements this sample.
_INSTALL.bat Installation script that installs dll.
validation.vsd Visio Enterprise UML Database design.
validation.pdf Adobe Acrobat version of UML Database design.
data.mdb Sample geodatabase dataset.


Key Interfaces: IClassExtension, IFeatureClassExtension, IObjectClassExtension, IObjectClassValidation