Author: ajith
Date: Thu Mar 29 13:46:16 2007
New Revision: 523836
URL: http://svn.apache.org/viewvc?view=rev&rev=523836
Log:
1. Added a special method to load the extension registry from a system property
if available.
2. Added a full test case that checks the deserialization of a custom attribute
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttribute.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeDeserializer.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeSerializer.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtDeserializerTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtensionRegistry.java
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/external/
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?view=diff&rev=523836&r1=523835&r2=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
Thu Mar 29 13:46:16 2007
@@ -1864,7 +1864,7 @@
Attr attribute = (Attr)attributes.item(i);
String namespaceURI = attribute.getNamespaceURI();
- String name = attribute.getName();
+ String name = attribute.getLocalName();
if (namespaceURI!= null &&
!"".equals(namespaceURI) && //ignore unqualified
attributes
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java?view=diff&rev=523836&r1=523835&r2=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
Thu Mar 29 13:46:16 2007
@@ -31,11 +31,8 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import org.apache.ws.commons.schema.constants.Constants;
@@ -102,7 +99,7 @@
*/
private Map schemas = new HashMap();
-
+
/**
* base URI is used as the base for loading the
* imports
@@ -253,6 +250,24 @@
SchemaKey key = new SchemaKey(XmlSchema.SCHEMA_NS, null);
addSchema(key, xsd);
+
+ // look for a system property to see whether we have a registered
+ // extension registry class. if so we'll instantiate a new one
+ // and set it as the extension registry
+ //if there is an error, we'll just print out a message and move on.
+
+ if
(System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY)!= null){
+ try {
+ Class clazz =
Class.forName(System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY));
+ this.extReg = (ExtensionRegistry)clazz.newInstance();
+ } catch (ClassNotFoundException e) {
+ System.err.println("The specified extension registry class
cannot be found!");
+ } catch (InstantiationException e) {
+ System.err.println("The specified extension registry class
cannot be instantiated!");
+ } catch (IllegalAccessException e) {
+ System.err.println("The specified extension registry class
cannot be accessed!");
+ }
+ }
}
boolean containsSchema(SchemaKey pKey) {
@@ -334,7 +349,7 @@
SchemaBuilder builder = new SchemaBuilder(this, null);
return builder.handleXmlSchemaElement(elem, null);
}
-
+
public XmlSchema read(Document doc, String uri, ValidationEventHandler
veh) {
return read(doc, uri, veh, null);
}
@@ -379,7 +394,7 @@
}
return (XmlSchema[]) result.toArray(new XmlSchema[result.size()]);
}
-
+
/**
* Returns an array of all the XmlSchemas in this collection.
*/
@@ -387,7 +402,7 @@
Collection c = schemas.values();
return (XmlSchema[]) c.toArray(new XmlSchema[c.size()]);
}
-
+
public XmlSchemaElement getElementByQName(QName qname) {
String uri = qname.getNamespaceURI();
for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext();
) {
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?view=diff&rev=523836&r1=523835&r2=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
Thu Mar 29 13:46:16 2007
@@ -38,6 +38,10 @@
import java.util.Map;
public class XmlSchemaSerializer {
+ /**
+ * Extension registry for the serializer
+ * */
+
private ExtensionRegistry extReg;
public ExtensionRegistry getExtReg() {
@@ -48,6 +52,7 @@
this.extReg = extReg;
}
+
private Hashtable schema_ns;
static String xsdPrefix = "xs";
@@ -2522,11 +2527,17 @@
return docs.createElementNS(namespace, elementName);
}
- //will search whether the prefix is available in global hash table, if it
- //is there than append the prefix to the element name. If not then it will
- //create new prefix corresponding to that namespace and store that in
- //hash table. Finally add the new prefix and namespace to <schema>
- //element
+ /**
+ * will search whether the prefix is available in global hash table, if it
+ * is there than append the prefix to the element name. If not then it
will
+ * create new prefix corresponding to that namespace and store that in
+ * hash table. Finally add the new prefix and namespace to <schema>
+ * element
+ * @param names
+ * @param schemaObj
+ * @return resolved QName of the string
+ */
+
private String resolveQName(QName names,
XmlSchema schemaObj) {
@@ -2600,7 +2611,12 @@
private void processExtensibilityComponents(XmlSchemaObject
schemaObject,Element parentElement){
if (extReg!=null){
- // need to call the extensions registry here
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ if (metaInfoMap!=null && !metaInfoMap.isEmpty()) {
+ //get the extra objects and call the respective deserializers
+
+
+ }
}
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java?view=diff&rev=523836&r1=523835&r2=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java
Thu Mar 29 13:46:16 2007
@@ -23,18 +23,18 @@
*/
public class Constants {
public static final String XMLNS_URI =
- "http://www.w3.org/XML/1998/namespace";
+ "http://www.w3.org/XML/1998/namespace";
public static final String XMLNS_PREFIX =
- "xml";
+ "xml";
//
// Schema Namespaces
//
public static final String URI_2001_SCHEMA_XSD =
- "http://www.w3.org/2001/XMLSchema";
+ "http://www.w3.org/2001/XMLSchema";
public static final String URI_2001_SCHEMA_XSI =
- "http://www.w3.org/2001/XMLSchema-instance";
+ "http://www.w3.org/2001/XMLSchema-instance";
// Define qnames for the all of the XSD and SOAP-ENC encodings
public static final QName XSD_STRING = new QName(URI_2001_SCHEMA_XSD,
"string");
@@ -125,15 +125,22 @@
public static final String EXTERNAL_ELEMENTS = "EXTERNAL_ELEMENTS";
}
+ /**
+ * class holding the the constants for meta data storage
+ */
+ public static class SystemConstants{
+ public static final String EXTENSION_REGISTRY_KEY =
"org.apache.ws.commons.extensions.ExtensionRegistry";
+ }
+
public static final String XMLNS_ATTRIBUTE_NS_URI =
- "http://www.w3.org/2000/xmlns/";
+ "http://www.w3.org/2000/xmlns/";
public static final String XMLNS_ATTRIBUTE = "xmlns";
public static final String DEFAULT_NS_PREFIX = "";
public static final String XML_NS_URI =
- "http://www.w3.org/XML/1998/namespace";
+ "http://www.w3.org/XML/1998/namespace";
public static final String XML_NS_PREFIX = "xml";
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java?view=diff&rev=523836&r1=523835&r2=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
Thu Mar 29 13:46:16 2007
@@ -67,15 +67,15 @@
* @param deserializer - an instance of the deserializer
*/
public void registerDeserializer(QName name,ExtensionDeserializer
deserializer){
- extensionSerializers.put(name,deserializer);
+ extensionDeserializers.put(name,deserializer);
}
/**
* Register a serializer with a Class
* @param classOfType - the class of the object that would be serialized
* @param serializer - an instance of the deserializer
*/
- public void registerserializer(Class classOfType,ExtensionSerializer
serializer){
- extensionDeserializers.put(classOfType,serializer);
+ public void registerSerializer(Class classOfType,ExtensionSerializer
serializer){
+ extensionSerializers.put(classOfType,serializer);
}
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttribute.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttribute.java?view=auto&rev=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttribute.java
(added)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttribute.java
Thu Mar 29 13:46:16 2007
@@ -0,0 +1,35 @@
+package tests.customext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Custom Attribute class
+ * The is will be with reference to the http://customattrib.org
+ * namespace and will have 'customAttrib' as the name and the
+ * value will be a prefix and a suffix seperated with a colon
+ * see the externalAnnotations.xsd for an example schema.
+ */
+public class CustomAttribute {
+
+ public static final QName CUSTOM_ATTRIBUTE_QNAME = new
QName("http://customattrib.org","customAttrib");
+ private String prefix;
+ private String suffix;
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+
+}
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeDeserializer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeDeserializer.java?view=auto&rev=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeDeserializer.java
(added)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeDeserializer.java
Thu Mar 29 13:46:16 2007
@@ -0,0 +1,46 @@
+package tests.customext;
+
+import org.apache.ws.commons.schema.extensions.ExtensionDeserializer;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+import org.w3c.dom.Attr;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author : Ajith Ranabahu
+ * Date: Mar 29, 2007
+ * Time: 3:58:59 PM
+ */
+public class CustomAttributeDeserializer implements ExtensionDeserializer {
+
+ /**
+ * deserialize the given element
+ *
+ * @param schemaObject - Parent schema element
+ * @param name - the QName of the element/attribute to be
deserialized.
+ * in the case where a deserializer is used to handle
multiple elements/attributes
+ * this may be useful to determine the correct
deserialization
+ * @param domNode - the raw DOM Node read from the source. This will
be the
+ * extension element itself if for an element or the
extension attribute object if
+ * it is an attribute
+ */
+ public void deserialize(XmlSchemaObject schemaObject, QName name, Node
domNode) {
+ if (CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.equals(name)){
+ Attr attrib = (Attr)domNode;
+ String value = attrib.getValue();
+ //break the attrib into
+ CustomAttribute customAttrib = new CustomAttribute();
+ String[] strings = value.split(":");
+ customAttrib.setPrefix(strings[0]);
+ customAttrib.setSuffix(strings[1]);
+
+ //put this in the schema object meta info map
+
schemaObject.addMetaInfo(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME,customAttrib);
+
+
+
+
+ }
+ }
+}
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeSerializer.java?view=auto&rev=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeSerializer.java
(added)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomAttributeSerializer.java
Thu Mar 29 13:46:16 2007
@@ -0,0 +1,24 @@
+package tests.customext;
+
+import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+/**
+ * serializer for the custom attribute
+ */
+public class CustomAttributeSerializer implements ExtensionSerializer {
+
+ /**
+ * serialize the given element
+ *
+ * @param schemaObject - Parent schema object.contains the extension
+ * to be serialized
+ * @param classOfType - The class of type to be serialized
+ * @param domNode - the parent DOM Node that will ultimately be
serialized. The XMLSchema
+ * serialization mechanism is to create a DOM tree
first and serialize it
+ */
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType,
Node domNode) {
+
+ }
+}
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtDeserializerTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtDeserializerTest.java?view=auto&rev=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtDeserializerTest.java
(added)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtDeserializerTest.java
Thu Mar 29 13:46:16 2007
@@ -0,0 +1,54 @@
+package tests.customext;
+
+import junit.framework.TestCase;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.constants.Constants;
+import tests.Resources;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Deserialize the custom extension types
+ */
+public class CustomExtDeserializerTest extends TestCase {
+
+
+ public void testSimpleTypeSchemaGeneration() throws Exception {
+ //set the system property for the custom extension registry
+
System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+ CustomExtensionRegistry.class.getName());
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ CustomAttribute customAttrib =
(CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
+ assertNotNull(customAttrib);
+
+ }
+
+ }
+}
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtensionRegistry.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtensionRegistry.java?view=auto&rev=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtensionRegistry.java
(added)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/CustomExtensionRegistry.java
Thu Mar 29 13:46:16 2007
@@ -0,0 +1,18 @@
+package tests.customext;
+
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+
+/**
+ * Custom extension registry to test the functionality
+ * of the extension mechanism
+ */
+public class CustomExtensionRegistry extends ExtensionRegistry {
+
+ public CustomExtensionRegistry() {
+ //register our custom type
+ registerDeserializer(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME,new
CustomAttributeDeserializer());
+ registerSerializer(CustomAttribute.class,new
CustomAttributeSerializer());
+ }
+
+
+}
Added:
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd?view=auto&rev=523836
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd
(added)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd
Thu Mar 29 13:46:16 2007
@@ -0,0 +1,19 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ xmlns:ext="http://customattrib.org"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="Struct" ext:customAttrib="toplevel:type">
+ <sequence>
+ <element name="varString" type="xsd:string"
ext:customAttrib="inner:element"/>
+ <element name="varInt" type="xsd:int"
ext:customAttrib="inner:element"/>
+ <element name="varFloat" type="xsd:float"
ext:customAttrib="inner:element"/>
+ <element name="varStruct" type="tns:Struct"
ext:customAttrib="inner:element"/>
+ </sequence>
+ </complexType>
+
+ <element name="attrTest" type="tns:Struct"
ext:customAttrib="toplevel:element"/>
+
+</schema>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]