You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/09/02 08:47:43 UTC
cvs commit: ws-jaxme/src/xs/org/apache/ws/jaxme/xs/xml/impl XsTWildcardImpl.java
jochen 2004/09/01 23:47:43
Modified: src/xs/org/apache/ws/jaxme/xs/junit ParserTest.java
src/xs/org/apache/ws/jaxme/xs/xml XsNamespaceList.java
src/xs/org/apache/ws/jaxme/xs/xml/impl XsTWildcardImpl.java
Log:
Made XsNamespaceList a mutable object. This is required, when importing a schema without namespace
into another schema.
PR: JAXME-24
Obtained from: Mik Lernout, mik at futurestreet.org
Revision Changes Path
1.19 +49 -4 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ParserTest.java 27 Aug 2004 20:49:30 -0000 1.18
+++ ParserTest.java 2 Sep 2004 06:47:42 -0000 1.19
@@ -22,6 +22,7 @@
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;
@@ -1203,6 +1204,24 @@
" </xs:sequence>\n" +
" </xs:complexType>\n" +
" </xs:element>\n" +
+ "\n" +
+ " <xs:element name='AnyAttribute'>\n" +
+ " <xs:complexType>\n" +
+ " <xs:anyAttribute namespace='##any'/>\n" +
+ " </xs:complexType>\n" +
+ " </xs:element>\n" +
+ "\n" +
+ " <xs:element name='OtherAttribute'>\n" +
+ " <xs:complexType>\n" +
+ " <xs:anyAttribute namespace='##other'/>\n" +
+ " </xs:complexType>\n" +
+ " </xs:element>\n" +
+ "\n" +
+ " <xs:element name='ListAttribute'>\n" +
+ " <xs:complexType>\n" +
+ " <xs:anyAttribute namespace='##targetNamespace http://ws.apache.org/jaxme/test/misc/wildcards/2'/>\n" +
+ " </xs:complexType>\n" +
+ " </xs:element>\n" +
"</xs:schema>\n";
pParser.getContext().setXsObjectFactory(new XsObjectFactoryImpl(){
@@ -1224,11 +1243,37 @@
isource.setSystemId("testImportSchemaWithoutNamespace.xsd");
XSSchema schema = pParser.parse(isource);
XSElement[] elements = schema.getElements();
- assertEquals(4, elements.length);
+ assertEquals(7, elements.length);
assertEquals(new XsQName("xyz", "c"), elements[0].getName());
assertEquals(new XsQName("xyz", "d"), elements[1].getName());
- assertEquals(new XsQName("xyz", "a"), elements[2].getName());
- assertEquals(new XsQName("xyz", "b"), elements[3].getName());
+ XSComplexType anyAttrElem = assertComplexType(elements[2].getType());
+ XSAttributable[] attrs = anyAttrElem.getAttributes();
+ assertEquals(1, attrs.length);
+ assertTrue(attrs[0] instanceof XSWildcard);
+ XSWildcard wc = (XSWildcard) attrs[0];
+ XsNamespaceList nsl = wc.getNamespaceList();
+ assertTrue(nsl.isAny());
+ assertNull(nsl.getUris());
+ XSComplexType otherAttrElem = assertComplexType(elements[3].getType());
+ attrs = otherAttrElem.getAttributes();
+ assertEquals(1, attrs.length);
+ assertTrue(attrs[0] instanceof XSWildcard);
+ nsl = ((XSWildcard) attrs[0]).getNamespaceList();
+ assertTrue(nsl.isOther());
+ assertEquals(1, nsl.getUris().length);
+ assertEquals("xyz", nsl.getUris()[0].toString());
+ XSComplexType listAttrElem = assertComplexType(elements[4].getType());
+ attrs = listAttrElem.getAttributes();
+ assertEquals(1, attrs.length);
+ assertTrue(attrs[0] instanceof XSWildcard);
+ nsl = ((XSWildcard) attrs[0]).getNamespaceList();
+ assertTrue(!nsl.isOther());
+ assertTrue(!nsl.isAny());
+ assertEquals(2, nsl.getUris().length);
+ assertEquals("xyz", nsl.getUris()[0].toString());
+ assertEquals("http://ws.apache.org/jaxme/test/misc/wildcards/2", nsl.getUris()[1].toString());
+ assertEquals(new XsQName("xyz", "a"), elements[5].getName());
+ assertEquals(new XsQName("xyz", "b"), elements[6].getName());
}
/** <p>Tests, whether importing a schema without namespace
1.4 +11 -13 ws-jaxme/src/xs/org/apache/ws/jaxme/xs/xml/XsNamespaceList.java
Index: XsNamespaceList.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/xml/XsNamespaceList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XsNamespaceList.java 15 Aug 2004 11:46:29 -0000 1.3
+++ XsNamespaceList.java 2 Sep 2004 06:47:43 -0000 1.4
@@ -80,9 +80,9 @@
/** <p>A namespace list matching "##other" with the given
* target namespace <code>pTargetNamespace</code>.</p>
*/
- static class Other extends XsNamespaceList {
+ public static class Other extends XsNamespaceList {
private final XsAnyURI[] uris;
- Other(XsAnyURI pTargetNamespace) {
+ protected Other(XsAnyURI pTargetNamespace) {
if (pTargetNamespace == null) {
pTargetNamespace = new XsAnyURI("");
}
@@ -102,21 +102,23 @@
public String toString() { return "##other"; }
/** <p>Returns getUris()[0].hashCode().</p>
*/
- public int hashCode() { return uris[0].hashCode(); }
+ public int hashCode() { return getUris()[0].hashCode(); }
/** <p>Returns, whether this is an instance of
* {@link Other} with the same target namespace.</p>
*/
public boolean equals(Object pOther) {
return pOther != null
&& (pOther instanceof Other)
- && uris[0].equals(((Other) pOther).uris[0]);
+ && getUris()[0].equals(((Other) pOther).getUris()[0]);
}
}
- static class Basic extends XsNamespaceList {
- private final XsAnyURI[] uris;
+ public static class Basic extends XsNamespaceList {
+ private final XsAnyURI targetNamespace;
+ private final XsAnyURI[] uris;
private final String toStr;
- Basic(String pValue, XsAnyURI pTargetNamespace) {
+ protected Basic(String pValue, XsAnyURI pTargetNamespace) {
+ targetNamespace = pTargetNamespace;
toStr = pValue;
Set set = new HashSet();
if (pTargetNamespace == null) {
@@ -133,11 +135,6 @@
}
}
uris = (XsAnyURI[]) set.toArray(new XsAnyURI[set.size()]);
- Arrays.sort(uris, new Comparator(){
- public int compare(Object pO1, Object pO2) {
- return ((XsAnyURI) pO1).getURI().compareTo(((XsAnyURI) pO2).getURI());
- }
- });
}
/** @return false
*/
@@ -157,6 +154,7 @@
* the result of {@link #getUris()}.</p>
*/
public int hashCode() {
+ XsAnyURI[] uris = getUris();
int hash = uris.length;
for (int i = 0; i < uris.length; i++) {
hash += uris[i].hashCode();
@@ -169,7 +167,7 @@
public boolean equals(Object pOther) {
return pOther != null
&& pOther instanceof Basic
- && Arrays.equals(uris, ((Basic) pOther).uris);
+ && Arrays.equals(getUris(), ((Basic) pOther).getUris());
}
}
1.4 +36 -2 ws-jaxme/src/xs/org/apache/ws/jaxme/xs/xml/impl/XsTWildcardImpl.java
Index: XsTWildcardImpl.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/xml/impl/XsTWildcardImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XsTWildcardImpl.java 15 Aug 2004 11:46:29 -0000 1.3
+++ XsTWildcardImpl.java 2 Sep 2004 06:47:43 -0000 1.4
@@ -17,6 +17,8 @@
package org.apache.ws.jaxme.xs.xml.impl;
import org.apache.ws.jaxme.xs.xml.*;
+import org.apache.ws.jaxme.xs.xml.XsNamespaceList.Basic;
+import org.apache.ws.jaxme.xs.xml.XsNamespaceList.Other;
/** <p>Implementation of the <code>xs:wildcard</code> type, with the
@@ -50,8 +52,40 @@
super(pParent);
}
- public void setNamespace(String pNamespaceList) {
- namespaceList = XsNamespaceList.valueOf(pNamespaceList, getXsESchema().getTargetNamespace());
+ public void setNamespace(final String pNamespaceList) {
+ if (getXsESchema().getTargetNamespace() == null) {
+ // The target can be changed, when importing this schema,
+ // thus we have to return a mutable object.
+ XsAnyURI pTargetNamespace = getXsESchema().getTargetNamespace();
+ if ("##any".equals(pNamespaceList)) {
+ namespaceList = XsNamespaceList.ANY;
+ } else if ("##other".equals(pNamespaceList)) {
+ namespaceList = new Other(pTargetNamespace){
+ public XsAnyURI[] getUris() {
+ XsAnyURI targetNamespace = getXsESchema().getTargetNamespace();
+ if (targetNamespace == null) {
+ return super.getUris();
+ } else {
+ return new XsAnyURI[]{targetNamespace};
+ }
+ }
+ };
+ } else {
+ namespaceList = new Basic(pNamespaceList, pTargetNamespace){
+ public XsAnyURI[] getUris() {
+ XsAnyURI targetNamespace = getXsESchema().getTargetNamespace();
+ if (targetNamespace == null) {
+ return super.getUris();
+ } else {
+ return XsNamespaceList.valueOf(pNamespaceList, targetNamespace).getUris();
+ }
+ }
+ };
+ };
+ } else {
+ // The target cannot be changed, so we return an immutable object.
+ namespaceList = XsNamespaceList.valueOf(pNamespaceList, getXsESchema().getTargetNamespace());
+ }
}
public XsNamespaceList getNamespace() {
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org