@@ -337,8 +337,9 @@ MetaField emailField = loader.getMetaFieldByName("email");
337337** Loader Hierarchy ** :
338338```java
339339// Create hierarchical loaders
340- MetaDataLoader coreLoader = new FileMetaDataLoader (" core" );
341- MetaDataLoader businessLoader = new FileMetaDataLoader (" business" );
340+ MetaDataLoader coreLoader = MetaDataLoader . fromResources(" core" ,
341+ List . of(" core-types.json" ));
342+ MetaDataLoader businessLoader = new MetaDataLoader (" business" );
342343
343344// Set up hierarchy
344345businessLoader.addParentLoader (coreLoader );
@@ -348,67 +349,138 @@ MetaObject coreType = businessLoader.getMetaObjectByName("CoreType"); // From pa
348349MetaObject businessType = businessLoader. getMetaObjectByName(" BusinessType" ); // From child
349350```
350351
351- ### FileMetaDataLoader
352+ #### Static Factory Methods
352353
353- ** Package ** : `com. metaobjects. loader. file`
354- ** Purpose ** : File - based metadata loader with JSON / XML support
355-
356- #### Key Methods
354+ `MetaDataLoader ` exposes a set of static factories that cover the common loading patterns. Each factory builds the appropriate `MetaDataSource `(s), calls `load(... )`, and `init()`s the loader in one step.
357355
358356```java
359- public class FileMetaDataLoader extends MetaDataLoader {
357+ public class MetaDataLoader {
360358
361- // Constants
362- public static final String SUBTYPE_FILE = " file " ;
363- public static final String XML_EXTENSION = " *.xml " ;
364- public static final String JSON_EXTENSION = " *.json " ;
359+ // Directory expansion (recursive by default; use Options to customize)
360+ public static MetaDataLoader fromDirectory ( String name , Path directory )
361+ public static MetaDataLoader fromDirectory ( String name , Path directory ,
362+ DirectorySource . Options opts )
365363
366- // Constructors
367- public FileMetaDataLoader (String name )
368- public FileMetaDataLoader (FileLoaderOptions options , String name )
364+ // URI list (file://, classpath://, http(s)://, jar://)
365+ public static MetaDataLoader fromUris (String name , List<URI > uris )
366+ public static MetaDataLoader fromUris (String name , List<URI > uris ,
367+ LoaderOptions opts )
369368
370- // Initialization
371- public FileMetaDataLoader init (FileMetaDataSources sources )
372- public FileLoaderOptions getLoaderOptions ()
369+ // Classpath resources (resolved via the loader's MetaDataClassLoader)
370+ public static MetaDataLoader fromResources (String name , List<String > resources )
371+ public static MetaDataLoader fromResources (String name , List<String > resources ,
372+ LoaderOptions opts )
373373
374- // Configuration
375- public void configure (LoaderConfiguration config )
376- protected void processSources (String sourceDir , List<String > rawSources )
374+ // In-memory content (JSON or XML)
375+ public static MetaDataLoader fromString (String name , String content ,
376+ MetaDataSource .MetaDataFormat format )
377+
378+ // Low-level: build sources yourself and hand them in
379+ public MetaDataLoader load (List<MetaDataSource > sources )
377380}
378381```
379382
380383#### Usage Examples
381384
382- ** File Loader Creation ** :
385+ ** Loader Creation ** :
383386```java
384- // Simple file loader
385- FileMetaDataLoader loader = new FileMetaDataLoader (" myLoader" );
387+ // Directory-based loader
388+ MetaDataLoader dirLoader = MetaDataLoader . fromDirectory(
389+ " myLoader" ,
390+ Path . of(" /metadata" )
391+ );
386392
387- // With custom options
388- FileLoaderOptions options = new FileLoaderOptions ()
389- .setVerbose(true )
390- .setCacheEnabled(true );
391- FileMetaDataLoader loader = new FileMetaDataLoader (options, " customLoader" );
393+ // With custom options (shouldRegister, verbose, strict)
394+ LoaderOptions opts = LoaderOptions . create(false , true , true );
395+ MetaDataLoader customLoader = MetaDataLoader . fromResources(
396+ " customLoader" ,
397+ List . of(" core-metadata.json" ),
398+ opts
399+ );
392400```
393401
394402** Source Configuration ** :
395403```java
396- // Local file sources
397- LocalFileMetaDataSources localSources = new LocalFileMetaDataSources (
398- " /metadata" , // Base directory
399- Arrays . asList(" user.json" , " product.xml" )
400- );
404+ // Single file
405+ MetaDataLoader fileLoader = new MetaDataLoader (" fileLoader" );
406+ fileLoader.load (List .of (new FileSource (Path .of ("/metadata /user .json "))));
407+ fileLoader.init ();
401408
402- loader.init (localSources );
403-
404- // URI sources
405- List<URI > uris = Arrays.asList (
409+ // URI list
410+ MetaDataLoader uriLoader = MetaDataLoader . fromUris(" uriLoader" , List . of(
406411 URI . create(" classpath://metadata/core.json" ),
407412 URI . create(" file:///opt/metadata/business.xml" )
413+ ));
414+
415+ // Inline string (handy for tests)
416+ MetaDataLoader inlineLoader = MetaDataLoader . fromString(
417+ " inlineLoader" ,
418+ jsonContent,
419+ MetaDataSource . MetaDataFormat . JSON
408420);
409- URIFileMetaDataSources uriSources = new URIFileMetaDataSources (uris);
421+ ```
422+
423+ ### MetaDataSource implementations
424+
425+ ** Package ** : `com. metaobjects. loader`
426+
427+ Four built- in sources implement the `MetaDataSource ` SPI :
428+
429+ ```java
430+ // Single file; format inferred from extension (.json / .xml) unless supplied
431+ public final class FileSource implements MetaDataSource {
432+ public FileSource (Path path )
433+ public FileSource (Path path , MetaDataFormat format )
434+ }
435+
436+ // Directory expander; produces FileSources for each metadata file inside
437+ public final class DirectorySource {
438+ public DirectorySource (Path directory )
439+ public DirectorySource (Path directory , Options opts )
440+ public List<MetaDataSource > expandToList ()
441+
442+ public static final class Options {
443+ public Options setExclude(List<String > excludeNames) // skip by file name
444+ public Options setRecurse(boolean recurse) // default true
445+ }
446+ }
447+
448+ // URI-backed source (file://, classpath://, http(s)://, jar://)
449+ public class UriSource implements MetaDataSource {
450+ public UriSource (URI uri )
451+ }
452+
453+ // In-memory content; default id is "<inline>"
454+ public class InMemoryStringSource implements MetaDataSource {
455+ public InMemoryStringSource (String content )
456+ public InMemoryStringSource (String content , String id )
457+ public InMemoryStringSource (String content , String id , MetaDataFormat format )
458+ }
459+ ```
460+
461+ ### LoaderOptions
410462
411- loader.init (uriSources );
463+ ** Package ** : `com. metaobjects. loader`
464+ ** Purpose ** : Tunable flags for loader behavior
465+
466+ ```java
467+ public class LoaderOptions {
468+
469+ // Factory
470+ public static LoaderOptions create (boolean shouldRegister ,
471+ boolean verbose ,
472+ boolean strict )
473+
474+ // Fluent setters
475+ public LoaderOptions setShouldRegister (boolean shouldRegister )
476+ public LoaderOptions setVerbose (boolean verbose )
477+ public LoaderOptions setStrict (boolean strict )
478+
479+ // Accessors
480+ public boolean shouldRegister ()
481+ public boolean isVerbose ()
482+ public boolean isStrict ()
483+ }
412484```
413485
414486## Registry and Type System APIs
0 commit comments