use of org.teiid.core.types.XMLType in project teiid by teiid.
the class WSWSDLProcedureExecution method getOutputParameterValues.
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
Object result = returnValue;
if (returnValue != null && procedure.getArguments().size() > 1 && Boolean.TRUE.equals(procedure.getArguments().get(1).getArgumentValue().getValue())) {
SQLXMLImpl sqlXml = new StAXSQLXML(returnValue);
XMLType xml = new XMLType(sqlXml);
xml.setType(Type.DOCUMENT);
result = xml;
}
return Arrays.asList(result);
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class SaxonXQueryExpression method createXMLType.
public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager, boolean emptyOnEmpty, CommandContext context) throws XPathException, TeiidComponentException, TeiidProcessingException {
final Item item = iter.next();
if (item == null && !emptyOnEmpty) {
return null;
}
XMLType.Type type = Type.CONTENT;
if (item instanceof NodeInfo) {
NodeInfo info = (NodeInfo) item;
type = getType(info);
}
final Item next = iter.next();
if (next != null) {
type = Type.CONTENT;
}
SQLXMLImpl xml = XMLSystemFunctions.saveToBufferManager(bufferManager, new XMLTranslator() {
@Override
public void translate(Writer writer) throws TransformerException, IOException {
QueryResult.serializeSequence(new PushBackSequenceIterator(iter, item, next), config, writer, DEFAULT_OUTPUT_PROPERTIES);
}
}, context);
XMLType value = new XMLType(xml);
value.setType(type);
return value;
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class XQueryEvaluator method evaluate.
public static Object evaluate(XMLType value, XMLCast expression, CommandContext context) throws ExpressionEvaluationException {
Configuration config = new Configuration();
Type t = value.getType();
try {
Item i = null;
switch(t) {
case CONTENT:
// content could map to an array value, but we aren't handling that case here yet - only in xmltable
case COMMENT:
case PI:
throw new FunctionExecutionException();
case TEXT:
i = new StringValue(value.getString());
break;
case UNKNOWN:
case DOCUMENT:
case ELEMENT:
StreamSource ss = value.getSource(StreamSource.class);
try {
i = config.buildDocument(ss);
} finally {
if (ss.getInputStream() != null) {
ss.getInputStream().close();
}
if (ss.getReader() != null) {
ss.getReader().close();
}
}
break;
default:
// $NON-NLS-1$
throw new AssertionError("Unknown xml value type " + t);
}
return XMLTableNode.getValue(expression.getType(), i, config, context);
} catch (IOException e) {
throw new FunctionExecutionException(e);
} catch (ValidationException e) {
throw new FunctionExecutionException(e);
} catch (TransformationException e) {
throw new FunctionExecutionException(e);
} catch (XPathException e) {
throw new FunctionExecutionException(e);
} catch (SQLException e) {
throw new FunctionExecutionException(e);
}
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class WSProcedureExecution method execute.
@SuppressWarnings("unchecked")
public void execute() throws TranslatorException {
List<Argument> arguments = this.procedure.getArguments();
String style = (String) arguments.get(0).getArgumentValue().getValue();
String action = (String) arguments.get(1).getArgumentValue().getValue();
XMLType docObject = (XMLType) arguments.get(2).getArgumentValue().getValue();
Source source = null;
try {
Class type = StAXSource.class;
if (executionFactory.getDefaultServiceMode() == Mode.MESSAGE) {
type = DOMSource.class;
}
source = convertToSource(type, docObject);
String endpoint = (String) arguments.get(3).getArgumentValue().getValue();
if (style == null) {
style = executionFactory.getDefaultBinding().getBindingId();
} else {
try {
style = Binding.valueOf(style.toUpperCase()).getBindingId();
} catch (IllegalArgumentException e) {
// $NON-NLS-1$
throw new TranslatorException(WSExecutionFactory.UTIL.getString("invalid_invocation", Arrays.toString(Binding.values())));
}
}
Dispatch dispatch = conn.createDispatch(style, endpoint, type, executionFactory.getDefaultServiceMode());
if (Binding.HTTP.getBindingId().equals(style)) {
if (action == null) {
// $NON-NLS-1$
action = "POST";
}
dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, action);
if (source != null && !"POST".equalsIgnoreCase(action)) {
// $NON-NLS-1$
if (this.executionFactory.getXMLParamName() == null) {
// $NON-NLS-1$
throw new WebServiceException(WSExecutionFactory.UTIL.getString("http_usage_error"));
}
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
StringWriter writer = new StringWriter();
// TODO: prevent this from being too large
t.transform(source, new StreamResult(writer));
// $NON-NLS-1$
String param = Util.httpURLEncode(this.executionFactory.getXMLParamName()) + "=" + Util.httpURLEncode(writer.toString());
endpoint = WSConnection.Util.appendQueryString(endpoint, param);
} catch (TransformerException e) {
throw new WebServiceException(e);
}
}
} else {
if (action != null) {
dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action);
}
}
if (source == null) {
// JBoss Native DispatchImpl throws exception when the source is null
// $NON-NLS-1$
source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<none/>")));
}
this.returnValue = (Source) dispatch.invoke(source);
} catch (SQLException e) {
throw new TranslatorException(e);
} catch (WebServiceException e) {
throw new TranslatorException(e);
} catch (XMLStreamException e) {
throw new TranslatorException(e);
} finally {
Util.closeSource(source);
}
}
use of org.teiid.core.types.XMLType in project teiid by teiid.
the class LobWorkItem method createLobStream.
/**
* Create a object which can create a sequence of LobChunk objects on a given
* LOB object
* @throws SQLException
*/
private ByteLobChunkStream createLobStream(String referenceStreamId) throws TeiidComponentException, SQLException {
// get the reference object in the buffer manager, and try to stream off
// the original sources.
Streamable<?> streamable = parent.resultsBuffer.getLobReference(referenceStreamId);
if (streamable instanceof XMLType) {
XMLType xml = (XMLType) streamable;
return new ByteLobChunkStream(xml.getBinaryStream(), chunkSize);
} else if (streamable instanceof ClobType) {
ClobType clob = (ClobType) streamable;
return new ByteLobChunkStream(new ReaderInputStream(clob.getCharacterStream(), Charset.forName(Streamable.ENCODING)), chunkSize);
}
BlobType blob = (BlobType) streamable;
return new ByteLobChunkStream(blob.getBinaryStream(), chunkSize);
}
Aggregations