@Override public <T extends StructureReadHandle> T get(T handle) { HandleAccessor.receiveContent(handle, item); return handle; } @Override
public void init(RawQueryDefinition rawQuery, QueryOptionsWriteHandle options, String qtext, String sparql) { this.rawQuery = rawQuery; this.options = options; this.qtext = qtext; this.sparql = sparql; // if a query has been supplied, it's either in JSON or in XML if (rawQuery != null) { this.format = HandleAccessor.as(rawQuery.getHandle()).getFormat(); } else { if (options != null) { this.format = HandleAccessor.as(options).getFormat(); } else { // there's only qtext -- we choose format. this.format = Format.JSON; } } if ( format != Format.XML && format != Format.JSON ) { throw new IllegalArgumentException("Format of rawQuery must be XML or JSON"); } }
private void checkContentFormat(Object contentHandle) { checkContentFormat(HandleAccessor.checkHandle(contentHandle, "content")); } @SuppressWarnings("rawtypes")
@SuppressWarnings("rawtypes") @Override public <T extends RuleListReadHandle> T match(StructureWriteHandle document, String[] candidateRules, T ruleListHandle, ServerTransform transform) { HandleImplementation searchBase = HandleAccessor.checkHandle(document, "match"); Format searchFormat = searchBase.getFormat(); switch(searchFormat) { case UNKNOWN: searchFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON queries can filter for rule matches."); } String mimeType = searchFormat.getDefaultMimetype(); HandleAccessor.receiveContent(ruleListHandle, services.match(document, candidateRules, mimeType, transform)); return ruleListHandle; }
private RequestBody makeRequestBody(AbstractWriteHandle document) { if (document == null) { return new EmptyRequestBody(); } HandleImplementation handleBase = HandleAccessor.as(document); Format format = handleBase.getFormat(); String mimetype = (format == Format.BINARY) ? "application/x-unknown-content-type" : handleBase.getMimetype(); MediaType mediaType = MediaType.parse(mimetype); return (document instanceof OutputStreamSender) ? new StreamingOutputImpl((OutputStreamSender) document, null, mediaType) : new ObjectRequestBody(HandleAccessor.sendContent(document), mediaType); }
String structure = ""; if ( structuredQuery != null ) structure = structuredQuery.serialize(); if ( rawQuery != null ) structure = HandleAccessor.contentAsString(rawQuery.getHandle()); out.write(structure.getBytes("UTF-8")); out.flush(); if ( options != null ) { HandleImplementation handleBase = HandleAccessor.as(options); Object value = handleBase.sendContent(); if ( value instanceof OutputStreamSender ) { ((OutputStreamSender) value).write(out); } else { out.write(HandleAccessor.contentAsString(options).getBytes("UTF-8"));
private CombinedQueryDefinitionImpl parseCombinedQuery(RawCombinedQueryDefinition qdef) { DOMHandle handle = new DOMHandle(); HandleAccessor.receiveContent(handle, HandleAccessor.contentAsString(qdef.getHandle())); Document combinedQueryXml = handle.get(); DOMImplementationLS domImplementation = (DOMImplementationLS) combinedQueryXml.getImplementation();
@Override public void setSparql(TextWriteHandle sparql) { this.sparql = HandleAccessor.contentAsString(sparql); }
static public HandleImplementation checkHandle(Object object, String type) { if (!isHandle(object)) throw new IllegalArgumentException( type+" handle does not extend BaseHandle: "+object.getClass().getName() ); return ((HandleImplementation) object); } static public boolean isHandle(Object object) {
static public String contentAsString(AbstractWriteHandle handle) { try { Object content = sendContent(handle); if ( content == null ) return null; String stringContent = null;
static public <R extends AbstractReadHandle> void receiveContent(R handle, Object content) { if (handle == null) return; HandleImplementation handleImpl = (HandleImplementation) handle; if ( content == null ) { handleImpl.receiveContent(content); } else if ( handleImpl.receiveAs() != null && handleImpl.receiveAs().isAssignableFrom(content.getClass()) ) { handleImpl.receiveContent(content); } else if ( content instanceof String ) { if ( InputStream.class.isAssignableFrom(handleImpl.receiveAs()) ) { handleImpl.receiveContent( new ByteArrayInputStream(getBytes((String) content)) ); } else if ( Reader.class.isAssignableFrom(handleImpl.receiveAs()) ) { handleImpl.receiveContent( new StringReader((String) content) ); } else if ( byte[].class.isAssignableFrom(handleImpl.receiveAs()) ) { handleImpl.receiveContent( getBytes((String) content) ); } else if ( String.class.isAssignableFrom(handleImpl.receiveAs()) ) { handleImpl.receiveContent( content ); } } else { handleImpl.receiveContent(content); } } static private byte[] getBytes(String content) {
@SuppressWarnings("rawtypes") @Override public <T extends RuleListReadHandle> T match(StructureWriteHandle document, String[] candidateRules, T ruleListHandle, ServerTransform transform) { HandleImplementation searchBase = HandleAccessor.checkHandle(document, "match"); Format searchFormat = searchBase.getFormat(); switch(searchFormat) { case UNKNOWN: searchFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON queries can filter for rule matches."); } String mimeType = searchFormat.getDefaultMimetype(); HandleAccessor.receiveContent(ruleListHandle, services.match(document, candidateRules, mimeType, transform)); return ruleListHandle; }
if ( qdef.qtext != null ) searchNode.put("qtext", qdef.qtext); if ( qdef.options != null ) { HandleImplementation optionsBase = HandleAccessor.as(qdef.options); if ( Format.JSON != optionsBase.getFormat() ) { throw new IllegalStateException("Cannot combine a JSON-format structured " + "query with " + optionsBase.getFormat() + "-format options"); String json = HandleAccessor.contentAsString(qdef.options); JsonNode optionsNode = mapper.readTree(json); searchNode.replace("options", optionsNode.get("options")); String json = HandleAccessor.contentAsString(qdef.rawQuery.getHandle()); JsonNode rawQueryNode = mapper.readTree(json); JsonNode queryNode = rawQueryNode.get("query");
@Override public ServerEvaluationCall xquery(TextWriteHandle xquery) { setContext(Context.ADHOC_XQUERY); code = HandleAccessor.contentAsString(xquery); return this; }
static public HandleImplementation checkHandle(Object object, String type) { if (!isHandle(object)) throw new IllegalArgumentException( type+" handle does not extend BaseHandle: "+object.getClass().getName() ); return ((HandleImplementation) object); } static public boolean isHandle(Object object) {
private void checkContentFormat(Object contentHandle) { checkContentFormat(HandleAccessor.checkHandle(contentHandle, "content")); }
@Override public <T extends RuleListReadHandle> T match(QueryDefinition docQuery, long start, long pageLength, String[] candidateRules, T ruleListHandle, ServerTransform transform) { HandleAccessor.receiveContent(ruleListHandle, services.match(docQuery, start, pageLength, candidateRules, transform)); ; return ruleListHandle; }
private void addPointInTimeQueryParam(RequestParameters params, Object outputHandle) { HandleImplementation handleBase = HandleAccessor.as(outputHandle); if ( params != null && handleBase != null && handleBase.getPointInTimeQueryTimestamp() != -1 ) { logger.trace("param timestamp=[" + handleBase.getPointInTimeQueryTimestamp() + "]"); params.add("timestamp", Long.toString(handleBase.getPointInTimeQueryTimestamp())); } }
type = getJsonType(jsonNode); } else if ( valueObject instanceof AbstractWriteHandle ) { value = HandleAccessor.contentAsString((AbstractWriteHandle) valueObject); HandleImplementation valueBase = HandleAccessor.as((AbstractWriteHandle) valueObject); Format format = valueBase.getFormat();
@Override public ServerEvaluationCall javascript(TextWriteHandle javascript) { setContext(Context.ADHOC_JAVASCRIPT); code = HandleAccessor.contentAsString(javascript); return this; }