com.envimate.mapmate.deserialization.builder.ScannablePackageBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapmate Show documentation
Show all versions of mapmate Show documentation
MapMate is a modern mapping framework in the scope of mapping data in
Json, XML, or YAML format into DTOs composed and vice versa.
/*
* 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");
}
}
}