You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by aj...@apache.org on 2007/03/05 22:13:10 UTC
svn commit: r514868 - in
/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema:
./ constants/ extensions/
Author: ajith
Date: Mon Mar 5 13:13:09 2007
New Revision: 514868
URL: http://svn.apache.org/viewvc?view=rev&rev=514868
Log:
1. Adding the change proposed in WSCOMMONS-171 (https://issues.apache.org/jira/browse/WSCOMMONS-171)
I. Added the new set of classes to handle extension
II. Modified the schemaBuilder and schemaCollection to take an extra parameter, the extension registry
Note - the serializer changes are not complete but the existing tests cases run just fine. Would be adding more test cases as soon as the serializer change is complete
Added:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java
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/XmlSchemaObject.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
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=514868&r1=514867&r2=514868
==============================================================================
--- 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 Mon Mar 5 13:13:09 2007
@@ -17,8 +17,6 @@
package org.apache.ws.commons.schema;
-import java.util.HashMap;
-import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -31,6 +29,7 @@
import org.apache.ws.commons.schema.utils.NodeNamespaceContext;
import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
import org.apache.ws.commons.schema.utils.XDOMUtil;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -47,12 +46,31 @@
DocumentBuilderFactory docFac;
/**
+ * The extension registry to be used while building the
+ * schema model
+ */
+ private ExtensionRegistry extReg = null;
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
+ /**
* Schema builder constructor
* @param collection
*/
SchemaBuilder(XmlSchemaCollection collection, TargetNamespaceValidator validator) {
this.collection = collection;
this.validator = validator;
+
+ if (collection.getExtReg()!=null){
+ this.extReg = collection.getExtReg();
+ }
+
schema = new XmlSchema(collection);
}
@@ -180,7 +198,7 @@
schema.notations.collection.put(notation.name, notation);
schema.items.add(notation);
} else if (el.getLocalName().equals("annotation")) {
- XmlSchemaAnnotation annotation = handleAnnotation(el);
+ XmlSchemaAnnotation annotation = handleAnnotation(el);
schema.setAnnotation(annotation);
}
}
@@ -352,8 +370,8 @@
XmlSchema.SCHEMA_NS, "simpleType");
if (restrictionEl.hasAttribute("base")) {
- NamespaceContext ctx = new NodeNamespaceContext(restrictionEl);
- restriction.baseTypeName = getRefQName(restrictionEl.getAttribute("base"), ctx);
+ NamespaceContext ctx = new NodeNamespaceContext(restrictionEl);
+ restriction.baseTypeName = getRefQName(restrictionEl.getAttribute("base"), ctx);
} else if (inlineSimpleType != null) {
restriction.baseType = handleSimpleType(schema, inlineSimpleType, schemaEl);
@@ -493,32 +511,32 @@
}
private QName getRefQName(String pName, NamespaceContext pContext) {
- final int offset = pName.indexOf(':');
- String uri;
- final String localName;
- final String prefix;
- if (offset == -1) {
- uri = pContext.getNamespaceURI(Constants.DEFAULT_NS_PREFIX);
- if (Constants.NULL_NS_URI.equals(uri)) {
- return new QName(schema.logicalTargetNamespace, pName);
- }
- localName = pName;
- prefix = Constants.DEFAULT_NS_PREFIX;
- } else {
- prefix = pName.substring(0, offset);
- uri = pContext.getNamespaceURI(prefix);
+ final int offset = pName.indexOf(':');
+ String uri;
+ final String localName;
+ final String prefix;
+ if (offset == -1) {
+ uri = pContext.getNamespaceURI(Constants.DEFAULT_NS_PREFIX);
+ if (Constants.NULL_NS_URI.equals(uri)) {
+ return new QName(schema.logicalTargetNamespace, pName);
+ }
+ localName = pName;
+ prefix = Constants.DEFAULT_NS_PREFIX;
+ } else {
+ prefix = pName.substring(0, offset);
+ uri = pContext.getNamespaceURI(prefix);
if (uri == null || Constants.NULL_NS_URI.equals(uri)) {
if(schema.parent != null && schema.parent.getNamespaceContext() != null) {
uri = schema.parent.getNamespaceContext().getNamespaceURI(prefix);
}
}
- if (uri == null || Constants.NULL_NS_URI.equals(uri)) {
+ if (uri == null || Constants.NULL_NS_URI.equals(uri)) {
throw new IllegalStateException("The prefix " + prefix + " is not bound.");
- }
- localName = pName.substring(offset+1);
- }
- return new QName(uri, localName, prefix);
+ }
+ localName = pName.substring(offset+1);
+ }
+ return new QName(uri, localName, prefix);
}
/**
@@ -687,10 +705,10 @@
if (el.getLocalName().equals("restriction")) {
complexContent.content = handleComplexContentRestriction(schema, el,
- schemaEl);
+ schemaEl);
} else if (el.getLocalName().equals("extension")) {
complexContent.content = handleComplexContentExtension(schema, el,
- schemaEl);
+ schemaEl);
} else if (el.getLocalName().equals("annotation")) {
complexContent.setAnnotation(handleAnnotation(el));
}
@@ -1158,6 +1176,7 @@
return new QName(uri, pLocalName);
}
+
private XmlSchemaAttribute handleAttribute(XmlSchema schema,
Element attrEl, Element schemaEl) {
//todo: need to implement different rule of attribute such as
@@ -1172,7 +1191,7 @@
attr.name = name;
}
-
+
boolean isQualified = schema.getAttributeFormDefault().getValue().equals(XmlSchemaForm.QUALIFIED);
if (attr.name != null) {
final String name = attr.name;
@@ -1800,12 +1819,12 @@
if (schema != null) {
return schema;
}
- try {
+ try {
return collection.read(source, null, validator);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
+ }
/**
* Resolve the schemas
@@ -1823,36 +1842,55 @@
/**
* A generic method to process the extra attributes and the the extra
* elements present within the schema.
- * What it does right now is to attach extra attributes to a map
- * having QName/value pairs and store the map in the metadata section
- * of the schema object
+ * What are considered extensions are child elements with non schema namespace
+ * and child attributes with any namespace
* @param schemaObject
- * @param elt
+ * @param parentElement
*/
- private void processExtensibilityComponents(XmlSchemaObject schemaObject,Element elt){
- Map attribMap = new HashMap();
- NamedNodeMap attributes = elt.getAttributes();
- for (int i=0 ;i < attributes.getLength();i++){
- Attr attribute = (Attr)attributes.item(i);
-
- String namespaceURI = attribute.getNamespaceURI();
- String name = attribute.getName();
-
- if (namespaceURI!= null &&
- !"".equals(namespaceURI) && //ignore unqualified attributes
- !name.startsWith(Constants.XMLNS_ATTRIBUTE) && //ignore namespaces
- !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI)){
- attribMap.put(new QName(namespaceURI,name),
- attribute.getValue());
+ private void processExtensibilityComponents(XmlSchemaObject schemaObject,Element parentElement){
+
+ if (extReg!=null){
+ //process attributes
+ NamedNodeMap attributes = parentElement.getAttributes();
+ for (int i=0 ;i < attributes.getLength();i++){
+ Attr attribute = (Attr)attributes.item(i);
+
+ String namespaceURI = attribute.getNamespaceURI();
+ String name = attribute.getName();
+
+ if (namespaceURI!= null &&
+ !"".equals(namespaceURI) && //ignore unqualified attributes
+ !name.startsWith(Constants.XMLNS_ATTRIBUTE) && //ignore namespaces
+ !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI))
+ //does not belong to the schema namespace by any chance!
+ {
+ QName qName = new QName(namespaceURI,name);
+ extReg.deserializeExtension(schemaObject,qName,attribute);
+
+
+ }
}
- }
- if (!attribMap.isEmpty()){
- schemaObject.addMetaInfo(
- Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES,
- attribMap
- );
+ //process elements
+ NodeList allChildren = parentElement.getChildNodes();
+ for (int i=0 ;i < allChildren.getLength();i++){
+ if (allChildren.item(i).getNodeType()==Node.ELEMENT_NODE){
+
+ Element extElement = (Element)allChildren.item(i);
+
+ String namespaceURI = extElement.getNamespaceURI();
+ String name = extElement.getLocalName();
+
+ if (namespaceURI!= null &&
+ !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI))
+ //does not belong to the schema namespace
+ {
+ QName qName = new QName(namespaceURI,name);
+ extReg.deserializeExtension(schemaObject,qName,extElement);
+ }
+ }
+ }
}
}
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=514868&r1=514867&r2=514868
==============================================================================
--- 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 Mon Mar 5 13:13:09 2007
@@ -42,6 +42,7 @@
import org.apache.ws.commons.schema.resolver.URIResolver;
import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -53,6 +54,19 @@
*
*/
public final class XmlSchemaCollection {
+
+ // the default extension registry
+ private ExtensionRegistry extReg = new ExtensionRegistry();
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
+
static class SchemaKey {
private final String namespace;
private final String systemId;
Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java?view=diff&rev=514868&r1=514867&r2=514868
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java Mon Mar 5 13:13:09 2007
@@ -41,6 +41,14 @@
}
/**
+ * Directly set the meta info map into the schema element
+ * @param metaInfoMap
+ */
+ public void setMetaInfoMap(Map metaInfoMap) {
+ this.metaInfoMap = metaInfoMap;
+ }
+
+ /**
* Add a value to the meta info map
* will be initialized if not used
* previously
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=514868&r1=514867&r2=514868
==============================================================================
--- 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 Mon Mar 5 13:13:09 2007
@@ -18,6 +18,7 @@
import org.apache.ws.commons.schema.constants.Constants;
import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -36,6 +37,17 @@
import java.util.Iterator;
import java.util.Map;
public class XmlSchemaSerializer {
+
+ private ExtensionRegistry extReg;
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
private Hashtable schema_ns;
static String xsdPrefix = "xs";
@@ -108,10 +120,10 @@
}
String prefix = null;
if(schemaObj.getNamespaceContext() != null) {
- prefix = schemaObj.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);
+ prefix = schemaObj.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);
}
if(prefix == null && schemaObj.parent != null && schemaObj.parent.getNamespaceContext() != null) {
- prefix = schemaObj.parent.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);
+ prefix = schemaObj.parent.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);
}
if(prefix == null) {
prefix = "";
@@ -269,7 +281,7 @@
NamespacePrefixList ctx = schemaObj.getNamespaceContext();
schemaObj.schema_ns_prefix = xsdPrefix = ctx.getPrefix(xsdNamespace);
if(xsdPrefix == null) {
- schemaObj.schema_ns_prefix = xsdPrefix = "";
+ schemaObj.schema_ns_prefix = xsdPrefix = "";
}
String[] prefixes = ctx.getDeclaredPrefixes();
for (int i = 0; i < prefixes.length; i++) {
@@ -608,7 +620,7 @@
}
}
if (elementObj.isNillable) {
- serializedEl.setAttribute("nillable", "true");
+ serializedEl.setAttribute("nillable", "true");
}
return serializedEl;
@@ -2575,4 +2587,23 @@
super(msg);
}
}
+
+
+ /**
+ * A generic method to process the extra attributes and the the extra
+ * elements present within the schema.
+ * What are considered extensions are child elements with non schema namespace
+ * and child attributes with any namespace
+ * @param schemaObject
+ * @param parentElement
+ */
+ private void processExtensibilityComponents(XmlSchemaObject schemaObject,Element parentElement){
+
+ if (extReg!=null){
+ // need to call the extensions registry here
+
+ }
+
+ }
+
}
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=514868&r1=514867&r2=514868
==============================================================================
--- 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 Mon Mar 5 13:13:09 2007
@@ -122,6 +122,7 @@
*/
public static class MetaDataConstants{
public static final String EXTERNAL_ATTRIBUTES = "EXTERNAL_ATTRIBUTES";
+ public static final String EXTERNAL_ELEMENTS = "EXTERNAL_ELEMENTS";
}
public static final String XMLNS_ATTRIBUTE_NS_URI =
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java?view=auto&rev=514868
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java Mon Mar 5 13:13:09 2007
@@ -0,0 +1,73 @@
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Default deserializer. The action taken when there is nothing specific
+ * to be done would be to attach the raw element object as it is to the
+ * meta information map for an element or the raw attribute object
+ *
+ */
+public class DefaultExtensionDeserializer 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 node - 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 node) {
+
+ // we just attach the raw node either to the meta map of
+ // elements or the attributes
+ Map metaInfoMap = new HashMap();
+
+
+
+ if (node.getNodeType()==Node.ATTRIBUTE_NODE){
+
+ Map attribMap;
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
+ attribMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
+ }else{
+ attribMap = new HashMap();
+ metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES,attribMap);
+ }
+ attribMap.put(name,node);
+
+ }else if (node.getNodeType()==Node.ELEMENT_NODE){
+ Map elementMap;
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ELEMENTS)){
+ elementMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ELEMENTS);
+ }else{
+ elementMap = new HashMap();
+ metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ELEMENTS,elementMap);
+ }
+ elementMap.put(name,node);
+ }
+
+ //subsequent processing takes place only if this map is not empty
+ if (!metaInfoMap.isEmpty()){
+ Map metaInfoMapFromSchemaElement = schemaObject.getMetaInfoMap();
+ if (metaInfoMapFromSchemaElement==null){
+ schemaObject.setMetaInfoMap(metaInfoMap);
+ }else{
+ metaInfoMapFromSchemaElement.putAll(metaInfoMap);
+ }
+
+ }
+
+
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java?view=auto&rev=514868
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java Mon Mar 5 13:13:09 2007
@@ -0,0 +1,55 @@
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Node;
+import org.w3c.dom.Document;
+
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+
+ */
+public class DefaultExtensionSerializer implements ExtensionSerializer{
+
+ /**
+ * serialize the given element
+ *
+ * @param schemaObject - Parent schema element
+ * @param classOfType - the class of the object to be serialized
+ * @param node - The DOM Node that is the parent of the serialzation
+ */
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node node) {
+ // serialization is somewhat tricky in most cases hence this default serializer will
+ // do the exact reverse of the deserializer - look for any plain 'as is' items
+ // and attach them to the parent node.
+ // we just attach the raw node either to the meta map of
+ // elements or the attributes
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ Document parentDoc = node.getOwnerDocument();
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
+ Map attribMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
+ for(Iterator it = attribMap.keySet().iterator();it.hasNext();){
+ Object key = it.next();
+ Object value = attribMap.get(key);
+ // this comparison may not be the most ideal but lets keep it for now
+ if (value.getClass().equals(classOfType)){
+// Attr newAtt =
+ }
+
+ node.appendChild(
+ parentDoc.importNode((Node)it.next(),true));
+ }
+ }
+
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ELEMENTS)){
+ Map elementMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ELEMENTS);
+ for(Iterator it = elementMap.values().iterator();it.hasNext();){
+ node.appendChild(
+ parentDoc.importNode((Node)it.next(),true));
+ }
+ }
+
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java?view=auto&rev=514868
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java Mon Mar 5 13:13:09 2007
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Interface for the extension deserializer. The purpose of an instance
+ * of this is to deserialize the relevant attribute/element and perhaps generate
+ * a desired custom object. This custom object can be stored in the metadata map
+ * of the parent schema object. When to invoke a given deserializer is a decision
+ * taken by the extension registry
+ */
+public interface 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);
+
+}
Added: 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=auto&rev=514868
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java Mon Mar 5 13:13:09 2007
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The task of the extension serializer is to delegate the serilization of
+ * the extensions. The extension serializers/deserializers are retained in seperate
+ * maps and there are also two seperate references to default serializers and deserializers
+ * which would jump into action when there are no specifically attached
+ * serializers/deserializers
+ */
+public class ExtensionRegistry {
+
+ /**
+ * Maps for the storage of extension serializers /deserializers
+ */
+ private Map extensionSerializers = new HashMap();
+ private Map extensionDeserializers = new HashMap();
+
+ /**
+ * Default serializer and serializer
+ */
+ private ExtensionSerializer defaultExtensionSerializer =new DefaultExtensionSerializer();
+ private ExtensionDeserializer defaultExtensionDeserializer = new DefaultExtensionDeserializer();
+
+
+ public ExtensionSerializer getDefaultExtensionSerializer() {
+ return defaultExtensionSerializer;
+ }
+
+ public void setDefaultExtensionSerializer(ExtensionSerializer defaultExtensionSerializer) {
+ this.defaultExtensionSerializer = defaultExtensionSerializer;
+ }
+
+ public ExtensionDeserializer getDefaultExtensionDeserializer() {
+ return defaultExtensionDeserializer;
+ }
+
+ public void setDefaultExtensionDeserializer(ExtensionDeserializer defaultExtensionDeserializer) {
+ this.defaultExtensionDeserializer = defaultExtensionDeserializer;
+ }
+
+ /**
+ * Register a deserializer with a QName
+ * @param name - the QName of the element/attribute
+ * @param deserializer - an instance of the deserializer
+ */
+ public void registerDeserializer(QName name,ExtensionDeserializer deserializer){
+ extensionSerializers.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);
+ }
+
+
+ /**
+ * remove the registration for a serializer with a QName
+ * @param name - the QName of the element/attribute the
+ * serializer is associated with
+ */
+ public void unregisterSerializer(QName name){
+ extensionSerializers.remove(name);
+ }
+
+ /**
+ * remove the registration for a deserializer with a QName
+ * @param classOfType - the the
+ * deserializer is associated with
+ */
+ public void unregisterDeserializer(Class classOfType){
+ extensionDeserializers.remove(classOfType);
+ }
+
+
+ /**
+ * Serialize a given extension element
+ * @param parentSchemaObject - the parent schema object. This is what
+ * would contain the extension object, probably in side its meta information
+ * map
+ * @param classOfType - The class of type to be serialized
+ * @param node - 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 serializeExtension(XmlSchemaObject parentSchemaObject,
+ Class classOfType,
+ Node node){
+ Object serializerObject = extensionSerializers.get(classOfType);
+ if (serializerObject!=null){
+ //perform the serialization
+ ExtensionSerializer ser = (ExtensionSerializer)serializerObject;
+ ser.serialize(parentSchemaObject,classOfType,node);
+ }else if (defaultExtensionSerializer!=null) {
+ defaultExtensionSerializer.serialize(parentSchemaObject,classOfType,node);
+ }
+
+
+ }
+
+
+ /**
+ * Deserialize a given extension element
+ * @param parentSchemaObject - the parent schema object. This is anticipated
+ * to be created already and the relevant object would contain the extension
+ * object, probably in side its meta information map
+ * @param name - The qname of the element/attribute to be deserialized. This will be used to
+ * search for the extension as well as by the deserializer if a single deserializer is
+ * registered against a number of qnames
+ * @param rawNode - the raw DOM Node read from the source. This will be the
+ * extension element itself if for an element or extension attribute itself
+ * in case of an attribute
+ */
+ public void deserializeExtension(XmlSchemaObject parentSchemaObject,
+ QName name,
+ Node rawNode){
+ Object deserializerObject = extensionDeserializers.get(name);
+ if (deserializerObject !=null){
+ //perform the serialization
+ ExtensionDeserializer deser = (ExtensionDeserializer)deserializerObject;
+ deser.deserialize(parentSchemaObject,name,rawNode);
+ } else if (defaultExtensionDeserializer!=null){
+ defaultExtensionDeserializer.deserialize(parentSchemaObject,name,rawNode);
+ }
+ }
+
+}
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java?view=auto&rev=514868
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java Mon Mar 5 13:13:09 2007
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+
+/**
+ * Interface for the extension serializer. The purpose of an instance
+ * of this is to serialize the relevant custom object
+ * and generate attribute/elementa desired . This custom object
+ * may be stored in the metadata map
+ * of the parent schema object. When to invoke a given serializer is a decision
+ * taken by the extension registry
+ */
+public interface 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);
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org