All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.envimate.mapmate.deserialization.builder.ScannablePackageBuilder Maven / Gradle / Ivy

Go to download

MapMate is a modern mapping framework in the scope of mapping data in Json, XML, or YAML format into DTOs composed and vice versa.

There is a newer version: 1.6.8
Show newest version
/*
 * Copyright (C) 2017 [Richard Hauswald, Nune Isabekyan] (envimate GmbH - https://envimate.com/)
 */

package com.envimate.mapmate.deserialization.builder;

import com.envimate.mapmate.*;

import java.util.ArrayList;
import java.util.List;

public final class ScannablePackageBuilder {
    private final PackageName packageName;
    private final List> exclusions;
    private final DeserializerBuilder parent;
    private CustomPrimitiveFilter customPrimitiveFilter;
    private DataTransferObjectFilter dataTransferObjectFilter;

    ScannablePackageBuilder(final DeserializerBuilder deserializerBuilder, final PackageName packageName) {
        this.parent = deserializerBuilder;
        this.packageName = packageName;
        this.exclusions = new ArrayList<>(0);
    }

    public CustomPrimitiveFilterBuilderRequiredStep forCustomPrimitives() {
        return new CustomPrimitiveFilterBuilder(this);
    }

    DeserializerBuilder forCustomPrimitives(final CustomPrimitiveFilter customPrimitiveFilter) {
        this.customPrimitiveFilter = customPrimitiveFilter;
        return this.parent.thatScansThePackage(build());
    }

    public DataTransferObjectFilterBuilderRequiredStep forDataTransferObjects() {
        return new DataTransferObjectFilterBuilder(this);
    }

    DeserializerBuilder forDataTransferObjects(final DataTransferObjectFilter dataTransferObjectFilter) {
        this.dataTransferObjectFilter = dataTransferObjectFilter;
        return this.parent.thatScansThePackage(build());
    }

    public ScannablePackageBuilder excluding(final Class type) {
        if (type == null) {
            throw new NullPointerException("excluded type cannot be null");
        }
        this.exclusions.add(type);
        return this;
    }

    private ScannablePackageDirective build() {
        if(this.customPrimitiveFilter != null) {
            return new ScannablePackageWithDeserializableCPs(ScannablePackage.scannablePackage(
                    this.packageName,
                    this.customPrimitiveFilter.getFilters()),
                    this.customPrimitiveFilter);
        } else if(this.dataTransferObjectFilter != null) {
            return new ScannablePackageWithDeserializableDTOs(ScannablePackage.scannablePackage(
                    this.packageName,
                    this.dataTransferObjectFilter.getFilters()),
                    this.dataTransferObjectFilter);
        } else {
            throw new IllegalStateException("scannable package builder requires a filter");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy