A metadata-driven KerML metamodel implementation using the Mdm Framework - a next-generation MOF (Meta-Object Facility) combined with model data management.
The core framework (org.openmbee.gearshift) provides:
-
Metamodel Layer (
org.openmbee.gearshift.metamodel)MetaClass- Define types with attributes, operations, and constraintsMetaProperty- Define properties with multiplicity, aggregation, etc.MetaAssociation- Define relationships between typesMetaConstraint- OCL or custom constraint expressionsMetaOperation- Define operations/methods
-
Engine Layer (
org.openmbee.gearshift.engine)MetamodelRegistry- Register and manage metaclassesMDMEngine- Create instances, validate constraints, handle derived propertiesMDMObject- Runtime instances of metaclassesNameResolver- KerML 8.2.3.5 compliant name resolution engine
-
Repository Layer (
org.openmbee.gearshift.repository)ModelRepository- CRUD operations with indexing- Type-based and property-based indexing for fast queries
-
Query Layer (
org.openmbee.gearshift.query)QueryEngine- Fluent API for querying model instances
-
Unified API (
GearshiftEngine)- Single entry point combining all capabilities
The KerML-specific implementation (org.openmbee.gearshift.kerml) defines:
Element- Root of KerML hierarchyRelationship- Base for relationshipsMembership- Element membership in NamespacesNamespace- Container for ElementsImport- Import mechanisms (Membership, Namespace)Specialization- Type specialization relationshipsFeature- KerML featuresType- KerML typesClassifier- KerML classifiers
Define metamodels using Kotlin's named parameters:
val element = MetaClass(
name = "Element",
isAbstract = true,
attributes = listOf(
MetaProperty(
name = "name",
type = "String",
multiplicity = "0..1"
)
)
)Save/load metamodels as JSON:
// Save to JSON
MetamodelLoader.saveMetaClass(element, Path.of("element.json"))
// Load from JSON
val loaded = MetamodelLoader.loadMetaClass(Path.of("element.json"))Create instances and manage them:
val engine = GearshiftEngine()
engine.registerMetaClass(element)
// Create instance
val (id, instance) = engine.createInstance("Element")
engine.setProperty(id, "name", "MyElement")Indexed storage with queries:
// Query by type
val allFeatures = engine.getInstancesByType("Feature")
// Query by property
val named = engine.getInstancesByProperty("name", "MyFeature")
// Fluent queries
val results = engine.queryEngine
.from("Feature")
.where("isAbstract", true)
.execute()Metamodel and instance validation:
// Validate metamodel
val errors = engine.validateMetamodel()
// Validate instance
val instanceErrors = engine.validateInstance(id)Full KerML compliant name resolution:
// Resolve qualified name
val result = engine.resolveName(
qualifiedName = "BaseTypes::Integer",
localNamespaceId = "my-namespace-id"
)
// Access resolved element
if (result != null) {
val element = result.memberElement
val membership = result.membership
}
// Global scope resolution
val globalResult = engine.resolveName("$::StandardLibrary::Boolean", anyNamespaceId)
// Redefinition context
val redefinedResult = engine.resolveName(
qualifiedName = "baseFeature",
localNamespaceId = derivedTypeId,
isRedefinitionContext = true
)See Name Resolution for complete documentation.
See docs/README.md for the full documentation hub — architecture guides, reference material, and roadmap.
- Java 17 or later
- Gradle 8.x (or use the Gradle wrapper)
# Initialize Gradle wrapper (if not present)
gradle wrapper --gradle-version 8.5
# Build
./gradlew build
# Run
./gradlew run- Open the project directory
- IntelliJ will auto-detect the Gradle project
- Wait for dependencies to download
- Run
Application.kt
src/main/kotlin/org/openmbee/gearshift/
├── GearshiftEngine.kt # Main unified API
├── metamodel/ # Metamodel definitions
│ ├── MetaClass.kt
│ ├── MetaProperty.kt
│ ├── MetaAssociation.kt
│ ├── MetaConstraint.kt
│ ├── MetaOperation.kt
│ └── MetamodelLoader.kt # JSON serialization
├── engine/ # MOF engine
│ ├── MetamodelRegistry.kt
│ ├── MDMEngine.kt
│ ├── MDMObject.kt
│ └── NameResolver.kt # KerML 8.2.3.5 name resolution
├── repository/ # Model storage
│ └── ModelRepository.kt
├── query/ # Query engine
│ └── QueryEngine.kt
└── kerml/ # KerML implementation
├── KerMLMetamodel.kt # KerML metamodel definition
└── Application.kt # Main application
- Kotlin 1.9.22
- Jackson 2.16.1 (JSON serialization)
- ANTLR 4.13.1 (for GQL, OCL, and future KerML grammars)
- Kotlin Logging 6.0.3
- Logback 1.4.14
- Expand KerML Metamodel - Add complete KerML specification
- Code Generation - Generate Java/Kotlin API from metamodel
- OCL Integration - Evaluate OCL constraints
- KerML Parser - Integrate KerML ANTLR grammar
- Persistence - Add database backend for repository
- REST API - Expose via HTTP API
Gearshift combines the power of:
- MOF - Metamodel-driven architecture
- Model Data Management - Efficient storage and querying
- Modern Kotlin - Expressive syntax with named parameters
- JSON Interoperability - Easy import/export of metamodels
The result is a framework that feels like working with JSON while providing the full power of a metamodel-driven system.