forked from ballerina-platform/module-ballerina-data.xmldata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ballerina-platform#10 from prakanth97/fix_same_name
Support same element and attribute names with different namespaces
- Loading branch information
Showing
12 changed files
with
1,187 additions
and
374 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 151 additions & 89 deletions
240
native/src/main/java/io/ballerina/stdlib/data/utils/DataUtils.java
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
native/src/main/java/io/ballerina/stdlib/data/utils/DiagnosticErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2023, 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.stdlib.data.utils; | ||
|
||
/** | ||
* Represents a diagnostic error code. | ||
* | ||
* @since 0.0.1 | ||
*/ | ||
public enum DiagnosticErrorCode { | ||
|
||
UNSUPPORTED_TYPE("BDE_0001", "unsupported.type"), | ||
XML_ROOT_MISSING("BDE_0002", "xml.root.missing"), | ||
INVALID_REST_TYPE("BDE_0003", "invalid.rest.type"), | ||
ARRAY_SIZE_MISMATCH("BDE_0004", "array.size.mismatch"), | ||
REQUIRED_FIELD_NOT_PRESENT("BDE_0005", "required.field.not.present"), | ||
REQUIRED_ATTRIBUTE_NOT_PRESENT("BDE_0006", "required.attribute.not.present"), | ||
DUPLICATE_FIELD("BDE_0007", "duplicate.field"), | ||
FOUND_ARRAY_FOR_NON_ARRAY_TYPE("BDE_0008", "found.array.for.non.array.type"), | ||
EXPECTED_ANYDATA_OR_JSON("BDE_0009", "expected.anydata.or.json"), | ||
NAMESPACE_MISMATCH("BDE_0010", "namespace.mismatch"), | ||
TYPE_NAME_MISMATCH_WITH_XML_ELEMENT("BDE_0011", "type.name.mismatch.with.xml.element"); | ||
|
||
String diagnosticId; | ||
String messageKey; | ||
|
||
DiagnosticErrorCode(String diagnosticId, String messageKey) { | ||
this.diagnosticId = diagnosticId; | ||
this.messageKey = messageKey; | ||
} | ||
|
||
public String messageKey() { | ||
return messageKey; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
native/src/main/java/io/ballerina/stdlib/data/utils/DiagnosticLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2023, 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.stdlib.data.utils; | ||
|
||
import io.ballerina.runtime.api.creators.ErrorCreator; | ||
import io.ballerina.runtime.api.utils.StringUtils; | ||
import io.ballerina.runtime.api.values.BError; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
/** | ||
* Diagnostic log for data module. | ||
* | ||
* @since 0.0.1 | ||
*/ | ||
public class DiagnosticLog { | ||
private static final String ERROR_PREFIX = "error"; | ||
private static final String ERROR = "ConversionError"; | ||
private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("error", Locale.getDefault()); | ||
|
||
public static BError error(DiagnosticErrorCode code, Object... args) { | ||
String msg = formatMessage(code, args); | ||
return getXmlError(msg); | ||
} | ||
|
||
private static String formatMessage(DiagnosticErrorCode code, Object[] args) { | ||
String msgKey = MESSAGES.getString(ERROR_PREFIX + "." + code.messageKey()); | ||
return MessageFormat.format(msgKey, args); | ||
} | ||
|
||
public static BError getXmlError(String message) { | ||
return ErrorCreator.createError(ModuleUtils.getModule(), ERROR, StringUtils.fromString(message), | ||
null, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
native/src/main/java/io/ballerina/stdlib/data/xml/QualifiedName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2023, 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.stdlib.data.xml; | ||
|
||
/** | ||
* Represents a qualified name. | ||
* | ||
* @since 0.0.1 | ||
*/ | ||
public class QualifiedName { | ||
public static final String NS_ANNOT_NOT_DEFINED = "$$ns_annot_not_defined$$"; | ||
private String localPart; | ||
private String namespaceURI; | ||
private String prefix; | ||
|
||
public QualifiedName(String namespaceURI, String localPart, String prefix) { | ||
this.localPart = localPart; | ||
this.namespaceURI = namespaceURI; | ||
this.prefix = prefix; | ||
} | ||
|
||
public QualifiedName(String localPart) { | ||
this.localPart = localPart; | ||
this.namespaceURI = ""; | ||
this.prefix = ""; | ||
} | ||
|
||
public String getLocalPart() { | ||
return localPart; | ||
} | ||
|
||
public void setLocalPart(String localPart) { | ||
this.localPart = localPart; | ||
} | ||
|
||
public String getNamespaceURI() { | ||
return namespaceURI; | ||
} | ||
|
||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return localPart.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object objectToTest) { | ||
if (objectToTest == this) { | ||
return true; | ||
} | ||
|
||
if (objectToTest == null || !(objectToTest instanceof QualifiedName)) { | ||
return false; | ||
} | ||
|
||
QualifiedName qName = (QualifiedName) objectToTest; | ||
|
||
if (qName.namespaceURI.equals(NS_ANNOT_NOT_DEFINED) || namespaceURI.equals(NS_ANNOT_NOT_DEFINED)) { | ||
return localPart.equals(qName.localPart); | ||
} | ||
return localPart.equals(qName.localPart) && namespaceURI.equals(qName.namespaceURI) && | ||
prefix.equals(qName.prefix); | ||
} | ||
} |
Oops, something went wrong.