info.freelibrary.iiif.presentation.v3.services.AbstractService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jiiify-presentation-v3 Show documentation
Show all versions of jiiify-presentation-v3 Show documentation
A Java Library for version 3 of the IIIF Presentation API
package info.freelibrary.iiif.presentation.v3.services;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonSetter;
import info.freelibrary.util.StringUtils;
import info.freelibrary.util.warnings.JDK;
import info.freelibrary.iiif.presentation.v3.Service;
import info.freelibrary.iiif.presentation.v3.utils.JsonKeys;
/**
* An abstract service class that specific services can extend.
*/
public abstract class AbstractService> implements Service {
/**
* A list of services related to this service.
*/
protected List> myServices;
/**
* This service's type.
*/
protected String myType;
/**
* This service's ID.
*/
protected URI myID;
/**
* An empty constructor for Jackson's deserialization process.
*/
protected AbstractService() {
// This is intentionally left empty
}
@Override
@JsonGetter(JsonKeys.ID)
public URI getID() {
return myID;
}
@Override
@JsonIgnore
@SuppressWarnings(JDK.UNCHECKED)
public T setID(final URI aID) {
myID = aID;
return (T) this;
}
@Override
@JsonSetter(JsonKeys.ID)
public T setID(final String aID) {
return setID(URI.create(aID));
}
@Override
public abstract T setType(String aType);
@Override
public String getType() {
// Overrides the default method defined in the Service interface
return StringUtils.trimToNull(myType) == null ? getClass().getSimpleName() : myType;
}
@Override
@JsonSetter(JsonKeys.SERVICE)
@SuppressWarnings(JDK.UNCHECKED)
public T setServices(final List> aServiceList) {
if (!aServiceList.isEmpty()) {
final List> services = getServices();
Objects.requireNonNull(aServiceList);
services.clear();
services.addAll(aServiceList);
}
return (T) this;
}
@Override
@JsonIgnore
public T setServices(final Service>... aServiceArray) {
return setServices(Arrays.asList(aServiceArray));
}
@Override
@JsonGetter(JsonKeys.SERVICE)
@JsonInclude(Include.NON_EMPTY)
public List> getServices() {
if (myServices == null) {
myServices = new ArrayList<>();
}
return myServices;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy