@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"); }
@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 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() + ")"); }
@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() + ")"); }
@Override public XQItem createItemFromFloat(float value, XQItemType type) throws XQException { checkState(ex_connection_closed); if (type == null || type.getBaseType() == XQBASETYPE_FLOAT) { return new BagriXQItem(xqProcessor, new BagriXQItemType(XQBASETYPE_FLOAT, XQITEMKIND_ATOMIC, null, getTypeName(XQBASETYPE_FLOAT), false, null), value); } throw new XQException("wrong float type: " + type + "(" + type.getBaseType() + ")"); }
@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"); }
valType = ((XQItem) value).getItemType().getBaseType(); value = ((XQItem) value).getObject(); } catch (XQException 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; }
switch (type.getBaseType()) { case XQBASETYPE_BYTE: if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { return new BagriXQItem(xqProcessor, type, shortVal.byteValue()); throw new XQException("wrong short type: " + type + "(" + type.getBaseType() + ")");
switch (type.getBaseType()) { case XQBASETYPE_BYTE: case XQBASETYPE_SHORT: throw new XQException("wrong byte type: " + type + "(" + type.getBaseType() + ")");
switch (type.getBaseType()) { case XQBASETYPE_BYTE: if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { return new BagriXQItem(xqProcessor, type, intVal.byteValue()); throw new XQException("wrong int type: " + type + "(" + type.getBaseType() + ")");
/** * 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 XQItem createItemFromObject(Object value, XQItemType type) throws XQException { checkState(ex_connection_closed); if (value == null) { throw new XQException("value is null"); } if (type == null) { type = XQUtils.getTypeForObject(this, value); } else { if (!XQUtils.isTypeValueCompatible(type.getBaseType(), value)) { throw new XQException("Value is not compatible"); } } return new BagriXQItem(xqProcessor, type, value); }
@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); }
Number value = null; if(!skipBaseTypes) { int baseType = type.getBaseType(); if(baseType == XQBASETYPE_DOUBLE) { value = Double.valueOf(result.getDouble());
@Override public XQItem createItemFromAtomicValue(String value, XQItemType type) throws XQException { checkState(ex_connection_closed); if (type == null) { throw new XQException("value is null"); } if (value == null) { throw new XQException("type is null"); } if (!isAtomicType(type.getBaseType())) { throw new XQException("type is not atomic"); } if (!((BagriXQItemType) type).isValueCompatible(value)) { throw new XQException("Value is not compatible"); } return new BagriXQItem(xqProcessor, type, value); }
@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); } }
@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()); } }
Object itemValue = null; switch (itemType.getBaseType()) { case XQItemType.XQBASETYPE_BOOLEAN: itemValue = item.getBoolean();
type = createAtomicType(XQBASETYPE_STRING); switch (type.getBaseType()) { case XQBASETYPE_ANYURI: case XQBASETYPE_NOTATION: