}
OutputDataType encodeOutput(String key, Parameter<?> outputParam, String mimeType,
boolean reference) {
Wps10Factory f = Wps10Factory.eINSTANCE;
OutputDataType output = f.createOutputDataType();
output.setIdentifier(Ows11Util.code(key));
output.setTitle(Ows11Util.languageString(outputParam.description));
final Object o = outputs.get(key);
if (mimeType == null) {
mimeType = getOutputMimeType(key);
}
ProcessParameterIO ppio = ProcessParameterIO.find(outputParam, context, mimeType);
if (ppio == null) {
throw new WPSException("Don't know how to encode output " + key + " in mime type "
+ mimeType);
}
try {
if (reference && ppio instanceof ComplexPPIO) {
// encode as reference
OutputReferenceType outputReference = f.createOutputReferenceType();
output.setReference(outputReference);
ComplexPPIO cppio = (ComplexPPIO) ppio;
File file = resourceManager.getOutputFile(executionId, key + "." + cppio.getFileExtension());
// write out the file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
cppio.encode(o, fos);
} finally {
IOUtils.closeQuietly(fos);
}
// create the link
Map<String, String> kvp = new LinkedHashMap<String, String>();
kvp.put("service", "WPS");
kvp.put("version", "1.0.0");
kvp.put("request", "GetExecutionResult");
kvp.put("executionId", executionId);
kvp.put("outputId", file.getName());
if(o instanceof RawData) {
RawData rawData = (RawData) o;
kvp.put("mimetype", rawData.getMimeType());
} else {
kvp.put("mimetype", cppio.getMimeType());
}
outputReference.setHref(ResponseUtils.buildURL(request.getBaseUrl(), "ows", kvp, URLType.SERVICE));
outputReference.setMimeType(cppio.getMimeType());
} else {
// encode as data
DataType data = f.createDataType();
output.setData(data);
if (ppio instanceof LiteralPPIO) {
LiteralDataType literal = f.createLiteralDataType();
data.setLiteralData(literal);