[prev in list] [next in list] [prev in thread] [next in thread]
List: jaxme-dev
Subject: cvs commit: ws-jaxme/src/test/jaxb/jira jaxme-46.xsd
From: jochen () apache ! org
Date: 2004-12-04 23:22:34
Message-ID: 20041204232234.39905.qmail () minotaur ! apache ! org
[Download RAW message or body]
jochen 2004/12/04 15:22:34
Modified: src/xs/org/apache/ws/jaxme/xs/junit JiraTest.java
ParserTest.java
src/xs/org/apache/ws/jaxme/xs/impl XSAttributeImpl.java
src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBAttributeSG.java
src/jaxme/org/apache/ws/jaxme/junit JiraTest.java
ParserTest.java
Added: src/test/jaxb/jira jaxme-46.xsd
Log:
JaxMe-46: A referenced attribute wasn't necessarily initialized.
Revision Changes Path
1.4 +41 -0 ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/JiraTest.java
Index: JiraTest.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/JiraTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JiraTest.java 22 Oct 2004 21:35:06 -0000 1.3
+++ JiraTest.java 4 Dec 2004 23:22:33 -0000 1.4
@@ -7,13 +7,17 @@
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.ws.jaxme.xs.XSAttributable;
+import org.apache.ws.jaxme.xs.XSAttribute;
import org.apache.ws.jaxme.xs.XSComplexType;
+import org.apache.ws.jaxme.xs.XSElement;
import org.apache.ws.jaxme.xs.XSEnumeration;
import org.apache.ws.jaxme.xs.XSParser;
import org.apache.ws.jaxme.xs.XSSchema;
import org.apache.ws.jaxme.xs.XSSimpleContentType;
import org.apache.ws.jaxme.xs.XSSimpleType;
import org.apache.ws.jaxme.xs.XSType;
+import org.apache.ws.jaxme.xs.types.XSID;
import org.apache.ws.jaxme.xs.types.XSString;
import org.apache.ws.jaxme.xs.util.XsDateTimeFormat;
import org.apache.ws.jaxme.xs.xml.XsAnyURI;
@@ -102,6 +106,7 @@
+ " </xs:simpleContent>\n"
+ " </xs:complexType>\n"
+ "</xs:schema>";
+
XSSchema schema = parse(schemaSpec, "jira44.xsd");
XSType[] types = schema.getTypes();
assertEquals(3, types.length);
@@ -128,5 +133,41 @@
XSEnumeration[] outerType2Enums = \
outerType2contentType.getSimpleType().getEnumerations(); assertEquals(1, \
outerType2Enums.length); assertEquals("4", outerType2Enums[0].getValue());
+ }
+
+ /** Test for JAXME-46 in Jira.
+ */
+ public void testJira46() throws Exception {
+ final String uri = "http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/";
+ final String schemaSpec =
+ "<xs:schema targetNamespace='" + uri + "'\n" +
+ " xmlns:eGov_IT='" + uri + "'\n" +
+ " xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ " <xs:element name='Riferimento'>\n" +
+ " <xs:complexType>\n" +
+ " <xs:sequence/>\n" +
+ " <xs:attribute ref='eGov_IT:id' use='required'/>\n" +
+ " </xs:complexType>\n" +
+ " </xs:element>\n" +
+ " <xs:attribute name='id' type='xs:ID'/>\n" +
+ "</xs:schema>\n";
+ XSSchema schema = parse(schemaSpec, "jira46.xsd");
+ XSAttribute[] attrs = schema.getAttributes();
+ assertEquals(1, attrs.length);
+ XSAttribute idAttr = attrs[0];
+ assertEquals(new XsQName(uri, "id"), idAttr.getName());
+ assertEquals(XSID.getInstance(), idAttr.getType());
+ assertTrue(idAttr.isOptional());
+ XSElement[] elements = schema.getElements();
+ assertEquals(1, elements.length);
+ XSElement rifElem = elements[0];
+ XSComplexType ct = assertComplexType(rifElem.getType());
+ XSAttributable[] rifAttrs = ct.getAttributes();
+ assertEquals(1, rifAttrs.length);
+ XSAttribute idRef = (XSAttribute) rifAttrs[0];
+ assertFalse(idRef.equals(idAttr));
+ assertEquals(new XsQName(uri, "id"), idAttr.getName());
+ assertEquals(XSID.getInstance(), idAttr.getType());
+ assertFalse(idRef.isOptional());
}
}
1.20 +26 -9 ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/ParserTest.java
Index: ParserTest.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/ParserTest.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ParserTest.java 2 Sep 2004 06:47:42 -0000 1.19
+++ ParserTest.java 4 Dec 2004 23:22:33 -0000 1.20
@@ -22,7 +22,6 @@
import javax.xml.parsers.ParserConfigurationException;
import org.apache.ws.jaxme.xs.XSAnnotation;
-import org.apache.ws.jaxme.xs.XSAny;
import org.apache.ws.jaxme.xs.XSAppinfo;
import org.apache.ws.jaxme.xs.XSAttributable;
import org.apache.ws.jaxme.xs.XSAttribute;
@@ -53,11 +52,11 @@
import org.apache.ws.jaxme.xs.types.XSDecimal;
import org.apache.ws.jaxme.xs.types.XSDouble;
import org.apache.ws.jaxme.xs.types.XSFloat;
+import org.apache.ws.jaxme.xs.types.XSID;
import org.apache.ws.jaxme.xs.types.XSInt;
import org.apache.ws.jaxme.xs.types.XSNMToken;
import org.apache.ws.jaxme.xs.types.XSPositiveInteger;
import org.apache.ws.jaxme.xs.types.XSString;
-import org.apache.ws.jaxme.xs.xml.XsComplexContentType;
import org.apache.ws.jaxme.xs.xml.XsNamespaceList;
import org.apache.ws.jaxme.xs.xml.XsQName;
import org.apache.ws.jaxme.xs.xml.impl.XsObjectFactoryImpl;
@@ -69,9 +68,6 @@
/** <p>Implements some basic tests for the Schema generator.</p>
- *
- * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
- * @version $Id$
*/
public class ParserTest extends ParserTestBase {
/** <p>Creates a new instance of <code>ParserTest</code> named
@@ -195,6 +191,8 @@
assertAtomicType(st3);
}
+ /** Tests typical attribute uses.
+ */
public void testAttributes() throws Exception {
XSParser xsParser = newXSParser();
testAttributes(xsParser);
@@ -265,6 +263,8 @@
assertEquals(XSInt.getInstance(), attr2_5.getType());
}
+ /** Tests typical attribute group uses.
+ */
public void testAttributeGroups() throws Exception {
XSParser xsParser = newXSParser();
testAttributeGroups(xsParser);
@@ -276,6 +276,8 @@
final String schemaSource =
"<?xml version='1.0'?>\n" +
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ " <xs:attribute name='id' type='xs:ID'/>\n" +
+ "\n" +
" <xs:element name='a' type='xs:string'/>\n" +
"\n" +
" <xs:element name='b'>\n" +
@@ -316,6 +318,7 @@
" <xs:simpleContent>\n" +
" <xs:extension base='xs:int'>\n" +
" <xs:attribute name='g' type='xs:boolean'/>\n" +
+ " <xs:attribute ref='id'/>\n" +
" </xs:extension>\n" +
" </xs:simpleContent>\n" +
" </xs:complexType>\n" +
@@ -367,12 +370,17 @@
assertSimpleType(t4);
assertEquals(XSInt.getInstance(), t4);
XSAttributable[] a4 = ct4.getAttributes();
- assertEquals(1, a4.length);
+ assertEquals(2, a4.length);
XSAttribute a4_1 = (XSAttribute) a4[0];
assertEquals(new XsQName((String) null, "g"), a4_1.getName());
assertEquals(XSBoolean.getInstance(), a4_1.getType());
+ XSAttribute a4_2 = (XSAttribute) a4[1];
+ assertEquals(new XsQName((String) null, "id"), a4_2.getName());
+ assertEquals(XSID.getInstance(), a4_2.getType());
}
+ /** Tests typical element uses.
+ */
public void testElements() throws Exception {
XSParser xsParser = newXSParser();
testElements(xsParser);
@@ -380,7 +388,7 @@
testElements(jaxbParser);
}
- public void testFacets(XSParser pParser) throws Exception {
+ protected void testFacets(XSParser pParser) throws Exception {
final String schemaSource =
"<?xml version='1.0'?>\n" +
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
@@ -414,6 +422,8 @@
assertEquals("AR", enumerations[2].getValue());
}
+ /** Tests various facets.
+ */
public void testFacets() throws Exception {
XSParser xsParser = newXSParser();
testFacets(xsParser);
@@ -421,6 +431,8 @@
testFacets(jaxbParser);
}
+ /** Test of the w3c sample schema PO.
+ */
public void testPurchaseOrder() throws Exception {
final String schemaSource =
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\n" +
@@ -642,7 +654,6 @@
XSSimpleType skuSimpleType = assertSimpleType(sku);
assertEquals(XSString.getInstance(), assertRestriction(skuSimpleType));
assertEquals(sku, partNumType);
- // TODO: test restriction pattern
// USAddress
// <xsd:complexType name='USAddress'>
@@ -893,6 +904,9 @@
assertEquals(new XsQName((String) null, "ba1"), ba1.getName());
}
+ /** Tests setting attributes, which aren't specified in the
+ * schema.
+ */
public void testAdditionalAttributes() throws Exception {
final String schemaSource =
"<?xml version='1.0'?>\n" +
@@ -922,6 +936,8 @@
assertEquals("z", elementOpenAttrs.getValue(0));
}
+ /** Tests restriction of a simple type.
+ */
public void testSimpleTypeRestriction() throws Exception {
final String schemaSource =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
@@ -1032,7 +1048,8 @@
}
-
+ /** Tests definition of a key.
+ */
public void testSimpleKey() throws Exception {
XSParser xsParser = newXSParser();
testSimpleKey(xsParser);
1.4 +4 -0 \
ws-jaxme/src/xs/org/apache/ws/jaxme/xs/impl/XSAttributeImpl.java
Index: XSAttributeImpl.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/impl/XSAttributeImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XSAttributeImpl.java 16 Feb 2004 23:39:43 -0000 1.3
+++ XSAttributeImpl.java 4 Dec 2004 23:22:34 -0000 1.4
@@ -129,11 +129,15 @@
XSType myType;
if (isReference()) {
XSAttribute attribute = getXSSchema().getAttribute(getName());
+ attribute.validate();
if (attribute == null) {
throw new LocSAXException("Invalid attribute reference: No type named " + \
getName() + " defined.", getXsTAttribute().getLocator());
}
myType = attribute.getType();
+ if (myType == null) {
+ throw new IllegalStateException("The referenced attributes type must not \
be null."); + }
} else if (isInnerSimpleType()) {
XsTLocalSimpleType innerSimpleType = getXsTAttribute().getSimpleType();
myType = getXSSchema().getXSObjectFactory().newXSType(this, \
innerSimpleType);
1.5 +3 -3 \
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBAttributeSG.java
Index: JAXBAttributeSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBAttributeSG.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JAXBAttributeSG.java 26 Jul 2004 07:24:04 -0000 1.4
+++ JAXBAttributeSG.java 4 Dec 2004 23:22:34 -0000 1.5
@@ -59,6 +59,9 @@
isRequired = !pAttribute.isOptional();
name = pAttribute.getName();
XSType type = pAttribute.getType();
+ if (type == null) {
+ throw new IllegalStateException("The attribute type must not be \
null."); + }
if (type.isGlobal()) {
typeSG = getFactory().getTypeSG(type);
if (typeSG == null) {
@@ -112,9 +115,6 @@
public XsQName getName(AttributeSG pController) { return name; }
public boolean isRequired(AttributeSG pAttrController) { return isRequired; }
- public boolean hasIsSetMethod(AttributeSG pController) {
- return false;
- }
public void forAllValues(AttributeSG pController, JavaMethod pMethod,
DirectAccessible pElement, SGlet pSGlet) throws SAXException {
1.6 +4 -4 ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
Index: JiraTest.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JiraTest.java 28 Oct 2004 20:35:47 -0000 1.5
+++ JiraTest.java 4 Dec 2004 23:22:34 -0000 1.6
@@ -4,15 +4,15 @@
import javax.xml.bind.JAXBContext;
-import org.apache.ws.jaxme.test.misc.types.Row;
-import org.apache.ws.jaxme.test.misc.types.impl.RowImpl;
-import org.apache.ws.jaxme.test.misc.xsimport.a.Outer;
-
import magoffin.matt.ieat.domain.impl.IngredientImpl;
import net.dspc.commons.activitymodel.TransmissionData;
import net.dspc.commons.activitymodel2.Body1;
import net.dspc.commons.activitymodel2.Body2;
import net.dspc.commons.activitymodel2.ObjectFactory;
+
+import org.apache.ws.jaxme.test.misc.types.Row;
+import org.apache.ws.jaxme.test.misc.types.impl.RowImpl;
+import org.apache.ws.jaxme.test.misc.xsimport.a.Outer;
/** Some excerpts from Jira bug reports.
1.6 +65 -5 ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/ParserTest.java
Index: ParserTest.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/ParserTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ParserTest.java 20 Aug 2004 12:23:08 -0000 1.5
+++ ParserTest.java 4 Dec 2004 23:22:34 -0000 1.6
@@ -31,16 +31,26 @@
import org.apache.ws.jaxme.generator.sg.ListTypeSG;
import org.apache.ws.jaxme.generator.sg.ObjectSG;
import org.apache.ws.jaxme.generator.sg.ParticleSG;
+import org.apache.ws.jaxme.generator.sg.SGFactory;
import org.apache.ws.jaxme.generator.sg.SchemaSG;
import org.apache.ws.jaxme.generator.sg.SimpleContentSG;
import org.apache.ws.jaxme.generator.sg.SimpleTypeSG;
import org.apache.ws.jaxme.generator.sg.TypeSG;
import org.apache.ws.jaxme.generator.sg.UnionTypeSG;
+import org.apache.ws.jaxme.generator.sg.impl.JAXBSGFactory;
import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
+import org.apache.ws.jaxme.generator.sg.impl.SGFactoryImpl;
import org.apache.ws.jaxme.js.JavaQNameImpl;
+import org.apache.ws.jaxme.xs.XSAttributable;
+import org.apache.ws.jaxme.xs.XSAttribute;
+import org.apache.ws.jaxme.xs.XSComplexType;
+import org.apache.ws.jaxme.xs.XSElement;
import org.apache.ws.jaxme.xs.XSParser;
+import org.apache.ws.jaxme.xs.XSSchema;
+import org.apache.ws.jaxme.xs.jaxb.JAXBAttribute;
import org.apache.ws.jaxme.xs.jaxb.JAXBJavaType;
import org.apache.ws.jaxme.xs.jaxb.impl.JAXBParser;
+import org.apache.ws.jaxme.xs.types.XSID;
import org.apache.ws.jaxme.xs.xml.XsQName;
import org.xml.sax.InputSource;
@@ -54,15 +64,20 @@
public ParserTest(String arg) { super(arg); }
protected SchemaSG parse(String pSchema, String pSystemId) throws Exception {
- Generator generator = new GeneratorImpl();
- JAXBSchemaReader r = new JAXBSchemaReader();
- generator.setSchemaReader(r);
- r.setGenerator(generator);
+ JAXBSchemaReader r = getSchemaReader();
InputSource isource = new InputSource(new StringReader(pSchema));
isource.setSystemId(pSystemId);
return r.parse(isource);
}
+ protected JAXBSchemaReader getSchemaReader() {
+ Generator generator = new GeneratorImpl();
+ JAXBSchemaReader r = new JAXBSchemaReader();
+ generator.setSchemaReader(r);
+ r.setGenerator(generator);
+ return r;
+ }
+
public void testSimpleTypes() throws Exception {
final String schema =
"<?xml version='1.0'?>\n" +
@@ -1014,4 +1029,49 @@
ListTypeSG nmtsl = nmtss.getListType();
assertEquals(new Long(1), nmtsl.getMinLength());
}
+
+ /** Test for <a \
href="http://nagoya.apache.org/jira/browse/JAXME-45">JAXME-45</a> + */
+ public void testJira46() throws Exception {
+ final String uri = "http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/";
+ final String schemaSpec =
+ "<xs:schema targetNamespace='" + uri + "'\n" +
+ " xmlns:eGov_IT='" + uri + "'\n" +
+ " xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
+ " <xs:element name='Riferimento'>\n" +
+ " <xs:complexType>\n" +
+ " <xs:sequence/>\n" +
+ " <xs:attribute ref='eGov_IT:id' use='required'/>\n" +
+ " </xs:complexType>\n" +
+ " </xs:element>\n" +
+ " <xs:attribute name='id' type='xs:ID'/>\n" +
+ "</xs:schema>\n";
+
+ InputSource isource = new InputSource(new StringReader(schemaSpec));
+ isource.setSystemId("jira46.xsd");
+ JAXBSchemaReader r = getSchemaReader();
+ XSParser parser = r.getSGFactory().newXSParser();
+ parser.setValidating(false);
+ XSSchema schema = parser.parse(isource);
+ XSAttribute[] attrs = schema.getAttributes();
+ assertEquals(1, attrs.length);
+ XSAttribute idAttr = attrs[0];
+ assertTrue(idAttr instanceof JAXBAttribute);
+ assertEquals(new XsQName(uri, "id"), idAttr.getName());
+ assertEquals(XSID.getInstance(), idAttr.getType());
+ assertTrue(idAttr.isOptional());
+ XSElement[] elements = schema.getElements();
+ assertEquals(1, elements.length);
+ XSElement rifElem = elements[0];
+ assertFalse(rifElem.getType().isSimple());
+ XSComplexType ct = rifElem.getType().getComplexType();
+ XSAttributable[] rifAttrs = ct.getAttributes();
+ assertEquals(1, rifAttrs.length);
+ XSAttribute idRef = (XSAttribute) rifAttrs[0];
+ assertTrue(idRef instanceof JAXBAttribute);
+ assertFalse(idRef.equals(idAttr));
+ assertEquals(new XsQName(uri, "id"), idAttr.getName());
+ assertEquals(XSID.getInstance(), idAttr.getType());
+ assertFalse(idRef.isOptional());
+ }
}
1.1 ws-jaxme/src/test/jaxb/jira/jaxme-46.xsd
Index: jaxme-46.xsd
===================================================================
<xs:schema targetNamespace='http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/'
xmlns:eGov_IT='http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/'
xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='Riferimento'>
<xs:complexType>
<xs:sequence/>
<xs:attribute ref='eGov_IT:id' use='required'/>
</xs:complexType>
</xs:element>
<xs:attribute name='id' type='xs:ID'/>
</xs:schema>
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic