Brentcroft Materializer

Materialize and validate objects from XML.

License

License

GroupId

GroupId

com.brentcroft.tools
ArtifactId

ArtifactId

materializer
Last Version

Last Version

00.01.05
Release Date

Release Date

Type

Type

jar
Description

Description

Brentcroft Materializer
Materialize and validate objects from XML.
Project URL

Project URL

http://github.com/brentcroft/materializer
Source Code Management

Source Code Management

http://github.com/brentcroft/materializer

Download materializer

How to add to project

<!-- https://jarcasting.com/artifacts/com.brentcroft.tools/materializer/ -->
<dependency>
    <groupId>com.brentcroft.tools</groupId>
    <artifactId>materializer</artifactId>
    <version>00.01.05</version>
</dependency>
// https://jarcasting.com/artifacts/com.brentcroft.tools/materializer/
implementation 'com.brentcroft.tools:materializer:00.01.05'
// https://jarcasting.com/artifacts/com.brentcroft.tools/materializer/
implementation ("com.brentcroft.tools:materializer:00.01.05")
'com.brentcroft.tools:materializer:jar:00.01.05'
<dependency org="com.brentcroft.tools" name="materializer" rev="00.01.05">
  <artifact name="materializer" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.brentcroft.tools', module='materializer', version='00.01.05')
)
libraryDependencies += "com.brentcroft.tools" % "materializer" % "00.01.05"
[com.brentcroft.tools/materializer "00.01.05"]

Dependencies

compile (1)

Group / Artifact Type Version
com.brentcroft.tools : el-plates jar 01.01.02

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar RELEASE

test (1)

Group / Artifact Type Version
junit : junit jar RELEASE

Project Modules

There are no modules declared in this project.

materializer

Maven Central

Materialize and validate objects from an XML InputSource during SAX parsing.

Usage:

Materializer< Properties > materializer = new Materializer<>(
        () -> PropertiesRootTag.ROOT,
        Properties::new );

Properties properties = materializer
        .apply(
                new InputSource(
                        new FileInputStream( "src/test/resources/sample-properties.xml" ) ) );

A Materializer provides a functional interface (internally orchestrating a TagHandler and a pool of SAXParsers).

  1. Implement FlatTag enums for cases that build and validate the current item.
  2. Implement StepTag enums for cases that build and validate a child of the current item.
  3. Implement JumpTag enums for cases that delegate to another tag.

Schema validation is only applied if a non-null schema object is assigned to the Materializer. Additional validation can be declared on enums as required.

These enums inherit default methods from the Tag interfaces, so enum constructors only have to implement sufficient and necessary features.

Review the tests for more examples.

Following is the complete code for the usage shown above:

@Getter
public enum PropertiesRootTag implements FlatTag< Properties >
{
    ENTRY(
            "entry",
            ( properties, event ) -> event.getAttribute( "key" ),
            ( properties, text, cache ) -> properties.setProperty( cache, text ) ),
    COMMENT( "comment" ),
    PROPERTIES( "*", ENTRY, COMMENT ),
    ROOT( "", PROPERTIES );

    private final String tag;
    private final boolean multiple;
    private final boolean choice;
    private final FlatCacheOpener< Properties, OpenEvent, ? > opener;
    private final FlatCacheCloser< Properties, String, ? > closer;
    private final Tag< ? super Properties, ? >[] children;

    @SafeVarargs
    PropertiesRootTag( String tag, Tag< ? super Properties, ? >... children )
    {
        this( tag,null, null, children );
    }

    @SafeVarargs
    < C > PropertiesRootTag(
            String tag,
            BiFunction< Properties, OpenEvent, C > opener,
            TriConsumer< Properties, String, C > closer,
            Tag< ? super Properties, ? >... children
    )
    {
        this.tag = tag;
        this.multiple = isNull( children ) || children.length == 0;
        this.opener = Opener.flatCacheOpener( opener );
        this.closer = Closer.flatCacheCloser( closer );
        this.choice = nonNull( children ) && children.length > 0;
        this.children = children;
    }
}

Tag Generation

A simple SchemaRootTag is provided that models XSD schemas. View the tests to see an example of generating a Tag from a target Class and a Schema.

com.brentcroft.tools

Brentcroft

Good at grasping things, and then twisting them.

Versions

Version
00.01.05
00.01.04
00.01.03
00.01.02
00.01.01
00.00.09
00.00.08
00.00.07
00.00.06
00.00.05
00.00.04
00.00.03
00.00.02
00.00.01