Support json-item types
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml b/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
index e89d619..e28d405 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
+++ b/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
@@ -856,14 +856,14 @@
<!-- opext:array-constructor($expression as item()*) as array() -->
<operator name="opext:array-constructor">
<param name="expression" type="item()*"/>
- <return type="item()"/>
+ <return type="array()"/>
<runtime type="scalar" class="org.apache.vxquery.runtime.functions.jsonitem.ArrayConstructorScalarEvaluatorFactory"/>
</operator>
<!-- opext:object-constructor($expression as item()*) as object() -->
<operator name="opext:object-constructor">
<param name="expression" type="item()*"/>
- <return type="item()"/>
+ <return type="object()"/>
<runtime type="scalar" class="org.apache.vxquery.runtime.functions.jsonitem.ObjectConstructorScalarEvaluatorFactory"/>
</operator>
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/AbstractJsonItemType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/AbstractJsonItemType.java
new file mode 100644
index 0000000..c890d4d
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/AbstractJsonItemType.java
@@ -0,0 +1,26 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.vxquery.types;
+
+abstract class AbstractJsonItemType implements JsonItemType {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public final boolean isAtomicType() {
+ return false;
+ }
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/AnyJsonItemType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/AnyJsonItemType.java
new file mode 100644
index 0000000..6b367ba
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/AnyJsonItemType.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.types;
+
+public final class AnyJsonItemType extends AbstractJsonItemType {
+ private static final long serialVersionUID = 1L;
+ public static final AnyJsonItemType INSTANCE = new AnyJsonItemType();
+
+ private AnyJsonItemType() {
+ }
+
+ @Override
+ public String toString() {
+ return "json-item";
+ }
+
+ @Override
+ public int hashCode() {
+ return AnyJsonItemType.class.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return other instanceof AnyJsonItemType;
+ }
+
+ @Override
+ public JsonItemKind getJsonItemKind() {
+ return JsonItemKind.ANY;
+ }
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/ArrayType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/ArrayType.java
new file mode 100644
index 0000000..5108f32
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/ArrayType.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.types;
+
+public final class ArrayType extends AbstractJsonItemType {
+ private static final long serialVersionUID = 1L;
+
+ public static final ArrayType INSTANCE = new ArrayType();
+
+ @Override
+ public int hashCode() {
+ return ArrayType.class.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return other instanceof ArrayType;
+ }
+
+ @Override
+ public String toString() {
+ return "array";
+ }
+
+ @Override
+ public JsonItemKind getJsonItemKind() {
+ return JsonItemKind.ARRAY;
+ }
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeQNames.java b/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeQNames.java
index 9f762ff..ec2163e 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeQNames.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeQNames.java
@@ -125,4 +125,6 @@
XQueryConstants.XS_PREFIX);
public static final QName XSEXT_TYPE_TYPE_QNAME = new QName(XQueryConstants.XSEXT_NSURI, "type",
XQueryConstants.XSEXT_PREFIX);
+ public static final QName JS_NULL_TYPE_QNAME = new QName(XQueryConstants.JS_NSURI, "null",
+ XQueryConstants.JS_PREFIX);
}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java b/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
index 29bb5e2..ab4f627 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
@@ -219,6 +219,7 @@
types[BuiltinTypeConstants.XS_ANY_URI_TYPE_ID] = XS_ANY_URI;
types[BuiltinTypeConstants.XS_QNAME_TYPE_ID] = XS_QNAME;
types[BuiltinTypeConstants.XS_NOTATION_TYPE_ID] = XS_NOTATION;
+ types[BuiltinTypeConstants.JS_NULL_TYPE_ID] = JS_NULL;
typeNames = new QName[BuiltinTypeConstants.BUILTIN_TYPE_COUNT];
typeNames[BuiltinTypeConstants.XS_ANY_TYPE_ID] = BuiltinTypeQNames.XS_ANY_TYPE_QNAME;
@@ -270,6 +271,7 @@
typeNames[BuiltinTypeConstants.XS_ANY_URI_TYPE_ID] = BuiltinTypeQNames.XS_ANY_URI_TYPE_QNAME;
typeNames[BuiltinTypeConstants.XS_QNAME_TYPE_ID] = BuiltinTypeQNames.XS_QNAME_TYPE_QNAME;
typeNames[BuiltinTypeConstants.XS_NOTATION_TYPE_ID] = BuiltinTypeQNames.XS_NOTATION_TYPE_QNAME;
+ typeNames[BuiltinTypeConstants.JS_NULL_TYPE_ID] = BuiltinTypeQNames.JS_NULL_TYPE_QNAME;
}
public SchemaType getSchemaTypeById(int id) {
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/JsonItemKind.java b/vxquery-core/src/main/java/org/apache/vxquery/types/JsonItemKind.java
new file mode 100644
index 0000000..0af2811
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/JsonItemKind.java
@@ -0,0 +1,23 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.vxquery.types;
+
+public enum JsonItemKind {
+ ANY,
+ OBJECT,
+ ARRAY
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/JsonItemType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/JsonItemType.java
new file mode 100644
index 0000000..f06eebc
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/JsonItemType.java
@@ -0,0 +1,21 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.vxquery.types;
+
+public interface JsonItemType extends StructuredItemType {
+ public JsonItemKind getJsonItemKind();
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/NodeType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/NodeType.java
index cd43f97..ef4ba7d 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/NodeType.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/NodeType.java
@@ -16,6 +16,6 @@
*/
package org.apache.vxquery.types;
-public interface NodeType extends ItemType {
+public interface NodeType extends StructuredItemType {
public NodeKind getNodeKind();
}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/ObjectType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/ObjectType.java
new file mode 100644
index 0000000..b61f3b4
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/ObjectType.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.types;
+
+public final class ObjectType extends AbstractJsonItemType {
+ private static final long serialVersionUID = 1L;
+
+ public static final ObjectType INSTANCE = new ObjectType();
+
+ @Override
+ public int hashCode() {
+ return ObjectType.class.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return other instanceof ObjectType;
+ }
+
+ @Override
+ public JsonItemKind getJsonItemKind() {
+ return JsonItemKind.OBJECT;
+ }
+
+ @Override
+ public String toString() {
+ return "object";
+ }
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
index 2986a8c..0066967 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/SequenceType.java
@@ -30,7 +30,7 @@
private Quantifier quantifier;
static {
- Map<ItemType, SequenceType[]> types = new LinkedHashMap<ItemType, SequenceType[]>();
+ Map<ItemType, SequenceType[]> types = new LinkedHashMap<>();
createBuiltinEntry(types, BuiltinTypeRegistry.XS_ANY_ATOMIC);
createBuiltinEntry(types, BuiltinTypeRegistry.XS_STRING);
@@ -79,6 +79,7 @@
createBuiltinEntry(types, BuiltinTypeRegistry.XS_ANY_URI);
createBuiltinEntry(types, BuiltinTypeRegistry.XS_QNAME);
createBuiltinEntry(types, BuiltinTypeRegistry.XS_NOTATION);
+ createBuiltinEntry(types, BuiltinTypeRegistry.JS_NULL);
createBuiltinEntry(types, AnyItemType.INSTANCE);
createBuiltinEntry(types, AnyNodeType.INSTANCE);
@@ -88,14 +89,24 @@
createBuiltinEntry(types, CommentType.INSTANCE);
createBuiltinEntry(types, ProcessingInstructionType.ANYPI);
+ createBuiltinEntry(types, ArrayType.INSTANCE);
+ createBuiltinEntry(types, ObjectType.INSTANCE);
+
BUILTIN_SEQ_TYPES = Collections.unmodifiableMap(types);
}
+ private SequenceType(ItemType itemType, Quantifier quantifier) {
+ this.itemType = itemType;
+ this.quantifier = quantifier;
+ }
+
private static void createBuiltinEntry(Map<ItemType, SequenceType[]> types, ItemType itemType) {
- types.put(itemType, new SequenceType[] { new SequenceType(itemType, Quantifier.QUANT_ZERO),
- new SequenceType(itemType, Quantifier.QUANT_ONE),
- new SequenceType(itemType, Quantifier.QUANT_QUESTION),
- new SequenceType(itemType, Quantifier.QUANT_STAR), new SequenceType(itemType, Quantifier.QUANT_PLUS), });
+ types.put(itemType,
+ new SequenceType[] { new SequenceType(itemType, Quantifier.QUANT_ZERO),
+ new SequenceType(itemType, Quantifier.QUANT_ONE),
+ new SequenceType(itemType, Quantifier.QUANT_QUESTION),
+ new SequenceType(itemType, Quantifier.QUANT_STAR),
+ new SequenceType(itemType, Quantifier.QUANT_PLUS), });
}
public static SequenceType create(ItemType itemType, Quantifier quantifier) {
@@ -106,11 +117,6 @@
return types[quantifier.ordinal()];
}
- private SequenceType(ItemType itemType, Quantifier quantifier) {
- this.itemType = itemType;
- this.quantifier = quantifier;
- }
-
public ItemType getItemType() {
return itemType;
}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/StructuredItemType.java b/vxquery-core/src/main/java/org/apache/vxquery/types/StructuredItemType.java
new file mode 100644
index 0000000..eb8a0af
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/StructuredItemType.java
@@ -0,0 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.vxquery.types;
+
+public interface StructuredItemType extends ItemType {
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/types/TypeUtils.java b/vxquery-core/src/main/java/org/apache/vxquery/types/TypeUtils.java
index f76a423..6dfa677 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/types/TypeUtils.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/types/TypeUtils.java
@@ -26,8 +26,8 @@
return createSequenceType(RootStaticContextImpl.INSTANCE, str);
}
- public static SequenceType createSequenceType(StaticContext sCtx, String str) {
- str = str.trim();
+ public static SequenceType createSequenceType(StaticContext sCtx, String s) {
+ String str = s.trim();
Quantifier q = Quantifier.QUANT_ONE;
if (str.endsWith("?")) {
q = Quantifier.QUANT_QUESTION;
@@ -43,6 +43,12 @@
ItemType it;
if (str.equals("item()")) {
it = AnyItemType.INSTANCE;
+ } else if (str.equals("json-item()")) {
+ it = AnyJsonItemType.INSTANCE;
+ } else if (str.equals("object()")) {
+ it = ObjectType.INSTANCE;
+ } else if (str.equals("array()")) {
+ it = ArrayType.INSTANCE;
} else if (str.equals("node()")) {
it = AnyNodeType.INSTANCE;
} else if (str.equals("document-node()")) {
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XQueryConstants.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XQueryConstants.java
index d8fdf94..29b9bcb 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XQueryConstants.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XQueryConstants.java
@@ -36,13 +36,31 @@
public static final String LOCAL_NSURI = "http://www.w3.org/2005/xquery-local-functions";
public static final String ERR_NSURI = "http://www.w3.org/2005/xqt-errors";
-
+
public static final String OP_PREFIX = "op";
public static final String OP_NSURI = "urn:org.apache.vxquery.operators";
public static final String OPEXT_PREFIX = "opext";
public static final String OPEXT_NSURI = "urn:org.apache.vxquery.operators-ext";
+ public static final String JS_PREFIX = "js";
+ public static final String JS_NSURI = "http://jsoniq.org/types";
+
+ public static final String JN_PREFIX = "jn";
+ public static final String JN_NSURI = "http://jsoniq.org/functions";
+
+ public static final String LIBJN_PREFIX = "libjn";
+ public static final String LIBJN_NSURI = "http://jsoniq.org/function-library";
+
+ public static final String JERR_PREFIX = "jerr";
+ public static final String JERR_NSURI = "http://jsoniq.org/errors";
+
+ public static final String JUPD_PREFIX = "jupd";
+ public static final String JUPD_NSURI = "http://jsoniq.org/updates";
+
+ public static final String JDM_PREFIX = "jdm";
+ public static final String JDM_NSURI = "urn:org.apache.vxquery.jsoniq-data-model";
+
private XQueryConstants() {
}
@@ -57,7 +75,7 @@
public enum TypeQuantifier {
QUANT_QUESTION, QUANT_STAR, QUANT_PLUS
}
-
+
public enum PathType {
SLASH,
SLASH_SLASH,