org.xs4j.xmlspitter.OutputSupplierFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xmlslurper Show documentation
Show all versions of xmlslurper Show documentation
An attempt to port parsing capabilities offered by Groovy XMLSlurper into the Java world. The following is not planned to be accurate projection, instead the most useful functions will be implemented.
The newest version!
package org.xs4j.xmlspitter;
import org.xs4j.util.NotNull;
import java.io.OutputStream;
import java.io.Writer;
/**
* Created by mturski on 1/5/2017.
*/
public class OutputSupplierFactory {
public static OutputSupplierFactory getInstance() {
return new OutputSupplierFactory();
}
private OutputSupplierFactory() {
}
/**
* A convenient method to acquire generic {@link OutputSupplier}.
*
* @param type of output
* @return a new instance of OutputSupplier
*/
public OutputSupplier createOutputSupplier() {
return new GenericOutputSupplier();
}
/**
* A convenient method to acquire generic {@link OutputSupplier}.
*
* @param clazz instance of declared type of output
* @param type of output
* @return a new instance of OutputSupplier
*/
public OutputSupplier createOutputSupplier(Class clazz) {
return new GenericOutputSupplier();
}
class GenericOutputSupplier implements OutputSupplier {
static final String ILLEGAL_SUPPLIER_ARGUMENT = "%s must supply with object instances of %s or %s";
private T output;
@Override
public T supply() {
return output;
}
@Override
public OutputSupplier set(@NotNull T output) {
if (!(output instanceof Writer) && !(output instanceof OutputStream) )
throw new IllegalArgumentException(String.format(ILLEGAL_SUPPLIER_ARGUMENT, OutputSupplier.class.getName(), Writer.class.getName(), OutputStream.class.getName()));
this.output = output;
return this;
}
}
}