aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSundong Ahn <sundongahn@google.com>2019-04-03 10:26:31 +0900
committerSundong Ahn <sundongahn@google.com>2019-04-05 05:33:58 +0000
commitb564858b10510e64b44e3afd4c8dffe66dc249fb (patch)
treed38ddfcddf3eb773fc6e848a6cfbdf8ca3e9011c
parenta742042e7fde0c98220c71a5fb6ee3f56b998b60 (diff)
downloadxsdc-android-10.0.0_r20.tar.gz
If the maxOccurs of sequence or choice is more than 1, the sub-element can occurs multiple. But the multiple of an element depends only on the element's maxOccurs. So If the parent element can occurs multiple, the sub-elements can also occurs mutitple. Test: m -j && make update-api && make check-api Bug: 128380795 Merged-In: I90954a3289c4db97c746422374f2e2860b6ce086 Change-Id: I90954a3289c4db97c746422374f2e2860b6ce086 (cherry picked from commit edaf152e2ea13e5e6aa64354a3c1bf0789b08094)
-rw-r--r--src/com/android/xsdc/XsdHandler.java10
-rw-r--r--src/com/android/xsdc/tag/XsdElement.java6
-rw-r--r--tests/main.cpp2
-rw-r--r--tests/resources/simple_type/api/current.txt21
-rw-r--r--tests/resources/simple_type/simple_type.xsd18
5 files changed, 54 insertions, 3 deletions
diff --git a/src/com/android/xsdc/XsdHandler.java b/src/com/android/xsdc/XsdHandler.java
index e0b795e..7737e37 100644
--- a/src/com/android/xsdc/XsdHandler.java
+++ b/src/com/android/xsdc/XsdHandler.java
@@ -488,6 +488,10 @@ public class XsdHandler extends DefaultHandler {
for (XsdTag tag : state.tags) {
if (tag == null) continue;
if (tag instanceof XsdElement) {
+ if (maxOccurs != null && (maxOccurs.equals("unbounded")
+ || Integer.parseInt(maxOccurs) > 1)) {
+ ((XsdElement)tag).setMultiple(true);
+ }
elements.add((XsdElement) tag);
}
}
@@ -495,10 +499,16 @@ public class XsdHandler extends DefaultHandler {
}
private static List<XsdElement> makeChoice(State state) throws XsdParserException {
+ String maxOccurs = state.attributeMap.get("maxOccurs");
List<XsdElement> elements = new ArrayList<>();
+
for (XsdTag tag : state.tags) {
if (tag == null) continue;
if (tag instanceof XsdElement) {
+ if (maxOccurs != null && (maxOccurs.equals("unbounded")
+ || Integer.parseInt(maxOccurs) > 1)) {
+ ((XsdElement)tag).setMultiple(true);
+ }
XsdElement element = (XsdElement)tag;
elements.add(setDeprecated(new XsdChoice(element.getName(), element.getRef(),
element.getType(), element.isMultiple()), element.isDeprecated()));
diff --git a/src/com/android/xsdc/tag/XsdElement.java b/src/com/android/xsdc/tag/XsdElement.java
index 2bdd534..40a6695 100644
--- a/src/com/android/xsdc/tag/XsdElement.java
+++ b/src/com/android/xsdc/tag/XsdElement.java
@@ -22,7 +22,7 @@ import javax.xml.namespace.QName;
public class XsdElement extends XsdTag {
final private XsdType type;
- final private boolean multiple;
+ private boolean multiple;
public XsdElement(String name, QName ref, XsdType type, boolean multiple)
throws XsdParserException {
@@ -42,6 +42,10 @@ public class XsdElement extends XsdTag {
return type;
}
+ public void setMultiple(boolean multiple) {
+ this.multiple = multiple;
+ }
+
public boolean isMultiple() {
return multiple;
}
diff --git a/tests/main.cpp b/tests/main.cpp
index 9af8569..41b3811 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -38,7 +38,7 @@ public:
TEST_F(XmlTest, Simpletype) {
using namespace simple::type;
string file_name = "resources/simple_type.xml";
- SimpleTypes simple = *read(file_name.c_str());
+ SimpleTypes simple = *readSimpleTypes(file_name.c_str());
for (int i = 0; i < simple.getListInt().size(); ++i) {
EXPECT_EQ(simple.getListInt()[i], i + 1);
diff --git a/tests/resources/simple_type/api/current.txt b/tests/resources/simple_type/api/current.txt
index 49ba190..c42010e 100644
--- a/tests/resources/simple_type/api/current.txt
+++ b/tests/resources/simple_type/api/current.txt
@@ -7,6 +7,13 @@ package simple.type {
enum_constant @Deprecated public static final simple.type.EnumType YES;
}
+ public class MultiChoice {
+ ctor public MultiChoice();
+ method public java.util.List<java.lang.String> getExample1_optional();
+ method public java.util.List<java.lang.String> getExample2_optional();
+ method public java.util.List<java.lang.String> getExample3_optional();
+ }
+
public class SimpleTypes {
ctor public SimpleTypes();
method public java.util.List<java.lang.Integer> getListInt();
@@ -17,9 +24,21 @@ package simple.type {
method public void setYesOrNo(simple.type.EnumType);
}
+ public class SingleChoice {
+ ctor public SingleChoice();
+ method public String getExample1_optional();
+ method public String getExample2_optional();
+ method public String getExample3_optional();
+ method public void setExample1_optional(String);
+ method public void setExample2_optional(String);
+ method public void setExample3_optional(String);
+ }
+
public class XmlParser {
ctor public XmlParser();
- method public static simple.type.SimpleTypes read(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public static simple.type.MultiChoice readMultiChoice(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public static simple.type.SimpleTypes readSimpleTypes(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public static simple.type.SingleChoice readSingleChoice(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
}
diff --git a/tests/resources/simple_type/simple_type.xsd b/tests/resources/simple_type/simple_type.xsd
index 368487f..dbd96a4 100644
--- a/tests/resources/simple_type/simple_type.xsd
+++ b/tests/resources/simple_type/simple_type.xsd
@@ -33,4 +33,22 @@
</xs:sequence>
</xs:complexType>
</xs:element>
+ <xs:element name="multi-choice">
+ <xs:complexType>
+ <xs:choice maxOccurs="unbounded">
+ <xs:element name="example1" type="xs:string"/>
+ <xs:element name="example2" type="xs:string"/>
+ <xs:element name="example3" type="xs:string"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="single-choice">
+ <xs:complexType>
+ <xs:choice>
+ <xs:element name="example1" type="xs:string"/>
+ <xs:element name="example2" type="xs:string"/>
+ <xs:element name="example3" type="xs:string"/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
</xs:schema>