static public <R extends AbstractReadHandle> Class<R> receiveAs(R handle) { if (handle == null) return null; return ((HandleImplementation) handle).receiveAs(); } static public <R extends AbstractReadHandle> void receiveContent(R handle, Object content) {
static public <R extends AbstractReadHandle> Class<R> receiveAs(R handle) { if (handle == null) return null; return ((HandleImplementation) handle).receiveAs(); } static public <R extends AbstractReadHandle> void receiveContent(R handle, Object content) {
private <T extends AbstractReadHandle> T readTransform( String transformName, String sourceMimetype, T sourceHandle) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { if (transformName == null) throw new IllegalArgumentException("Reading transform with null name"); if (logger.isInfoEnabled()) logger.info("Reading transform source for {}", transformName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "transform"); sourceBase.receiveContent( services.getValue(requestLogger, "config/transforms", transformName, true, sourceMimetype, sourceBase.receiveAs()) ); return sourceHandle; }
@Override public <T extends TextReadHandle> T readServices(String resourceName, T sourceHandle) { if (resourceName == null) throw new IllegalArgumentException("Reading resource services source with null name"); if (logger.isInfoEnabled()) logger.info("Reading resource services source for {}", resourceName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "resource"); sourceBase.receiveContent( services.getValue(requestLogger, "config/resources", resourceName, true, "application/xquery", sourceBase.receiveAs()) ); return sourceHandle; }
@SuppressWarnings("unchecked") @Override public String[] suggest(SuggestDefinition suggestDef) { DOMHandle handle = new DOMHandle(); @SuppressWarnings("rawtypes") HandleImplementation suggestBase = HandleAccessor.checkHandle(handle, "suggest"); suggestBase.receiveContent(services.suggest(suggestBase.receiveAs(), suggestDef)); Document doc = handle.get(); NodeList nodeList = doc.getDocumentElement().getChildNodes(); List<String> suggestions = new ArrayList<String>(); for (int i=0; i <nodeList.getLength(); i++) { suggestions.add(nodeList.item(i).getTextContent()); } return suggestions.toArray(new String[suggestions.size()]); }
@SuppressWarnings("unchecked") @Override public String[] suggest(SuggestDefinition suggestDef) { DOMHandle handle = new DOMHandle(); @SuppressWarnings("rawtypes") HandleImplementation suggestBase = HandleAccessor.checkHandle(handle, "suggest"); suggestBase.receiveContent(services.suggest(suggestBase.receiveAs(), suggestDef)); Document doc = handle.get(); NodeList nodeList = doc.getDocumentElement().getChildNodes(); List<String> suggestions = new ArrayList<>(); for (int i=0; i <nodeList.getLength(); i++) { suggestions.add(nodeList.item(i).getTextContent()); } return suggestions.toArray(new String[suggestions.size()]); }
private <T extends AbstractReadHandle> T readTransform( String transformName, String sourceMimetype, T sourceHandle) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { if (transformName == null) throw new IllegalArgumentException("Reading transform with null name"); if (logger.isInfoEnabled()) logger.info("Reading transform source for {}", transformName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "transform"); sourceBase.receiveContent( services.getValue(requestLogger, "config/transforms", transformName, true, sourceMimetype, sourceBase.receiveAs()) ); return sourceHandle; }
@Override public <T extends TextReadHandle> T readServices(String resourceName, T sourceHandle) { if (resourceName == null) throw new IllegalArgumentException("Reading resource services source with null name"); if (logger.isInfoEnabled()) logger.info("Reading resource services source for {}", resourceName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "resource"); sourceBase.receiveContent( services.getValue(requestLogger, "config/resources", resourceName, true, sourceBase.getMimetype(), sourceBase.receiveAs()) ); return sourceHandle; }
@Override public <T extends StructureReadHandle> T listServices(T listHandle, boolean refresh) { if (listHandle == null) throw new IllegalArgumentException("null handle for listing resource services"); if (logger.isInfoEnabled()) logger.info("Reading resource services list"); HandleImplementation listBase = HandleAccessor.checkHandle(listHandle, "resource"); Format listFormat = listBase.getFormat(); if (!(Format.JSON == listFormat || Format.XML == listFormat)) throw new IllegalArgumentException( "list handle for unsupported format: "+listFormat.getClass().getName()); RequestParameters extraParams = null; if (!refresh) { extraParams = new RequestParameters(); extraParams.put("refresh", "false"); } listBase.receiveContent( services.getValues(requestLogger, "config/resources", extraParams, listFormat.getDefaultMimetype(), listBase.receiveAs()) ); return listHandle; }
@SuppressWarnings("unchecked") public static <T extends AbstractReadHandle> T exportTextToHandle( List<XMLEvent> events, T handle ) { if (handle == null) { return null; } @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.checkHandle(handle, "export"); baseHandle.receiveContent( eventTextToObject(events, baseHandle.receiveAs()) ); return handle; } public static Object eventTextToObject(List<XMLEvent> events, Class<?> as) {
@SuppressWarnings("unchecked") public static <T extends AbstractReadHandle> T exportToHandle( List<XMLEvent> events, T handle ) { if (handle == null) { return null; } @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.checkHandle(handle, "export"); baseHandle.receiveContent( eventsToObject(events, baseHandle.receiveAs()) ); return handle; } public static Object eventsToObject(List<XMLEvent> events, Class<?> as) {
@SuppressWarnings("unchecked") public static <T extends AbstractReadHandle> T exportToHandle( List<XMLEvent> events, T handle ) { if (handle == null) { return null; } @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.checkHandle(handle, "export"); baseHandle.receiveContent( eventsToObject(events, baseHandle.receiveAs()) ); return handle; } public static Object eventsToObject(List<XMLEvent> events, Class<?> as) {
public <R extends AbstractReadHandle> R getContent(R handle) { if (part == null) throw new IllegalStateException("Content already retrieved"); HandleImplementation handleBase = HandleAccessor.as(handle); extractHeaders(); updateFormat(handleBase, format); updateMimetype(handleBase, mimetype); updateLength(handleBase, length); try { Object contentEntity = getEntity(part, handleBase.receiveAs()); handleBase.receiveContent((reqlog != null) ? reqlog.copyContent(contentEntity) : contentEntity); return handle; } finally { part = null; reqlog = null; } }
@SuppressWarnings("unchecked") public static <T extends AbstractReadHandle> T exportTextToHandle( List<XMLEvent> events, T handle ) { if (handle == null) { return null; } @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.checkHandle(handle, "export"); baseHandle.receiveContent( eventTextToObject(events, baseHandle.receiveAs()) ); return handle; } public static Object eventTextToObject(List<XMLEvent> events, Class<?> as) {
@Override public <R extends AbstractReadHandle> R getContent(R handle) { if (part == null) throw new IllegalStateException("Content already retrieved"); HandleImplementation handleBase = HandleAccessor.as(handle); extractHeaders(); updateFormat(handleBase, format); updateMimetype(handleBase, mimetype); updateLength(handleBase, length); Object contentEntity = part.getEntityAs(handleBase.receiveAs()); handleBase.receiveContent((reqlog != null) ? reqlog .copyContent(contentEntity) : contentEntity); part = null; reqlog = null; return handle; }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public <T extends StructureReadHandle> T readStatus(T handle) throws ForbiddenUserException, FailedRequestException { if (handle == null) throw new IllegalArgumentException("reading transaction status with null handle"); HandleImplementation handleBase = HandleAccessor.checkHandle(handle, "structure"); handleBase.receiveContent( services.getValue( null, "transactions", getTransactionId(), false, handleBase.getMimetype(), handleBase.receiveAs() ) ); return handle; }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public <T extends StructureReadHandle> T readStatus(T handle) throws ForbiddenUserException, FailedRequestException { if (handle == null) throw new IllegalArgumentException("reading transaction status with null handle"); HandleImplementation handleBase = HandleAccessor.checkHandle(handle, "structure"); handleBase.receiveContent( services.getValue( null, "transactions", getTransactionId(), this, false, handleBase.getMimetype(), handleBase.receiveAs() ) ); return handle; }
@SuppressWarnings("unchecked") @Override public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation optionsBase = HandleAccessor.checkHandle(optionsHandle, "optionslist"); Format optionsFormat = optionsBase.getFormat(); switch(optionsFormat) { case UNKNOWN: optionsFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON options list results are possible."); } String mimetype = optionsFormat.getDefaultMimetype(); String tid = transaction == null ? null : transaction.getTransactionId(); optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, transaction)); return optionsHandle; }
@SuppressWarnings("unchecked") @Override public <T extends ValuesListReadHandle> T valuesList(ValuesListDefinition valdef, T valuesHandle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation valuesBase = HandleAccessor.checkHandle(valuesHandle, "valueslist"); Format valuesFormat = valuesBase.getFormat(); switch(valuesFormat) { case UNKNOWN: valuesFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON values list results are possible."); } String mimetype = valuesFormat.getDefaultMimetype(); String tid = transaction == null ? null : transaction.getTransactionId(); valuesBase.receiveContent(services.valuesList(valuesBase.receiveAs(), valdef, mimetype, tid)); return valuesHandle; }
@SuppressWarnings("unchecked") @Override public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation optionsBase = HandleAccessor.checkHandle(optionsHandle, "optionslist"); Format optionsFormat = optionsBase.getFormat(); switch(optionsFormat) { case UNKNOWN: optionsFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON options list results are possible."); } String mimetype = optionsFormat.getDefaultMimetype(); String tid = transaction == null ? null : transaction.getTransactionId(); optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, tid)); return optionsHandle; }