@Override public void setDefaultElementTypeNamespace(String uri) throws XQException { if (uri == null) { throw new XQException("Default element type namespace URI is null"); } defaultElementTypeNamespace = uri; }
@Override public void setDefaultCollation(String uri) throws XQException { if (uri == null) { throw new XQException("Default collation URI is null"); } this.defaultCollationUri = uri; }
@Override public void setQueryLanguageTypeAndVersion(int langType) throws XQException { if (langType != LANGTYPE_XQUERY && langType != LANGTYPE_XQUERYX) { throw new XQException("Wrong language type and version value: " + langType); } // we do not support XQueryX, don't see how it can be set.. this.queryLanguageTypeAndVersion = langType; }
@Override public void setQueryTimeout(int seconds) throws XQException { if (seconds < 0) { throw new XQException("Wrong query timeout value: " + seconds); } this.queryTimeout = seconds; }
protected void checkAccess(boolean checkPosition) throws XQException { if (checkPosition && !positioned) { throw new XQException("Not positioned on an Item"); } if (accessed) { throw new XQException("Item has been already accessed"); } }
private XQItemAccessor getBoundItem(Map<String, Object> bindings, String varName) throws XQException { if (bindings.size() == 0) { throw new XQException("bindings not provided"); } XQItemAccessor item = (XQItemAccessor) bindings.get(varName); if (item == null) { throw new XQException("variable '" + varName + "' not bound"); } return item; }
@Override public int getBaseType() throws XQException { if (XQUtils.isBaseTypeSupported(kind)) { return baseType; } throw new XQException("getBaseType is not supported for this item kind: " + kind); }
@Override public String getPIName() throws XQException { if (XQUtils.isPINameSupported(kind)) { if (nodeName != null) { return nodeName.getLocalPart(); } return null; } throw new XQException("getPIName is not supported for this item kind: " + kind); }
@Override public void writeSequence(Writer ow, Properties props) throws XQException { checkState(ex_sequence_closed); if (ow == null) { throw new XQException("Provided Writer is null"); } try { ow.write(getSequenceAsString(props)); } catch (IOException ex) { throw new XQException(ex.getMessage()); } }
void checkState(String error) throws XQException { if (isClosed()) { throw new XQException(error); } }
public static void main(String[] args) throws Exception { if (args.length < 4) { throw new XQException("wrong number of arguments passed. Expected: schemaAddress schemaName userName password"); } Properties props = new Properties(); props.setProperty(pn_schema_address, args[0]); props.setProperty(pn_schema_name, args[1]); props.setProperty(pn_schema_user, args[2]); props.setProperty(pn_schema_password, args[3]); XQJClientApp client = new XQJClientApp(props); tester.testClient(client); }
@Override public void writeSequenceToResult(Result result) throws XQException { checkState(ex_sequence_closed); if (result == null) { throw new XQException("Provided Result is null"); } try { XMLUtils.stringToResult(getSequenceAsString(null), result); } catch (IOException ex) { throw new XQException(ex.getMessage()); } }
@Override public void writeItemToResult(Result result) throws XQException { checkState(ex_item_closed); if (result == null) { throw new XQException("Provided Result is null"); } try { XMLUtils.stringToResult(getItemAsString(null), result); } catch (IOException ex) { throw new XQException(ex.getMessage()); } }
@Override public XQItemType createAttributeType(QName nodeName, int baseType, QName typeName, URI schemaURI) throws XQException { checkState(ex_connection_closed); if (baseType == XQBASETYPE_UNTYPED || baseType == XQBASETYPE_ANYTYPE) { throw new XQException("Wrong base type: " + baseType); } return new BagriXQItemType(baseType, XQITEMKIND_ATTRIBUTE, nodeName, typeName, false, schemaURI); }
@Override public XQExpression createExpression(XQStaticContext context) throws XQException { checkState(ex_connection_closed); if (context == null) { throw new XQException(ex_null_context); } return new BagriXQExpression(this, context); }
@Override public XMLStreamReader getSequenceAsStream() throws XQException { checkState(ex_sequence_closed); try { return XMLUtils.stringToStream(getSequenceAsString(null)); } catch (IOException ex) { throw new XQException(ex.getMessage()); } }
@Override public double getDouble() throws XQException { checkState(ex_item_closed); if (type.getBaseType() == XQBASETYPE_DOUBLE) { return (Double) value; } if (type.getBaseType() == XQBASETYPE_FLOAT) { return ((Float) value).doubleValue(); } throw new XQException("ItemType is not double"); }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public XQSequence createSequence(Iterator itr) throws XQException { checkState(ex_connection_closed); if (itr == null) { throw new XQException("Iterator is null"); } // shouldn't we check processor props to know type of sequence? return new ScrollableXQSequence(this, xqProcessor, copyIterator(itr)); //return new IterableXQSequence(this, xqProcessor, itr); }
@Override public void executeCommand(String cmd) throws XQException { checkState(ex_expression_closed); if (cmd == null) { throw new XQException("Provided command is null"); } connection.executeCommand(cmd, getBindings()); }
@Override public XQItem createItemFromBoolean(boolean value, XQItemType type) throws XQException { checkState(ex_connection_closed); if (type == null || type.getBaseType() == XQBASETYPE_BOOLEAN) { return new BagriXQItem(xqProcessor, new BagriXQItemType(XQBASETYPE_BOOLEAN, XQITEMKIND_ATOMIC, null, getTypeName(XQBASETYPE_BOOLEAN), false, null), value); } throw new XQException("wrong boolean type: " + type + "(" + type.getBaseType() + ")"); }