|
| 1 | +# MetaObjects Architecture Guide for Claude AI |
| 2 | + |
| 3 | +## Core Architecture Overview |
| 4 | + |
| 5 | +MetaObjects implements a sophisticated metadata-driven development framework where application behavior and structure are controlled through metadata definitions rather than hard-coded implementations. |
| 6 | + |
| 7 | +## Module Architecture |
| 8 | + |
| 9 | +### Build Dependency Order |
| 10 | +``` |
| 11 | +metadata → maven-plugin → core → om |
| 12 | +``` |
| 13 | + |
| 14 | +**Critical**: `metadata` must be built first as it generates models used by `core`. |
| 15 | + |
| 16 | +### Module Responsibilities |
| 17 | + |
| 18 | +#### 1. Metadata Module (`metadata/`) |
| 19 | +- **Core metadata models**: `MetaObject`, `MetaField`, `MetaAttribute` |
| 20 | +- **Exception hierarchy**: `MetaDataException`, `ValueException`, `InvalidMetaDataException` |
| 21 | +- **Base interfaces**: `MetaDataAware`, `DataTypeAware`, `MetaDataValueHandler` |
| 22 | +- **Data type system**: `DataTypes` enum, validation framework |
| 23 | +- **Key classes**: `MetaAttribute`, `StringAttribute`, `ClassAttribute` |
| 24 | + |
| 25 | +#### 2. Maven Plugin Module (`maven-plugin/`) |
| 26 | +- **Code generation**: `MetaDataGeneratorMojo` |
| 27 | +- **Build integration**: Maven lifecycle integration |
| 28 | +- **Configuration**: `GeneratorParam`, `LoaderParam` |
| 29 | +- **MojoSupport**: Interface for MetaDataLoader integration |
| 30 | + |
| 31 | +#### 3. Core Module (`core/`) |
| 32 | +- **MetaObject implementations**: `ValueMetaObject`, `DataMetaObject`, `ProxyMetaObject`, `MappedMetaObject` |
| 33 | +- **Loader framework**: `FileMetaDataLoader`, `XMLFileMetaDataLoader` |
| 34 | +- **IO system**: JSON/XML serialization with Gson integration |
| 35 | +- **Generators**: PlantUML, XSD, JSON model generators |
| 36 | +- **Validation**: Field and object-level validation framework |
| 37 | + |
| 38 | +#### 4. Object Manager Module (`om/`) |
| 39 | +- **Expression system**: `Expression`, `ExpressionGroup`, `ExpressionOperator` |
| 40 | +- **Query framework**: `QueryOptions`, `Range`, `SortOrder` |
| 41 | +- **Manager integration**: `ManagerAwareMetaObject` |
| 42 | + |
| 43 | +## Key Design Patterns |
| 44 | + |
| 45 | +### 1. Metadata-Driven Architecture |
| 46 | +```java |
| 47 | +// Objects are defined by metadata, not classes |
| 48 | +MetaObject metaObj = loader.getMetaObject("MyObject"); |
| 49 | +Object instance = metaObj.newInstance(); |
| 50 | +metaObj.setFieldValue(instance, "fieldName", value); |
| 51 | +``` |
| 52 | + |
| 53 | +### 2. Type System |
| 54 | +```java |
| 55 | +public enum DataTypes { |
| 56 | + STRING, INT, LONG, FLOAT, DOUBLE, BOOLEAN, DATE, OBJECT, ARRAY |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### 3. MetaObject Inheritance Hierarchy |
| 61 | +``` |
| 62 | +MetaDataAware |
| 63 | + ├── MetaObject (interface) |
| 64 | + ├── ValueMetaObject (dynamic, public access) |
| 65 | + ├── DataMetaObject (wrapped, protected access) |
| 66 | + ├── ProxyMetaObject (proxy implementations) |
| 67 | + └── MappedMetaObject (Map-based objects) |
| 68 | +``` |
| 69 | + |
| 70 | +### 4. Loader Architecture |
| 71 | +``` |
| 72 | +MetaDataLoader (base) |
| 73 | + ├── FileMetaDataLoader (sophisticated parser) |
| 74 | + ├── XMLFileMetaDataLoader (backward compatible) |
| 75 | + └── SimpleLoader (strict TypesConfig/MetaModel) |
| 76 | +``` |
| 77 | + |
| 78 | +## Critical Components |
| 79 | + |
| 80 | +### MetaObject Interface |
| 81 | +- `newInstance()` - Create objects from metadata |
| 82 | +- `getFieldValue()/setFieldValue()` - Field access |
| 83 | +- `performValidation()` - Object validation |
| 84 | +- `getMetaField()` - Field metadata access |
| 85 | + |
| 86 | +### Serialization System |
| 87 | +- **JsonModelWriter/JsonMetaDataWriter**: Gson-based JSON serialization |
| 88 | +- **XMLSerializationHandler**: Custom XML serialization |
| 89 | +- **TypeAdapters**: MetaObject-aware Gson adapters |
| 90 | + |
| 91 | +### Validation Framework |
| 92 | +- **Field-level**: `ArrayValidator`, `StringValidator` |
| 93 | +- **Object-level**: `MetaValidator` interface |
| 94 | +- **Integration**: Automatic validation on object creation/modification |
| 95 | + |
| 96 | +### Generator Framework |
| 97 | +- **PlantUML**: UML diagram generation from metadata |
| 98 | +- **XSD**: Schema generation for MetaModel files |
| 99 | +- **JSON Models**: Export metadata as JSON |
| 100 | +- **Code Generation**: Java interface generation |
| 101 | + |
| 102 | +## Data Flow |
| 103 | + |
| 104 | +### 1. Metadata Loading |
| 105 | +``` |
| 106 | +TypesConfig.xml → MetaDataLoader → MetaObject definitions → Registry |
| 107 | +``` |
| 108 | + |
| 109 | +### 2. Object Creation |
| 110 | +``` |
| 111 | +MetaObject.newInstance() → Apply defaults → Validation → Object instance |
| 112 | +``` |
| 113 | + |
| 114 | +### 3. Serialization |
| 115 | +``` |
| 116 | +Object → MetaObject → TypeAdapter → JSON/XML output |
| 117 | +``` |
| 118 | + |
| 119 | +## Configuration Files |
| 120 | + |
| 121 | +### TypesConfig.xml |
| 122 | +Defines metadata structure, validation rules, and object relationships: |
| 123 | +```xml |
| 124 | +<typesConfig> |
| 125 | + <metaObjects> |
| 126 | + <object name="Person" class="com.example.Person"> |
| 127 | + <field name="name" type="STRING" required="true"/> |
| 128 | + <field name="age" type="INT" defaultValue="0"/> |
| 129 | + </object> |
| 130 | + </metaObjects> |
| 131 | +</typesConfig> |
| 132 | +``` |
| 133 | + |
| 134 | +### MetaModel Files |
| 135 | +Define specific object instances and their metadata. |
| 136 | + |
| 137 | +## Performance Considerations |
| 138 | + |
| 139 | +### Caching Strategy |
| 140 | +- **ArrayValidator**: Caches min/max size values with boolean flags |
| 141 | +- **MetaObject Registry**: Singleton pattern for metadata caching |
| 142 | +- **Type conversion**: Optimized paths for native types |
| 143 | + |
| 144 | +### Memory Management |
| 145 | +- Uses modern Java features (Java 21) |
| 146 | +- StringBuilder over StringBuffer for performance |
| 147 | +- Lazy loading of metadata where possible |
| 148 | + |
| 149 | +## Error Handling Patterns |
| 150 | + |
| 151 | +### Exception Hierarchy |
| 152 | +``` |
| 153 | +MetaException (base) |
| 154 | + ├── MetaDataException |
| 155 | + │ ├── MetaDataNotFoundException |
| 156 | + │ └── InvalidMetaDataException |
| 157 | + └── ValueException |
| 158 | + ├── ValueNotFoundException |
| 159 | + └── InvalidValueException |
| 160 | +``` |
| 161 | + |
| 162 | +### Error Recovery |
| 163 | +- Graceful fallbacks in parsers |
| 164 | +- Comprehensive logging with SLF4J |
| 165 | +- Validation with detailed error messages |
| 166 | + |
| 167 | +## Integration Points |
| 168 | + |
| 169 | +### Maven Integration |
| 170 | +- Build-time code generation |
| 171 | +- Classpath-aware loading (runtime/compile/test) |
| 172 | +- OSGi bundle generation |
| 173 | + |
| 174 | +### Spring Boot Compatibility |
| 175 | +- Gson-based JSON serialization works with Spring Boot |
| 176 | +- Replace Jackson with Gson for MetaObject support |
| 177 | + |
| 178 | +### OSGi Support |
| 179 | +- Full OSGi bundle metadata |
| 180 | +- Classloader-aware metadata loading |
| 181 | +- Dynamic package imports/exports |
| 182 | + |
| 183 | +## Development Guidelines |
| 184 | + |
| 185 | +### Adding New MetaObject Types |
| 186 | +1. Extend base MetaObject interface |
| 187 | +2. Implement required lifecycle methods |
| 188 | +3. Add serialization support |
| 189 | +4. Update validation framework |
| 190 | +5. Add comprehensive tests |
| 191 | + |
| 192 | +### Creating New Generators |
| 193 | +1. Implement Generator interface |
| 194 | +2. Register in plugin configuration |
| 195 | +3. Add Maven goal support |
| 196 | +4. Document output format |
| 197 | + |
| 198 | +### Extending Validation |
| 199 | +1. Create validator implementing appropriate interface |
| 200 | +2. Register in metadata configuration |
| 201 | +3. Add to validation chain |
| 202 | +4. Test edge cases thoroughly |
| 203 | + |
| 204 | +## Common Pitfalls |
| 205 | + |
| 206 | +1. **Build Order**: Always build `metadata` before `core` |
| 207 | +2. **Classloader Issues**: Set appropriate classloader for OSGi/Maven contexts |
| 208 | +3. **Validation**: Don't skip object-level validation |
| 209 | +4. **Serialization**: Use MetaObject-aware serializers for complex objects |
| 210 | +5. **Memory**: Be careful with metadata caching in long-running applications |
| 211 | + |
| 212 | +## Future Architecture (v4.4.0+) |
| 213 | + |
| 214 | +- **Abstract/Interface MetaData**: Native support for inheritance |
| 215 | +- **Enhanced IO**: YAML, HOCON, TOML support |
| 216 | +- **Plugin Architecture**: Extensible IO readers/writers |
| 217 | +- **Editor Integration**: GUI-based metadata editing |
| 218 | +- **Advanced TypedMetaDataLoader**: More sophisticated loading control |
0 commit comments