
com.marklogic.client.dataservices.impl.HandleProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of marklogic-client-api Show documentation
Show all versions of marklogic-client-api Show documentation
The official MarkLogic Java client API.
The newest version!
/*
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
*/
package com.marklogic.client.dataservices.impl;
import com.marklogic.client.impl.RESTServices;
import com.marklogic.client.io.marker.BufferableContentHandle;
public interface HandleProvider {
BufferableContentHandle, ?> getInputHandle();
BufferableContentHandle, ?> getOutputHandle();
I[] newInputArray(int length);
O[] newOutputArray(int length);
BufferableContentHandle, ?>[] bufferableInputHandleOn(I[] input);
O[] outputAsArray(CallContextImpl callCtxt, RESTServices.MultipleCallResponse response);
class ContentHandleProvider implements HandleProvider {
private final BufferableContentHandle inputHandle;
private final BufferableContentHandle outputHandle;
public ContentHandleProvider(BufferableContentHandle inputHandle, BufferableContentHandle outputHandle) {
this.inputHandle = inputHandle;
this.outputHandle = outputHandle;
}
@Override
public BufferableContentHandle getInputHandle() {
return inputHandle;
}
@Override
public BufferableContentHandle getOutputHandle() {
return outputHandle;
}
@Override
public I[] newInputArray(int length) {
if (inputHandle == null) {
throw new IllegalStateException("No input handle provided");
}
return inputHandle.newArray(length);
}
@Override
public O[] newOutputArray(int length) {
if (outputHandle == null) {
throw new IllegalStateException("No output handle provided");
}
return outputHandle.newArray(length);
}
@Override
public BufferableContentHandle,?>[] bufferableInputHandleOn(I[] input) {
if (inputHandle == null) {
throw new IllegalStateException("No input handle provided");
}
return inputHandle.resendableHandleFor(input);
}
@Override
public O[] outputAsArray(CallContextImpl callCtxt, RESTServices.MultipleCallResponse response) {
if (outputHandle == null) {
throw new IllegalStateException("No output handle provided");
}
return response.asArrayOfContent(
callCtxt.isLegacyContext() ? null : callCtxt.getEndpointState(), outputHandle
);
}
}
class DirectHandleProvider
implements HandleProvider, BufferableContentHandle> {
private final BufferableContentHandle inputHandle;
private final BufferableContentHandle outputHandle;
public DirectHandleProvider(BufferableContentHandle inputHandle, BufferableContentHandle outputHandle) {
this.inputHandle = inputHandle;
this.outputHandle = outputHandle;
}
@Override
public BufferableContentHandle getInputHandle() {
return inputHandle;
}
@Override
public BufferableContentHandle getOutputHandle() {
return outputHandle;
}
@Override
public BufferableContentHandle[] newInputArray(int length) {
if (inputHandle == null) {
throw new IllegalStateException("No input handle provided");
}
return inputHandle.newHandleArray(length);
}
@Override
public BufferableContentHandle[] newOutputArray(int length) {
if (outputHandle == null) {
throw new IllegalStateException("No output handle provided");
}
return outputHandle.newHandleArray(length);
}
@Override
public BufferableContentHandle[] bufferableInputHandleOn(BufferableContentHandle[] input) {
return input;
}
@Override
public BufferableContentHandle[] outputAsArray(
CallContextImpl, BufferableContentHandle> callCtxt,
RESTServices.MultipleCallResponse response) {
if (outputHandle == null) {
throw new IllegalStateException("No output handle provided");
}
return response.asArrayOfHandles(callCtxt.getEndpointState(), outputHandle);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy