Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement XML to record converter #41198

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions distribution/zip/jballerina-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ dependencies {
langserverLib project(':ls-extensions:partial-parser')
langserverLib project(':ls-extensions:trigger-service')
langserverLib project(':ls-extensions:bal-shell-service')
langserverLib project(':xml-to-record-converter')

debugAdapterLib project(path: ':debug-adapter:debug-adapter-core', configuration: 'libs')
debugAdapterLib project(':debug-adapter:debug-adapter-cli')
Expand Down
2 changes: 1 addition & 1 deletion misc/identifier-util/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

exports io.ballerina.identifier to io.ballerina.lang, io.ballerina.runtime, io.ballerina.shell,
io.ballerina.testerina.runtime, io.ballerina.lang.runtime, io.ballerina.lang.error,
ballerina.debug.adapter.core, io.ballerina.jsonmapper, io.ballerina.cli;
ballerina.debug.adapter.core, io.ballerina.jsonmapper, io.ballerina.cli, io.ballerina.xmltorecordconverter;
}
65 changes: 65 additions & 0 deletions misc/xml-to-record-converter/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*/

apply from: "$rootDir/gradle/javaProject.gradle"
apply from: "$rootDir/gradle/ballerinaLangLibLoad.gradle"

configurations {
compile.transitive = false
compileClasspath.extendsFrom(compileOnly)
}

dependencies {
compileOnly project(':ballerina-parser')
compileOnly project(':ballerina-lang')
compileOnly project(':formatter:formatter-core')
compileOnly project(':language-server:language-server-commons')

implementation project(':ballerina-tools-api')
implementation project(':identifier-util')
implementation "org.apache.commons:commons-lang3:${project.apacheCommonsLang3Version}"
implementation "org.javatuples:javatuples:${project.javaTuples}"
compileOnly (group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: "${project.eclipseLsp4jVersion}")

testCompile 'org.testng:testng'
testCompile project(':ballerina-lang')
testCompile project(':formatter:formatter-core')
testCompile project(':language-server:language-server-core')
testCompile "org.javatuples:javatuples:${project.javaTuples}"
testCompile (group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: "${project.eclipseLsp4jVersion}")
}

test {
useTestNG() {
suites 'src/test/resources/testng.xml'
}
}

description = 'Module for converting XML to Ballerina Records Directly'

ext.moduleName = 'xml-to-record-converter'

compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.xmltorecordconverter;

/**
* Represents the Service constants.
*
* @since 2201.7.2
*/
public class Constants {
public static final String CAPABILITY_NAME = "xmlToRecord";
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.xmltorecordconverter;

import org.ballerinalang.langserver.commons.registration.BallerinaClientCapability;

/**
* Client capabilities for the XMLToRecord service.
*
* @since 2201.7.2
*/
public class XMLToRecordConverterClientCapabilities extends BallerinaClientCapability {

private boolean convert;

public boolean isConvert() {
return convert;
}

public void setConvert(boolean convert) {
this.convert = convert;
}

public XMLToRecordConverterClientCapabilities() {
super(Constants.CAPABILITY_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.xmltorecordconverter;


import org.ballerinalang.annotation.JavaSPIService;
import org.ballerinalang.langserver.commons.registration.BallerinaClientCapabilitySetter;

/**
* Client Capability setter for the {@link XMLToRecordConverterService}.
*
* @since 2201.7.2
*/
@JavaSPIService("org.ballerinalang.langserver.commons.registration.BallerinaClientCapabilitySetter")
public class XMLToRecordConverterClientCapabilitySetter extends
BallerinaClientCapabilitySetter<XMLToRecordConverterClientCapabilities> {

@Override
public String getCapabilityName() {
return Constants.CAPABILITY_NAME;
}

@Override
public Class<XMLToRecordConverterClientCapabilities> getCapability() {
return XMLToRecordConverterClientCapabilities.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.xmltorecordconverter;

import org.ballerinalang.langserver.commons.registration.BallerinaServerCapability;

/**
* Server capabilities for the XMLToRecord service.
*
* @since 2201.7.2
*/
public class XMLToRecordConverterServerCapabilities extends BallerinaServerCapability {

private boolean convert;

public boolean isConvert() {
return convert;
}

public void setConvert(boolean convert) {
this.convert = convert;
}

public XMLToRecordConverterServerCapabilities() {
super(Constants.CAPABILITY_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.xmltorecordconverter;

import org.ballerinalang.annotation.JavaSPIService;
import org.ballerinalang.langserver.commons.registration.BallerinaServerCapabilitySetter;

import java.util.Optional;

/**
* Capability setter for the {@link XMLToRecordConverterService}.
*
* @since 2201.7.2
*/
@JavaSPIService("org.ballerinalang.langserver.commons.registration.BallerinaServerCapabilitySetter")
public class XMLToRecordConverterServerCapabilitySetter extends
BallerinaServerCapabilitySetter<XMLToRecordConverterServerCapabilities> {

@Override
public Optional<XMLToRecordConverterServerCapabilities> build() {
XMLToRecordConverterServerCapabilities capabilities = new XMLToRecordConverterServerCapabilities();
capabilities.setConvert(true);
return Optional.of(capabilities);
}

@Override
public String getCapabilityName() {
return Constants.CAPABILITY_NAME;
}

@Override
public Class<XMLToRecordConverterServerCapabilities> getCapability() {
return XMLToRecordConverterServerCapabilities.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.xmltorecordconverter;

import org.ballerinalang.annotation.JavaSPIService;
import org.ballerinalang.langserver.commons.service.spi.ExtendedLanguageServerService;
import org.ballerinalang.langserver.commons.workspace.WorkspaceManager;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;
import org.eclipse.lsp4j.services.LanguageServer;

import java.util.concurrent.CompletableFuture;

/**
* The extended service for the XMLToRecord endpoint.
*
* @since 2.0.0
*/
@JavaSPIService("org.ballerinalang.langserver.commons.service.spi.ExtendedLanguageServerService")
@JsonSegment("xmlToRecord")
public class XMLToRecordConverterService implements ExtendedLanguageServerService {
private WorkspaceManager workspaceManager;

@Override
public void init(LanguageServer langServer, WorkspaceManager workspaceManager) {
ExtendedLanguageServerService.super.init(langServer, workspaceManager);
this.workspaceManager = workspaceManager;
}

@Override
public Class<?> getRemoteInterface() {
return getClass();
}

@JsonRequest
public CompletableFuture<XMLToRecordResponse> convert(XMLToRecordRequest request) {
return CompletableFuture.supplyAsync(() -> {
String xmlValue = request.getXmlValue();
boolean isRecordTypeDesc = request.getIsRecordTypeDesc();
boolean isClosed = request.getIsClosed();
boolean forceFormatRecordFields = request.getForceFormatRecordFields();

return XMLToRecordConverter.convert(xmlValue, false, isRecordTypeDesc, isClosed,
forceFormatRecordFields);
});
}

@Override
public String getName() {
return Constants.CAPABILITY_NAME;
}
}
Loading
Loading