@Override public void setContextItemStaticType(XQItemType contextItemType) throws XQException { if (contextItemType == null) { this.type = null; } else { QName typeName = null; if (XQUtils.isBaseTypeSupported(contextItemType.getItemKind())) { typeName = contextItemType.getTypeName(); } else { // ??? } QName nodeName = null; if (XQUtils.isNodeNameSupported(contextItemType.getItemKind())) { nodeName = contextItemType.getNodeName(); } this.type = new BagriXQItemType(contextItemType.getBaseType(), contextItemType.getItemKind(), nodeName, typeName, contextItemType.isElementNillable(), contextItemType.getSchemaURI()); } }
@Override public XQItemType createDocumentSchemaElementType(XQItemType elementType) throws XQException { checkState(ex_connection_closed); return new BagriXQItemType(XQBASETYPE_ANYTYPE, XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT, elementType.getNodeName(), elementType.getTypeName(), elementType.isElementNillable(), elementType.getSchemaURI()); }
@Override public XQItemType createDocumentElementType(XQItemType elementType) throws XQException { checkState(ex_connection_closed); if (elementType == null) { throw new XQException("provided elementType is null"); } if (elementType.getItemKind() != XQITEMKIND_ELEMENT) { throw new XQException("provided elementType has wrong kind: " + elementType); } return new BagriXQItemType(elementType.getBaseType(), XQITEMKIND_DOCUMENT_ELEMENT, elementType.getNodeName(), elementType.getTypeName(), false, null); }
public static BuiltInAtomicType getAtomicType(XQItemType type) throws XQException { int kind = type.getItemKind(); if (XQUtils.isBaseTypeSupported(kind)) { switch (type.getBaseType()) { case XQBASETYPE_ANYATOMICTYPE: return BuiltInAtomicType.ANY_ATOMIC; case XQBASETYPE_ANYSIMPLETYPE: return null;
@Override public float getFloat() throws XQException { checkState(ex_item_closed); if (type.getBaseType() == XQBASETYPE_FLOAT) { return (Float) value; } if (type.getBaseType() == XQBASETYPE_DOUBLE) { return ((Double) value).floatValue(); } throw new XQException("ItemType is not float"); }
if (this.getItemKind() != other.getItemKind()) { return false; if (this.getBaseType() != other.getBaseType()) { return false; if (other.getNodeName() != null) { return false; if (!nodeName.equals(other.getNodeName())) { return false; if (other.getSchemaURI() != null) { return false; if (!schemaURI.equals(other.getSchemaURI())) { return false; if (other.getTypeName() != null) { return false; if (!typeName.equals(other.getTypeName())) { return false; if (isAnonymousType() != other.isAnonymousType()) { return false; if (isElementNillable() != other.isElementNillable()) { return false;
int itemKind = type.getItemKind(); return ( itemKind == XQITEMKIND_ATTRIBUTE
/** * Gets the given text content as String if the type is a string base type * @param type * @param result * @return */ protected String convertToString(XQItemType type,XQResultSequence result) throws XQException { boolean skipBaseTypes = shouldSkipBaseType(type); String value = null; if(!skipBaseTypes) { int baseType = type.getBaseType(); if(baseType == XQBASETYPE_STRING) { value = result.getAtomicValue(); } } else if(XQITEMKIND_TEXT == type.getItemKind()) { value = result.getNode().getTextContent(); } else if(XQITEMKIND_ATTRIBUTE == type.getItemKind()) { value = ((Attr)result.getNode()).getValue(); } return value; }
@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 public Node getNode() throws XQException { checkState(ex_item_closed); switch (type.getItemKind()) { case XQITEMKIND_ATTRIBUTE: case XQITEMKIND_SCHEMA_ATTRIBUTE: return (org.w3c.dom.Attr) value; case XQITEMKIND_COMMENT: return (org.w3c.dom.Comment) value; case XQITEMKIND_DOCUMENT: return (org.w3c.dom.Document) value; case XQITEMKIND_ELEMENT: case XQITEMKIND_DOCUMENT_ELEMENT: case XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT: case XQITEMKIND_SCHEMA_ELEMENT: return (org.w3c.dom.Element) value; case XQITEMKIND_PI: return (org.w3c.dom.ProcessingInstruction) value; case XQITEMKIND_TEXT: return (org.w3c.dom.Text) value; default: throw new XQException("ItemType is not Node: " + value.getClass().getName()); } }
@Override public void write(ObjectDataOutput out, XQItemType type) throws IOException { try { int kind = type.getItemKind(); out.writeInt(kind); if (isBaseTypeSupported(kind)) { out.writeInt(type.getBaseType()); //out.writeObject(type.getTypeName()); writeQName(out, type.getTypeName()); } if (isNodeNameSupported(kind)) { // || isPINameSupported(kind)) { //out.writeObject(type.getNodeName()); // can be issues with wildcards writeQName(out, type.getNodeName()); } if (type.getSchemaURI() == null) { out.writeBoolean(false); } else { out.writeBoolean(true); out.writeUTF(type.getSchemaURI().toString()); } out.writeBoolean(type.isElementNillable()); } catch (XQException ex) { throw new IOException(ex); } }
/** * Checks the data type of the string and converts to boolean if applicable. * The types have to be either boolean or string. For a string value, * the returned value is same as Boolean.valueOf(strValue) * * @param type * @param result * @return */ protected Boolean convertToBoolean(XQItemType type,XQResultSequence result) throws XQException { boolean skipBaseTypes = shouldSkipBaseType(type); Boolean value = null; if(!skipBaseTypes) { if(type.getBaseType() == XQBASETYPE_BOOLEAN) { value = Boolean.valueOf(result.getBoolean()); } else if(type.getBaseType() == XQBASETYPE_STRING) { value = Boolean.valueOf(result.getAtomicValue()); } } else if(XQITEMKIND_TEXT == type.getItemKind()) { String textContent = result.getNode().getTextContent(); value = Boolean.valueOf(textContent); } else if(XQITEMKIND_ATTRIBUTE == type.getItemKind()) { String textContent = ((Attr)result.getNode()).getValue(); value = Boolean.valueOf(textContent); } return value; }
@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() + ")"); }
public static Item convertXQItem(XQItem xqItem, Configuration config) throws XQException, XPathException { BuiltInAtomicType type = getAtomicType(xqItem.getItemType()); if (type == null) { return convertToItem(xqItem.getObject(), config, xqItem.getItemType().getItemKind()); } return convertToAtomicItem(xqItem.getObject(), config, type); }
Number value = null; if(!skipBaseTypes) { int baseType = type.getBaseType(); if(baseType == XQBASETYPE_DOUBLE) { value = Double.valueOf(result.getDouble()); else if(XQITEMKIND_TEXT == type.getItemKind()) { String textContent = result.getNode().getTextContent(); value = convertStringToNumber(textContent); else if(XQITEMKIND_ATTRIBUTE == type.getItemKind()) { String textContent = ((Attr)result.getNode()).getValue(); value = convertStringToNumber(textContent);
@Override public boolean getBoolean() throws XQException { checkState(ex_item_closed); if (type == null) { throw new XQException("ItemType is null"); } if (type.getBaseType() == XQBASETYPE_BOOLEAN) { return (Boolean) value; } throw new XQException("ItemType is not boolean"); }
@Override public XQItem createItemFromDocument(String value, String baseURI, XQItemType type) throws XQException { checkState(ex_connection_closed); if (value == null) { throw new XQException("value is null"); } // do not delete this line. it'll throw exception // in case when value contains wrong XML try { XMLUtils.textToDocument(value); } catch (IOException ex) { throw new XQException(ex.getMessage()); } if (type == null) { return new BagriXQItem(xqProcessor, createDocumentElementType(createElementType(null, XQBASETYPE_UNTYPED)), value); } else { int kind = type.getItemKind(); if (kind == XQITEMKIND_DOCUMENT || kind == XQITEMKIND_DOCUMENT_ELEMENT || kind == XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT) { return new BagriXQItem(xqProcessor, type, value); } } throw new XQException("wrong document type: " + type); }
switch (type.getItemKind()) { case XQITEMKIND_ATOMIC: { int bType = type.getBaseType(); switch (bType) { case XQBASETYPE_ANYURI:
@Override public XQItem createItemFromDouble(double value, XQItemType type) throws XQException { checkState(ex_connection_closed); if (type == null || type.getBaseType() == XQBASETYPE_DOUBLE) { return new BagriXQItem(xqProcessor, new BagriXQItemType(XQBASETYPE_DOUBLE, XQITEMKIND_ATOMIC, null, getTypeName(XQBASETYPE_DOUBLE), false, null), value); } throw new XQException("wrong double type: " + type + "(" + type.getBaseType() + ")"); }
logger.trace("write; got type: {}", type); if (XQUtils.isBaseTypeSupported(type.getItemKind())) { int bType = type.getBaseType(); if (XQUtils.isAtomicType(bType)) { switch (bType) { switch (type.getItemKind()) { case XQITEMKIND_DOCUMENT: case XQITEMKIND_DOCUMENT_ELEMENT: logger.info("write; wrong item kind: {}, writing as is", type.getItemKind()); out.writeObject(item.getObject());