[jboss-svn-commits] JBoss Common SVN: r2997 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Feb 25 13:35:13 EST 2009
Author: alex.loubyansky at jboss.com
Date: 2009-02-25 13:35:13 -0500 (Wed, 25 Feb 2009)
New Revision: 2997
Added:
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/AbstractRoot.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithDefaults.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupAll.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupChoice.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupSequence.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupUnorderedSequence.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithXmlTypePropOrder.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/test/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/test/JBossXmlTypeUnitTestCase.java
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlType.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/ChoiceMinOccurs0UnitTestCase.java
Log:
JBXB-184
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlType.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlType.java 2009-02-25 08:44:28 UTC (rev 2996)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlType.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -45,4 +45,9 @@
* @return the builder
*/
Class<? extends BeanAdapterBuilder> beanAdapterBuilder() default DefaultBeanAdapterBuilder.class;
+
+ /**
+ * @return model group type which should be used for the xml type
+ */
+ String modelGroup() default JBossXmlConstants.DEFAULT;
}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2009-02-25 08:44:28 UTC (rev 2996)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -1049,7 +1049,9 @@
// TODO simple types/content when no properties other than @XmlValue and @XmlAttribute
typeBinding.setSimple(false);
ModelGroupBinding model = null;
- if (allBinding)
+ if(jbossXmlType != null && !JBossXmlConstants.DEFAULT.equals(jbossXmlType.modelGroup()))
+ model = createModelGroup(jbossXmlType.modelGroup());
+ else if (allBinding)
model = new AllBinding(schemaBinding);
else
model = groupFactory.createSequence(schemaBinding);
@@ -1717,18 +1719,7 @@
if(createGroup)
{
- String kind = annotation.kind();
- if (kind.equals(JBossXmlConstants.MODEL_GROUP_SEQUENCE))
- group = groupFactory.createSequence(schemaBinding);
- else if (kind.equals(JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE))
- group = new UnorderedSequenceBinding(schemaBinding);
- else if (kind.equals(JBossXmlConstants.MODEL_GROUP_CHOICE))
- group = new ChoiceBinding(schemaBinding);
- else if (kind.equals(JBossXmlConstants.MODEL_GROUP_ALL))
- group = new AllBinding(schemaBinding);
- else
- throw new IllegalStateException("Unexpected JBossXmlModelGroup.kind=" + kind);
-
+ group = createModelGroup(annotation.kind());
if (groupName != null)
{
group.setQName(groupName);
@@ -1818,6 +1809,22 @@
defaultNamespace = overridenDefaultNamespace;
}
+
+ private ModelGroupBinding createModelGroup(String kind)
+ {
+ ModelGroupBinding group;
+ if (kind.equals(JBossXmlConstants.MODEL_GROUP_SEQUENCE))
+ group = groupFactory.createSequence(schemaBinding);
+ else if (kind.equals(JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE))
+ group = new UnorderedSequenceBinding(schemaBinding);
+ else if (kind.equals(JBossXmlConstants.MODEL_GROUP_CHOICE))
+ group = new ChoiceBinding(schemaBinding);
+ else if (kind.equals(JBossXmlConstants.MODEL_GROUP_ALL))
+ group = new AllBinding(schemaBinding);
+ else
+ throw new IllegalStateException("Unexpected JBossXmlModelGroup.kind=" + kind);
+ return group;
+ }
private SequenceBinding bindXmlElementWrapper(TypeInfo propertyType, ModelGroupBinding parentModel, XmlElementWrapper annotation, QName wrapperQName)
{
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/AbstractRoot.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/AbstractRoot.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/AbstractRoot.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+
+/**
+ * A AbstractRoot.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractRoot
+{
+ private String a;
+ private String b;
+
+ public String getA()
+ {
+ return a;
+ }
+
+ public void setA(String a)
+ {
+ this.a = a;
+ }
+
+ public String getB()
+ {
+ return b;
+ }
+
+ public void setB(String b)
+ {
+ this.b = b;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithDefaults.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithDefaults.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithDefaults.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A RootWithDefaults.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType()
+ at JBossXmlType()
+public class RootWithDefaults extends AbstractRoot
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupAll.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupAll.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupAll.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A RootWithDefaults.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b"})
+ at JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_ALL)
+public class RootWithModelGroupAll extends AbstractRoot
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupChoice.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupChoice.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupChoice.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A RootWithDefaults.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b"})
+ at JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_CHOICE)
+public class RootWithModelGroupChoice extends AbstractRoot
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupSequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupSequence.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupSequence.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A RootWithDefaults.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b"})
+ at JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_SEQUENCE)
+public class RootWithModelGroupSequence extends AbstractRoot
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupUnorderedSequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupUnorderedSequence.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithModelGroupUnorderedSequence.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A RootWithDefaults.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b"})
+ at JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE)
+public class RootWithModelGroupUnorderedSequence extends AbstractRoot
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithXmlTypePropOrder.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithXmlTypePropOrder.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/support/RootWithXmlTypePropOrder.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlType;
+
+/**
+ * A RootWithDefaults.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={"a", "b"})
+ at JBossXmlType()
+public class RootWithXmlTypePropOrder extends AbstractRoot
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/test/JBossXmlTypeUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/test/JBossXmlTypeUnitTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/jbossxmltype/test/JBossXmlTypeUnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.xb.builder.object.type.jbossxmltype.test;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.type.jbossxmltype.support.RootWithDefaults;
+import org.jboss.test.xb.builder.object.type.jbossxmltype.support.RootWithModelGroupAll;
+import org.jboss.test.xb.builder.object.type.jbossxmltype.support.RootWithModelGroupChoice;
+import org.jboss.test.xb.builder.object.type.jbossxmltype.support.RootWithXmlTypePropOrder;
+import org.jboss.test.xb.builder.object.type.jbossxmltype.support.RootWithModelGroupSequence;
+import org.jboss.test.xb.builder.object.type.jbossxmltype.support.RootWithModelGroupUnorderedSequence;
+import org.jboss.xb.binding.sunday.unmarshalling.AllBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ChoiceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ModelGroupBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.UnorderedSequenceBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * A JBossXmlTypeUnitTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossXmlTypeUnitTestCase extends AbstractBuilderTest
+{
+ public JBossXmlTypeUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testModelGroupWithDefaults() throws Exception
+ {
+ ModelGroupBinding group = getTypeModelGroup(RootWithDefaults.class);
+ assertTrue(group instanceof SequenceBinding);
+ // but it's unpredictable
+ assertUnorderedGroup(group);
+ }
+
+ public void testModelGroupWithXmlTypePropOrder() throws Exception
+ {
+ ModelGroupBinding group = getTypeModelGroup(RootWithXmlTypePropOrder.class);
+ assertTrue(group instanceof SequenceBinding);
+ assertOrderedGroup(group);
+ }
+
+ public void testModelGroupSequence() throws Exception
+ {
+ ModelGroupBinding group = getTypeModelGroup(RootWithModelGroupSequence.class);
+ assertTrue(group instanceof SequenceBinding);
+ assertOrderedGroup(group);
+ }
+
+ public void testModelGroupChoice() throws Exception
+ {
+ ModelGroupBinding group = getTypeModelGroup(RootWithModelGroupChoice.class);
+ assertTrue(group instanceof ChoiceBinding);
+ assertUnorderedGroup(group);
+ }
+
+ public void testModelGroupAll() throws Exception
+ {
+ ModelGroupBinding group = getTypeModelGroup(RootWithModelGroupAll.class);
+ assertTrue(group instanceof AllBinding);
+ assertUnorderedGroup(group);
+ }
+
+ public void testModelGroupUnorderedSequence() throws Exception
+ {
+ ModelGroupBinding group = getTypeModelGroup(RootWithModelGroupUnorderedSequence.class);
+ assertTrue(group instanceof UnorderedSequenceBinding);
+ assertUnorderedGroup(group);
+ }
+
+ private void assertOrderedGroup(ModelGroupBinding group)
+ {
+ Collection<ParticleBinding> particles = group.getParticles();
+ assertEquals(2, particles.size());
+ Iterator<ParticleBinding> i = particles.iterator();
+ ParticleBinding p = i.next();
+ assertEquals(0, p.getMinOccurs());
+ assertEquals(1, p.getMaxOccurs());
+ assertFalse(p.getMaxOccursUnbounded());
+ TermBinding t = p.getTerm();
+ assertTrue(t.isElement());
+ assertEquals(new QName("a"), ((ElementBinding)t).getQName());
+
+ p = i.next();
+ assertEquals(0, p.getMinOccurs());
+ assertEquals(1, p.getMaxOccurs());
+ assertFalse(p.getMaxOccursUnbounded());
+ t = p.getTerm();
+ assertTrue(t.isElement());
+ assertEquals(new QName("b"), ((ElementBinding)t).getQName());
+ }
+
+ private void assertUnorderedGroup(ModelGroupBinding group)
+ {
+ Collection<ParticleBinding> particles = group.getParticles();
+ assertEquals(2, particles.size());
+ Iterator<ParticleBinding> i = particles.iterator();
+ ParticleBinding p = i.next();
+ assertEquals(0, p.getMinOccurs());
+ assertEquals(1, p.getMaxOccurs());
+ assertFalse(p.getMaxOccursUnbounded());
+ TermBinding t = p.getTerm();
+ assertTrue(t.isElement());
+
+ QName eName = ((ElementBinding)t).getQName();
+ if(!new QName("a").equals(eName))
+ assertEquals(new QName("b"), eName);
+
+ p = i.next();
+ assertEquals(0, p.getMinOccurs());
+ assertEquals(1, p.getMaxOccurs());
+ assertFalse(p.getMaxOccursUnbounded());
+ t = p.getTerm();
+ assertTrue(t.isElement());
+
+ eName = ((ElementBinding)t).getQName();
+ if(!new QName("a").equals(eName))
+ assertEquals(new QName("b"), eName);
+ }
+
+ private ModelGroupBinding getTypeModelGroup(Class<?> root)
+ {
+ SchemaBinding schema = JBossXBBuilder.build(root);
+ ElementBinding e = schema.getElement(new QName("root"));
+ assertNotNull(e);
+ TermBinding t = e.getType().getParticle().getTerm();
+ assertTrue(t.isModelGroup());
+ return (ModelGroupBinding) t;
+ }
+}
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/ChoiceMinOccurs0UnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/ChoiceMinOccurs0UnitTestCase.java 2009-02-25 08:44:28 UTC (rev 2996)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/ChoiceMinOccurs0UnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
@@ -75,7 +75,7 @@
public void testMain() throws Exception
{
- enableTrace("org.jboss.xb.binding.sunday.unmarshalling.XsdBinder");
+ //enableTrace("org.jboss.xb.binding.sunday.unmarshalling.XsdBinder");
SchemaBinding schema = XsdBinder.bind(new StringReader(XSD), null);
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
Object o = unmarshaller.unmarshal(new StringReader(XML), schema);
More information about the jboss-svn-commits
mailing list