diff --git a/README.md b/README.md index 817dc92..98b2c5c 100644 --- a/README.md +++ b/README.md @@ -464,7 +464,7 @@ This repository only contains the source code for the package. ### Set up the prerequisites -1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). +1. Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations). * [Oracle](https://www.oracle.com/java/technologies/downloads/) * [OpenJDK](https://adoptium.net/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 65c2357..143368a 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "data.xmldata" -version = "1.0.0" +version = "1.0.1" authors = ["Ballerina"] keywords = ["xml"] repository = "https://github.com/ballerina-platform/module-ballerina-data-xmldata" @@ -9,14 +9,14 @@ license = ["Apache-2.0"] distribution = "2201.10.0" export = ["data.xmldata"] -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "data-native" -version = "1.0.0" -path = "../native/build/libs/data.xmldata-native-1.0.0.jar" +version = "1.0.1" +path = "../native/build/libs/data.xmldata-native-1.0.1-SNAPSHOT.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" -version = "1.5.0" -path = "./lib/constraint-native-1.5.0.jar" +version = "1.6.0" +path = "./lib/constraint-native-1.6.0-20241113-090900-d276ad5.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 1669a30..d69411d 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "constraint-compiler-plugin" class = "io.ballerina.lib.data.xmldata.compiler.XmldataCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/data.xmldata-compiler-plugin-1.0.0.jar" +path = "../compiler-plugin/build/libs/data.xmldata-compiler-plugin-1.0.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 81e9251..aed09f8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.11.0-20241112-214900-6b80ab87" [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.6.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -22,7 +22,7 @@ modules = [ [[package]] org = "ballerina" name = "data.xmldata" -version = "1.0.0" +version = "1.0.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "io"}, @@ -116,7 +116,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.1" +version = "2.6.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index e881ae9..6f8db8a 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,13 +9,13 @@ license = ["Apache-2.0"] distribution = "2201.10.0" export = ["data.xmldata"] -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "data-native" version = "@toml.version@" path = "../native/build/libs/data.xmldata-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" version = "@constraint.version@" diff --git a/compiler-plugin-test/build.gradle b/compiler-plugin-test/build.gradle index 6a96468..ec3b0a1 100644 --- a/compiler-plugin-test/build.gradle +++ b/compiler-plugin-test/build.gradle @@ -49,8 +49,11 @@ checkstyle { checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsTest { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/compiler-plugin/build.gradle b/compiler-plugin/build.gradle index 78ae721..7192800 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -47,8 +47,11 @@ checkstyle { checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsMain { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/gradle.properties b/gradle.properties index f92a9e9..91d43e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ org.gradle.caching=true group=io.ballerina.lib version=1.0.1-SNAPSHOT -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 checkstyleToolVersion=10.12.0 puppycrawlCheckstyleVersion=10.12.0 testngVersion=7.6.1 slf4jVersion=2.0.7 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 githubJohnrengelmanShadowVersion=8.1.1 underCouchDownloadVersion=4.0.4 researchgateReleaseVersion=2.8.0 ballerinaGradlePluginVersion=2.0.1 -stdlibIoVersion=1.6.1 -stdlibTimeVersion=2.4.0 -stdlibConstraintVersion=1.5.0 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibTimeVersion=2.6.0-20241113-073800-201b904 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 diff --git a/native/build.gradle b/native/build.gradle index ceb83f2..8398a3a 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -51,9 +51,12 @@ tasks.withType(Checkstyle) { } spotbugsMain { - enabled=false - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + enabled = false + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java b/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java index d48b942..57d3a2f 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java @@ -20,12 +20,12 @@ import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.ReferenceType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BDecimal; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java index 4811f56..9a076a0 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java @@ -21,10 +21,7 @@ import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.async.StrandMetadata; import io.ballerina.runtime.api.types.MethodType; -import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; @@ -34,10 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; /** * Java Input Stream based on Ballerina byte block stream. stream @@ -49,28 +43,19 @@ public class BallerinaByteBlockInputStream extends InputStream { private final BObject iterator; private final Environment env; private final String nextMethodName; - private final Type returnType; - private final String strandName; - private final StrandMetadata metadata; - private final Map properties; private final AtomicBoolean done = new AtomicBoolean(false); private final MethodType closeMethod; - private final Consumer futureResultConsumer; + private BError error = null; private byte[] currentChunk = new byte[0]; private int nextChunkIndex = 0; public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodType nextMethod, - MethodType closeMethod, Consumer futureResultConsumer) { + MethodType closeMethod) { this.env = env; this.iterator = iterator; this.nextMethodName = nextMethod.getName(); - this.returnType = nextMethod.getReturnType(); this.closeMethod = closeMethod; - this.strandName = env.getStrandName().orElse(""); - this.metadata = env.getStrandMetadata(); - this.properties = Map.of(); - this.futureResultConsumer = futureResultConsumer; } @Override @@ -88,8 +73,7 @@ public int read() { return read(); } } catch (InterruptedException e) { - BError error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); - futureResultConsumer.accept(error); + this.error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); return -1; } return -1; @@ -98,25 +82,8 @@ public int read() { @Override public void close() throws IOException { super.close(); - Semaphore semaphore = new Semaphore(0); if (closeMethod != null) { - env.getRuntime().invokeMethodAsyncSequentially(iterator, closeMethod.getName(), strandName, metadata, - new Callback() { - @Override - public void notifyFailure(BError bError) { - semaphore.release(); - } - - @Override - public void notifySuccess(Object result) { - semaphore.release(); - } - }, properties, returnType); - } - try { - semaphore.acquire(); - } catch (InterruptedException e) { - throw new IOException("Error while closing the stream", e); + env.getRuntime().callMethod(iterator, closeMethod.getName(), null); } } @@ -125,44 +92,28 @@ private boolean hasBytesInCurrentChunk() { } private boolean readNextChunk() throws InterruptedException { - Semaphore semaphore = new Semaphore(0); - Callback callback = new Callback() { - - @Override - public void notifyFailure(BError bError) { - // Panic with an error + try { + Object result = env.getRuntime().callMethod(iterator, nextMethodName, null); + if (result == null) { done.set(true); - futureResultConsumer.accept(bError); - currentChunk = new byte[0]; - semaphore.release(); - // TODO : Should we panic here? + return true; } - - @Override - public void notifySuccess(Object result) { - if (result == null) { - done.set(true); - currentChunk = new byte[0]; - semaphore.release(); - return; - } - if (result instanceof BMap) { - BMap valueRecord = (BMap) result; - final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get(); - final BArray arrayValue = valueRecord.getArrayValue(value); - currentChunk = arrayValue.getByteArray(); - semaphore.release(); - } else { - // Case where Completes with an error - done.set(true); - semaphore.release(); - } + if (result instanceof BMap) { + BMap valueRecord = (BMap) result; + final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get(); + final BArray arrayValue = valueRecord.getArrayValue(value); + currentChunk = arrayValue.getByteArray(); + } else { + done.set(true); } - - }; - env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback, - properties, returnType); - semaphore.acquire(); + } catch (BError bError) { + done.set(true); + currentChunk = new byte[0]; + } return !done.get(); } + + public BError getError() { + return this.error; + } } diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java deleted file mode 100644 index 126d8ad..0000000 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. 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 io.ballerina.lib.data.xmldata.io; - -import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; -import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.lib.data.xmldata.xml.XmlParser; -import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.types.MethodType; -import io.ballerina.runtime.api.types.ObjectType; -import io.ballerina.runtime.api.utils.TypeUtils; -import io.ballerina.runtime.api.values.BMap; -import io.ballerina.runtime.api.values.BObject; -import io.ballerina.runtime.api.values.BString; -import io.ballerina.runtime.api.values.BTypedesc; - -import java.io.InputStreamReader; -import java.util.function.Consumer; - -/** - * This class will read data from a Ballerina Stream of byte blocks, in non-blocking manner. - * - * @since 0.1.0 - */ -public class DataReaderTask implements Runnable { - - private static final String METHOD_NAME_NEXT = "next"; - private static final String METHOD_NAME_CLOSE = "close"; - - private final Environment env; - private final BObject iteratorObj; - private final Future future; - private final BTypedesc typed; - private final BMap options; - - public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed, - BMap options) { - this.env = env; - this.iteratorObj = iteratorObj; - this.future = future; - this.typed = typed; - this.options = options; - } - - static MethodType resolveNextMethod(BObject iterator) { - MethodType method = getMethodType(iterator, METHOD_NAME_NEXT); - if (method != null) { - return method; - } - throw new IllegalStateException("next method not found in the iterator object"); - } - - static MethodType resolveCloseMethod(BObject iterator) { - return getMethodType(iterator, METHOD_NAME_CLOSE); - } - - private static MethodType getMethodType(BObject iterator, String methodName) { - ObjectType objectType = (ObjectType) TypeUtils.getReferredType(iterator.getOriginalType()); - MethodType[] methods = objectType.getMethods(); - // Assumes compile-time validation of the iterator object - for (MethodType method : methods) { - if (method.getName().equals(methodName)) { - return method; - } - } - return null; - } - - @Override - public void run() { - DataReaderTask.ResultConsumer resultConsumer = new DataReaderTask.ResultConsumer<>(future); - try (var byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, resolveNextMethod(iteratorObj), - resolveCloseMethod(iteratorObj), resultConsumer)) { - Object result = XmlParser.parse(new InputStreamReader(byteBlockSteam), options, typed); - future.complete(result); - } catch (Exception e) { - future.complete(DiagnosticLog.error(DiagnosticErrorCode.STREAM_BROKEN, e.getMessage())); - } - } - - /** - * This class will hold module related utility functions. - * - * @param The type of the result - * @param future The future to complete - * @since 0.1.0 - */ - public record ResultConsumer(Future future) implements Consumer { - - @Override - public void accept(T t) { - future.complete(t); - } - } -} diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java index 791e568..146accc 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java @@ -18,10 +18,10 @@ package io.ballerina.lib.data.xmldata.utils; -import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BXmlItem; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java new file mode 100644 index 0000000..5d289ba --- /dev/null +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. 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 io.ballerina.lib.data.xmldata.utils; + +import io.ballerina.runtime.api.types.MethodType; +import io.ballerina.runtime.api.types.ObjectType; +import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.values.BObject; + +/** + * A class that holds util methods needed for BallerinaByteBlockInputStream class. + * + * @since 2.5.0 + */ +public class DataReader { + + private static final String METHOD_NAME_NEXT = "next"; + private static final String METHOD_NAME_CLOSE = "close"; + + public static MethodType resolveNextMethod(BObject iterator) { + MethodType method = getMethodType(iterator, METHOD_NAME_NEXT); + if (method != null) { + return method; + } + throw new IllegalStateException("next method not found in the iterator object"); + } + + public static MethodType resolveCloseMethod(BObject iterator) { + return getMethodType(iterator, METHOD_NAME_CLOSE); + } + + public static MethodType getMethodType(BObject iterator, String methodName) { + ObjectType objectType = (ObjectType) TypeUtils.getReferredType(iterator.getOriginalType()); + MethodType[] methods = objectType.getMethods(); + // Assumes compile-time validation of the iterator object + for (MethodType method : methods) { + if (method.getName().equals(methodName)) { + return method; + } + } + return null; + } +} diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java index 0a8cd06..78021eb 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java @@ -24,18 +24,18 @@ import io.ballerina.lib.data.xmldata.xml.QualifiedNameMap; import io.ballerina.lib.data.xmldata.xml.QualifiedNameSemantic; import io.ballerina.runtime.api.Module; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.ReferenceType; import io.ballerina.runtime.api.types.TupleType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java index 22de127..8eda9f9 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java @@ -18,12 +18,10 @@ package io.ballerina.lib.data.xmldata.xml; -import io.ballerina.lib.data.xmldata.io.DataReaderTask; -import io.ballerina.lib.data.xmldata.io.DataReaderThreadPool; +import io.ballerina.lib.data.xmldata.io.BallerinaByteBlockInputStream; import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; @@ -36,6 +34,9 @@ import java.io.InputStreamReader; import java.io.StringReader; +import static io.ballerina.lib.data.xmldata.utils.DataReader.resolveCloseMethod; +import static io.ballerina.lib.data.xmldata.utils.DataReader.resolveNextMethod; + /** * Xml conversion. * @@ -69,10 +70,13 @@ public static Object parseBytes(BArray xml, BMap options, BType public static Object parseStream(Environment env, BStream xml, BMap options, BTypedesc typed) { try { final BObject iteratorObj = xml.getIteratorObj(); - final Future future = env.markAsync(); - DataReaderTask task = new DataReaderTask(env, iteratorObj, future, typed, options); - DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); - return null; + BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env, + iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj)); + Object result = XmlParser.parse(new InputStreamReader(byteBlockSteam), options, typed); + if (byteBlockSteam.getError() != null) { + return byteBlockSteam.getError(); + } + return result; } catch (Exception e) { return DiagnosticLog.error(DiagnosticErrorCode.XML_PARSE_ERROR, e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java index 113f1b8..0ed318e 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java @@ -23,16 +23,16 @@ import io.ballerina.lib.data.xmldata.utils.DataUtils; import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.utils.XmlUtils; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java index 0d1776f..273ee4a 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java @@ -23,16 +23,16 @@ import io.ballerina.lib.data.xmldata.utils.DataUtils.XmlAnalyzerData; import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.types.XmlNodeType; import io.ballerina.runtime.api.utils.StringUtils;