axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/message/events CharactersEvent.java EndElementEvent.java StartElementEvent.java
Date Thu, 03 May 2001 14:32:49 GMT
gdaniels    01/05/03 07:32:48

  Modified:    java/src/org/apache/axis/deployment
                        SimpleDeploymentManager.java
               java/src/org/apache/axis/encoding
                        DeserializationContext.java DeserializerBase.java
                        SOAPEncoding.java SOAPTypeMappingRegistry.java
                        SerializationContext.java Serializer.java
                        TypeMappingRegistry.java
               java/src/org/apache/axis/message ElementRecorder.java
                        MessageElement.java RPCElement.java RPCParam.java
                        SOAPHeader.java SOAPSAXHandler.java
               java/src/org/apache/axis/message/events CharactersEvent.java
                        EndElementEvent.java StartElementEvent.java
  Added:       java/src/org/apache/axis/encoding DeserializerFactory.java
  Removed:     java/src/org/apache/axis/encoding TypeMapper.java
  Log:
  First cut at a more real encoding system, which supports mapping arbitrary
  types to serializers/deserializers.  Needs cleanup (especially in terms of
  how the various pieces learn about each other), but the basic structure
  works.  See samples/encoding for a demo of encoding a custom data
  type.
  
  Revision  Changes    Path
  1.2       +3 -2      xml-axis/java/src/org/apache/axis/deployment/SimpleDeploymentManager.java
  
  Index: SimpleDeploymentManager.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/SimpleDeploymentManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleDeploymentManager.java	2001/04/29 17:24:58	1.1
  +++ SimpleDeploymentManager.java	2001/05/03 14:31:35	1.2
  @@ -117,8 +117,9 @@
               if (tmr == null) tmr = new TypeMappingRegistry();
               Serializer s = (Serializer)t.getSerializer().newInstance();
               Deserializer d = (Deserializer)t.getDeserializer().newInstance();
  -            tmr.addSerializer(t.getLanguageSpecificType(), s);
  -            tmr.addDeserializer(t.getQName(), d);
  +            // !!! FIXME - new serializer/deserializer system!
  +            //tmr.addSerializer(t.getLanguageSpecificType(), s);
  +            //tmr.addDeserializer(t.getQName(), d);
           }
           
           // deploy handlers
  
  
  
  1.2       +16 -2     xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java
  
  Index: DeserializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeserializationContext.java	2001/04/26 23:03:08	1.1
  +++ DeserializationContext.java	2001/05/03 14:31:43	1.2
  @@ -72,11 +72,12 @@
   {
       public SOAPSAXHandler baseHandler;
       public Hashtable idMappings = new Hashtable();
  -    public TypeMapper typeMappings = new TypeMapper();
  +    public TypeMappingRegistry mappingRegistry = new SOAPTypeMappingRegistry();
       
       public DeserializationContext(SOAPSAXHandler baseHandler)
       {
           this.baseHandler = baseHandler;
  +        mappingRegistry.setDeserializationContext(this);
       }
       
       public void pushElementHandler(ContentHandler handler)
  @@ -89,6 +90,19 @@
           return (String)baseHandler.getNamespaceURI(prefix);
       }
       
  +    public void setTypeMappingRegistry(TypeMappingRegistry reg)
  +    {
  +        mappingRegistry = reg;
  +        if (reg != null) {
  +            reg.setDeserializationContext(this);
  +        }
  +    }
  +
  +    public TypeMappingRegistry getTypeMappingRegistry()
  +    {
  +        return mappingRegistry;
  +    }
  +    
       public void registerID(String id, MessageElement element)
       {
           // Throw an exception if already registered?
  @@ -102,6 +116,6 @@
       
       public DeserializerBase getDeserializer(QName qName)
       {
  -        return typeMappings.getDeserializer(qName);
  +        return mappingRegistry.getDeserializer(qName);
       }
   }
  
  
  
  1.2       +48 -39    xml-axis/java/src/org/apache/axis/encoding/DeserializerBase.java
  
  Index: DeserializerBase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializerBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeserializerBase.java	2001/04/26 23:03:08	1.1
  +++ DeserializerBase.java	2001/05/03 14:31:44	1.2
  @@ -74,80 +74,89 @@
   
   public class DeserializerBase extends DefaultHandler
   {
  -    public static long STARTDOCUMENT  = 0x0002;
  -    public static long ENDDOCUMENT    = 0x0004;
  -    public static long STARTPREFIXMAP = 0x0008;
  -    public static long ENDPREFIXMAP   = 0x0010;
  -    public static long STARTELEMENT   = 0x0020;
  -    public static long ENDELEMENT     = 0x0040;
  -    public static long CHARACTERS     = 0x0080;
  -    public static long WHITESPACE     = 0x0100;
  -    public static long SKIPPEDENTITY  = 0x0200;
  -    public static long PROCESSINGINST = 0x0400;
  -    
  -    private long allowedEvents = 0;
       protected Object value = null;
  +    protected DeserializationContext context = null;
  +    protected DeserializerBase parent = null;
       
       public Object getValue()
       {
           return value;
       }
  +    
  +    public void setDeserializationContext(DeserializationContext context)
  +    {
  +        this.context = context;
  +    }
  +    
  +    public void setParent(DeserializerBase parent)
  +    {
  +        this.parent = parent;
  +    }
       
  -    protected void setAllowedEvents(long mask)
  +    /** Deserialization structure handlers
  +     */
  +    public void onEndChild(String localName, DeserializerBase deserializer)
  +        throws SAXException
       {
  -        allowedEvents = mask;
       }
       
  +    /** DEFAULT IMPLEMENTATIONS OF SAX EVENT HANDLERS
  +     * 
  +     * All of these throw errors at this level, so if you want to allow
  +     * things like children, you need to override these methods in your
  +     * deserializer.
  +     */
       public void startDocument() throws SAXException {
  -        if ((allowedEvents & STARTDOCUMENT) == 0)
  -            throw new SAXException(
  -                "StartDocument event not allowed in this context.");
  +        throw new SAXException(
  +            "StartDocument event not allowed in this context.");
       }
       
       public void endDocument() throws SAXException {
  -        if ((allowedEvents & ENDDOCUMENT) == 0)
  -            throw new SAXException(
  -                "EndDocument event not allowed in this context.");
  +        throw new SAXException(
  +            "EndDocument event not allowed in this context.");
       }
       
       public void startPrefixMapping(String p1, String p2) throws SAXException {
  -        if ((allowedEvents & STARTPREFIXMAP) == 0)
  -            throw new SAXException(
  -                "StartPrefixMapping event not allowed in this context.");
  +        throw new SAXException(
  +            "StartPrefixMapping event not allowed in this context.");
       }
       
       public void endPrefixMapping(String p1) throws SAXException {
  -        if ((allowedEvents & ENDPREFIXMAP) == 0)
  -            throw new SAXException(
  -                "EndPrefixMapping event not allowed in this context.");
  +        throw new SAXException(
  +            "EndPrefixMapping event not allowed in this context.");
       }
       
       public void characters(char[] p1, int p2, int p3) throws SAXException {
  -        if ((allowedEvents & CHARACTERS) == 0)
  -            throw new SAXException(
  -                "Characters event not allowed in this context.");
  +        throw new SAXException(
  +            "Characters event not allowed in this context.");
       }
       
       public void ignorableWhitespace(char[] p1, int p2, int p3) 
           throws SAXException
       {
  -        if ((allowedEvents & WHITESPACE) == 0)
  -            throw new SAXException(
  -                "IgnorableWhitespace event not allowed in this context.");
  +        throw new SAXException(
  +            "IgnorableWhitespace event not allowed in this context.");
       }
  - 
  +    
       public void skippedEntity(String p1) throws SAXException {
  -        if ((allowedEvents & SKIPPEDENTITY) == 0)
  -            throw new SAXException(
  -                "SkippedEntity event not allowed in this context.");
  +        throw new SAXException(
  +            "SkippedEntity event not allowed in this context.");
       }
       
       public void startElement(String namespace, String localName,
                                String qName, Attributes attributes)
           throws SAXException
  +    {
  +        throw new SAXException(
  +            "StartElement event not allowed in this context.");
  +    }
  +
  +    public void endElement(String namespace, String localName,
  +                             String qName)
  +        throws SAXException
       {
  -        if ((allowedEvents & STARTELEMENT) == 0)
  -            throw new SAXException(
  -                "StartElement event not allowed in this context.");
  +        if (parent != null) {
  +            parent.onEndChild(localName, this);
  +        }
       }
   }
  
  
  
  1.2       +45 -103   xml-axis/java/src/org/apache/axis/encoding/SOAPEncoding.java
  
  Index: SOAPEncoding.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SOAPEncoding.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SOAPEncoding.java	2001/04/29 17:25:00	1.1
  +++ SOAPEncoding.java	2001/05/03 14:31:46	1.2
  @@ -1,15 +1,14 @@
   package org.apache.axis.encoding;
   
  -import org.w3c.dom.Element;
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Attr;
  +import org.xml.sax.*;
  +import org.xml.sax.helpers.AttributesImpl;
   import org.apache.axis.utils.QName;
   import org.apache.axis.utils.XMLUtils;
   import org.apache.axis.Constants;
   import java.util.Hashtable;
  +import java.io.IOException;
   
  -public class SOAPEncoding implements Serializer, Deserializer { 
  -
  +public class SOAPEncoding implements Serializer { 
       private Hashtable typemap = new Hashtable();
       private Hashtable namemap = new Hashtable();
       
  @@ -30,115 +29,58 @@
           namemap.put(Short.class,   SOAPTypeMappingRegistry.SOAP_SHORT);
       }
       
  -    public Element serialize(QName qname, Object value, TypeMappingRegistry tmr, Document
doc) {
  -        Element e;
  -        String name = null;
  -        String ns = null;
  +    public void serialize(QName qname, Attributes attributes,
  +                          Object value, SerializationContext context)
  +        throws IOException
  +    {
           QName xsitype = null;
           Class type = null;
           
  -        if (value != null) type = value.getClass();
  -        if (qname != null) {
  -            name = qname.getLocalPart();
  -            ns = qname.getNamespaceURI();
  -            xsitype = (QName)typemap.get(type);
  +        if (value != null) {
  +            type = value.getClass();
           } else {
  -            if (type != null) {
  -                QName q = (QName)namemap.get(type);
  -                if (q != null) {
  -                    name = q.getLocalPart();
  -                    ns = q.getNamespaceURI();
  -                }
  -            }
  +            // !!! add xsi:null attribute
           }
           
  -        if (name != null) {
  -            if (ns != null) {
  -                e = doc.createElementNS(ns, name);
  -            } else {
  -                e = doc.createElement(name);
  +        if (type != null) {
  +            if (qname == null) {
  +                qname = (QName)namemap.get(type);
               }
  -            if (xsitype != null) {
  -                e.setAttributeNS(Constants.URI_SCHEMA_XSI, "type", Constants.NSPREFIX_SCHEMA_XSD
+ ":" + xsitype.getLocalPart());
  -            }
  -            if (value != null) {
  -                e.appendChild(doc.createTextNode(value.toString()));
  -            }
  -            return e;
  -        } 
  -        return null;
  -    }
  -
  -    public Object deserialize(Element element, TypeMappingRegistry tmr) {
  -        String xsdprefix = XMLUtils.getPrefix(Constants.URI_SCHEMA_XSD, element);
  -        String xsitype = element.getAttributeNS(Constants.URI_SCHEMA_XSI, "type");
  -        QName name = new QName(element.getNamespaceURI(), element.getLocalName());
  -        String value = element.getFirstChild().getNodeValue();
  +            xsitype = (QName)typemap.get(type);
  +        }
  +        
  +        Attributes attrs = attributes;
  +        String str = context.qName2String(xsitype);
           
           if (xsitype != null) {
  -            if (xsitype.startsWith(xsdprefix + ":")) {
  -                String stype = xsitype.substring(xsdprefix.length() + 1);
  -                QName type = new QName(Constants.URI_SCHEMA_XSD, stype);
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_STRING.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_STRING.getLocalPart()))
{
  -                    return new String(value);
  -                }
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_BOOLEAN.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_BOOLEAN.getLocalPart()))
{
  -                    return new Boolean(value);
  -                }
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_DOUBLE.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_DOUBLE.getLocalPart()))
{
  -                    return new Double(value);
  -                }
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_FLOAT.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_FLOAT.getLocalPart()))
{
  -                    return new Float(value);
  +            // !!! should check if we're writing types or not?
  +            AttributesImpl impl = new AttributesImpl();
  +            boolean gotType = false;
  +            
  +            if (attributes != null) {
  +                for (int i = 0; i < attributes.getLength(); i++) {
  +                    impl.addAttribute(attributes.getURI(i),
  +                                      attributes.getLocalName(i),
  +                                      attributes.getQName(i), "CDATA",
  +                                      attributes.getValue(i));
  +                    if (attributes.getURI(i).equals(Constants.URI_SCHEMA_XSI) &&
  +                        attributes.getLocalName(i).equals("type"))
  +                        gotType = true;
                   }
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_INT.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_INT.getLocalPart()))
{
  -                    return new Integer(value);
  -                }
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_LONG.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_LONG.getLocalPart()))
{
  -                    return new Long(value);
  -                }
  -                if (type.getNamespaceURI().equals(SOAPTypeMappingRegistry.XSD_SHORT.getNamespaceURI())
&&
  -                    type.getLocalPart().equals(SOAPTypeMappingRegistry.XSD_SHORT.getLocalPart()))
{
  -                    return new Short(value);
  -                }
               }
  -        }
  -        
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_STRING.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_STRING.getLocalPart()))
{
  -            return new String(value);
  -        }
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_BOOLEAN.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_BOOLEAN.getLocalPart()))
{
  -            return new Boolean(value);
  -        }
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_DOUBLE.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_DOUBLE.getLocalPart()))
{
  -            return new Double(value);
  -        }
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_FLOAT.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_FLOAT.getLocalPart()))
{
  -            return new Float(value);
  -        }
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_INT.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_INT.getLocalPart()))
{
  -            return new Integer(value);
  -        }
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_LONG.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_LONG.getLocalPart()))
{
  -            return new Long(value);
  -        }
  -        if (name.getNamespaceURI().equals(SOAPTypeMappingRegistry.SOAP_SHORT.getNamespaceURI())
&&
  -            name.getLocalPart().equals(SOAPTypeMappingRegistry.SOAP_SHORT.getLocalPart()))
{
  -            return new Short(value);
  +            
  +            if (!gotType) {
  +                impl.addAttribute(Constants.URI_SCHEMA_XSI,
  +                               "type", "xsi:type",
  +                               "CDATA", str);
  +            }
  +            
  +            attrs = impl;
           }
  -        
  -        return null;
  +
  +        context.startElement(qname, attrs);
  +        if (value != null)
  +            context.writeString(value.toString());
  +        context.endElement();
       }
   }
  
  
  
  1.2       +80 -21    xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java
  
  Index: SOAPTypeMappingRegistry.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SOAPTypeMappingRegistry.java	2001/04/29 17:25:00	1.1
  +++ SOAPTypeMappingRegistry.java	2001/05/03 14:31:48	1.2
  @@ -2,6 +2,7 @@
   
   import org.apache.axis.Constants;
   import org.apache.axis.utils.QName;
  +import org.xml.sax.*;
   
   public class SOAPTypeMappingRegistry extends TypeMappingRegistry { 
       
  @@ -20,29 +21,87 @@
       public static final QName SOAP_LONG = new QName(Constants.URI_SOAP_ENC, "long");
       public static final QName SOAP_SHORT = new QName(Constants.URI_SOAP_ENC, "short");
       
  +    abstract class BasicDeser extends DeserializerBase {
  +        public void startElement(String namespace, String name, String qName,
  +                                 Attributes attributes)
  +        {
  +        }
  +        
  +        public void characters(char [] chars, int start, int end)
  +        {
  +            value = makeValue(new String(chars, start, end));
  +        }
  +        abstract Object makeValue(String source);
  +    }
  +    class IntDeser extends BasicDeser {
  +        Object makeValue(String source) { return new Integer(source); }
  +    }
  +    class IntDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new IntDeser(); }
  +    }
  +    class FloatDeser extends BasicDeser {
  +        Object makeValue(String source) { return new Float(source); }
  +    }
  +    class FloatDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new FloatDeser(); }
  +    }
  +    class LongDeser extends BasicDeser {
  +        Object makeValue(String source) { return new Long(source); }
  +    }
  +    class LongDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new LongDeser(); }
  +    }
  +    class StringDeser extends BasicDeser {
  +        Object makeValue(String source) { return source; };
  +    }
  +    class StringDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new StringDeser(); }
  +    }
  +    class BooleanDeser extends BasicDeser {
  +        Object makeValue(String source) { return new Boolean(source); }
  +    }
  +    class BooleanDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new BooleanDeser(); }
  +    }
  +    class DoubleDeser extends BasicDeser {
  +        Object makeValue(String source) { return new Double(source); }
  +    }
  +    class DoubleDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new DoubleDeser(); }
  +    }
  +    class ShortDeser extends BasicDeser {
  +        Object makeValue(String source) { return new Short(source); }
  +    }
  +    class ShortDeserializerFactory implements DeserializerFactory {
  +        public DeserializerBase getDeserializer() { return new ShortDeser(); }
  +    }
  +
       public SOAPTypeMappingRegistry() {
           SOAPEncoding se = new SOAPEncoding();
  -        addSerializer(java.lang.String.class, se);
  -        addSerializer(java.lang.Boolean.class, se);
  -        addSerializer(java.lang.Double.class, se);
  -        addSerializer(java.lang.Float.class, se);
  -        addSerializer(java.lang.Integer.class, se);
  -        addSerializer(java.lang.Long.class, se);
  -        addSerializer(java.lang.Short.class, se);
  -        addDeserializer(XSD_STRING, se);    
  -        addDeserializer(XSD_BOOLEAN, se);
  -        addDeserializer(XSD_DOUBLE, se);
  -        addDeserializer(XSD_FLOAT, se);
  -        addDeserializer(XSD_INT, se);
  -        addDeserializer(XSD_LONG, se);
  -        addDeserializer(XSD_SHORT, se);
  -        addDeserializer(SOAP_STRING, se);
  -        addDeserializer(SOAP_BOOLEAN, se);
  -        addDeserializer(SOAP_DOUBLE, se);
  -        addDeserializer(SOAP_FLOAT, se);
  -        addDeserializer(SOAP_INT, se);
  -        addDeserializer(SOAP_LONG, se);
  -        addDeserializer(SOAP_SHORT, se);
  +        addSerializer(java.lang.String.class, XSD_STRING, se);
  +        addSerializer(java.lang.Boolean.class, XSD_BOOLEAN, se);
  +        addSerializer(java.lang.Double.class, XSD_DOUBLE, se);
  +        addSerializer(java.lang.Float.class, XSD_FLOAT, se);
  +        addSerializer(java.lang.Integer.class, XSD_INT, se);
  +        addSerializer(java.lang.Long.class, XSD_LONG, se);
  +        addSerializer(java.lang.Short.class, XSD_SHORT, se);
  +        
  +        addDeserializerFactory(XSD_STRING, new StringDeserializerFactory());    
  +        addDeserializerFactory(XSD_BOOLEAN, new BooleanDeserializerFactory());
  +        addDeserializerFactory(XSD_DOUBLE, new DoubleDeserializerFactory());
  +        addDeserializerFactory(XSD_FLOAT, new FloatDeserializerFactory());
  +        addDeserializerFactory(XSD_INT, new IntDeserializerFactory());
  +        addDeserializerFactory(XSD_LONG, new LongDeserializerFactory());
  +        addDeserializerFactory(XSD_SHORT, new ShortDeserializerFactory());
  +        /*
  +        addDeserializerFactory(SOAP_STRING, se);
  +        addDeserializerFactory(SOAP_BOOLEAN, se);
  +        addDeserializerFactory(SOAP_DOUBLE, se);
  +        addDeserializerFactory(SOAP_FLOAT, se);
  +        addDeserializerFactory(SOAP_INT, se);
  +        addDeserializerFactory(SOAP_LONG, se);
  +        addDeserializerFactory(SOAP_SHORT, se);
  +        */
       }
       
   }
  
  
  
  1.4       +18 -2     xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SerializationContext.java	2001/04/30 05:16:41	1.3
  +++ SerializationContext.java	2001/05/03 14:31:50	1.4
  @@ -83,13 +83,23 @@
       
       int lastPrefixIndex = 1;
       
  -    TypeMapper typeMapper = new TypeMapper();
  +    TypeMappingRegistry mappingRegistry = new SOAPTypeMappingRegistry();
       
       public SerializationContext(Writer writer)
       {
           this.writer = writer;
       }
       
  +    public void setTypeMappingRegistry(TypeMappingRegistry reg)
  +    {
  +        mappingRegistry = reg;
  +    }
  +    
  +    public TypeMappingRegistry getTypeMappingRegistry()
  +    {
  +        return mappingRegistry;
  +    }
  +    
       public String getPrefixForURI(String uri)
       {
           String prefix = nsStack.getPrefix(uri);
  @@ -129,8 +139,14 @@
       }
       
       public QName getQNameForClass(Class cls)
  +    {
  +        return mappingRegistry.getTypeQName(cls);
  +    }
  +    
  +    public void serialize(QName qName, Attributes attributes, Object value)
  +        throws IOException
       {
  -        return typeMapper.getTypeQName(cls);
  +        mappingRegistry.serialize(qName, attributes, value, this);
       }
       
       public void startElement(QName qName, Attributes attributes)
  
  
  
  1.4       +5 -5      xml-axis/java/src/org/apache/axis/encoding/Serializer.java
  
  Index: Serializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/Serializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Serializer.java	2001/04/29 17:35:00	1.3
  +++ Serializer.java	2001/05/03 14:31:52	1.4
  @@ -58,15 +58,15 @@
   //import org.apache.axis.message.Message;
   //import org.apache.axis.message.MessageElement;
   //import org.apache.axis.utils.NSStack;
  +import java.io.IOException;
   import org.apache.axis.utils.QName;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.Document;
  +import org.xml.sax.Attributes;
   
   /**
    * @author James Snell (jasnell@us.ibm.com)
    */
   public interface Serializer { 
  -    
  -    //public MessageElement serialize(QName name, Object value, NSStack nsStack, TypeMappingRegistry
tmr, Message message);
  -    public Element serialize(QName name, Object value, TypeMappingRegistry tmr, Document
doc);
  +    public void serialize(QName name, Attributes attributes,
  +                          Object value, SerializationContext context)
  +        throws IOException;
   }
  
  
  
  1.4       +60 -20    xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java
  
  Index: TypeMappingRegistry.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TypeMappingRegistry.java	2001/04/29 17:25:00	1.3
  +++ TypeMappingRegistry.java	2001/05/03 14:31:57	1.4
  @@ -61,36 +61,78 @@
   import org.apache.axis.message.*;
   import org.w3c.dom.Element;
   import org.w3c.dom.Document;
  +import org.xml.sax.*;
   import java.io.*;
   
   /**
    * @author James Snell (jasnell@us.ibm.com)
    */
  -public class TypeMappingRegistry implements Serializer, Deserializer { 
  +public class TypeMappingRegistry implements Serializer { 
   
  +    class SerializerDescriptor implements Serializable {
  +        QName typeQName;
  +        Serializer serializer;
  +        SerializerDescriptor(QName typeQName, Serializer serializer)
  +        {
  +            this.typeQName = typeQName;
  +            this.serializer = serializer;
  +        }
  +    }
  +    
       Hashtable s;
       Hashtable d;
  +    DeserializationContext context = null;
  +    
  +    public void setDeserializationContext(DeserializationContext context)
  +    {
  +        this.context = context;
  +    }
  +    
  +    private String generateKey(QName qName)
  +    {
  +        return qName.getNamespaceURI() + " + " + qName.getLocalPart();
  +    }
       
  -    public void addSerializer(Class _class, Serializer serializer) {
  +    public void addSerializer(Class _class, QName qName, Serializer serializer) {
           if (s == null) s = new Hashtable();
  -        s.put(_class, serializer);
  +        s.put(_class, new SerializerDescriptor(qName, serializer));
       }
       
  -    public void addDeserializer(QName qname, Deserializer deserializer) {
  +    public void addDeserializerFactory(QName qname,
  +                                       DeserializerFactory deserializerFactory) {
           if (d == null) d= new Hashtable();
  -        d.put(qname, deserializer);
  +        d.put(generateKey(qname), deserializerFactory);
       }
   
       public Serializer getSerializer(Class _class) {
  -        if (s != null) return (Serializer)s.get(_class);
  +        if (s == null)
  +            return null;
  +        SerializerDescriptor desc = (SerializerDescriptor)s.get(_class);
  +        if (desc != null) return desc.serializer;
           return null;
       }
       
  -    public Deserializer getDeserializer(QName qname) {
  -        if (d != null) return (Deserializer)d.get(qname);
  +    public QName getTypeQName(Class _class) {
  +        if (s == null)
  +            return null;
  +        SerializerDescriptor desc = (SerializerDescriptor)s.get(_class);
  +        if (desc != null) return desc.typeQName;
           return null;
       }
       
  +    public DeserializerBase getDeserializer(QName qname) {
  +        if (d == null)
  +            return null;
  +        
  +        DeserializerFactory factory = (DeserializerFactory)d.get(generateKey(qname));
  +        if (factory == null)
  +            return null;
  +        
  +        DeserializerBase dSer = factory.getDeserializer();
  +        dSer.setDeserializationContext(context);
  +        return dSer;
  +    }
  +    
       public void removeSerializer(Class _class) {
           if (s != null) s.remove(_class);
       }
  @@ -136,24 +178,22 @@
           load(fis);
       }
   
  -    public Element serialize(QName name, Object value, TypeMappingRegistry tmr, Document
doc) {
  +    public void serialize(QName name, Attributes attributes,
  +                          Object value, SerializationContext context)
  +        throws IOException
  +    {
           if (value != null) {
               Class _class = value.getClass();
               Serializer ser = getSerializer(_class);
  -            if (tmr == null) tmr = this;
  -            return ser.serialize(name, value, tmr, doc);
  +            if (ser != null) {
  +                ser.serialize(name, attributes, value, context);
  +            } else {
  +                throw new IOException("No serializer found for class " + _class.getName());
  +            }
           }
  -        return null;
  +        // !!! Write out a generic null, or get type info from somewhere else?
       }
   
  -    public Object deserialize(Element element, TypeMappingRegistry tmr) {
  -        QName q = new QName(element.getNamespaceURI(), element.getLocalName());
  -        Deserializer des = getDeserializer(q);
  -        if (tmr == null) tmr = this;
  -        return des.deserialize(element, tmr);
  -    }
  -    
  -    
       //public MessageElement serialize(QName name, Object value, NSStack nsStack, Message
message) {
       //    if (value != null) {
       //        Class _class = value.getClass();
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/encoding/DeserializerFactory.java
  
  Index: DeserializerFactory.java
  ===================================================================
  package org.apache.axis.encoding;
  
  public interface DeserializerFactory
  {
      public DeserializerBase getDeserializer();
  }
  
  
  
  1.3       +6 -3      xml-axis/java/src/org/apache/axis/message/ElementRecorder.java
  
  Index: ElementRecorder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/ElementRecorder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElementRecorder.java	2001/04/28 13:52:15	1.2
  +++ ElementRecorder.java	2001/05/03 14:32:15	1.3
  @@ -84,7 +84,7 @@
           throws SAXException
       {
           if (DEBUG_LOG) {
  -            System.out.println("(rec) startElement ['" + namespace + "' " +
  +            System.err.println("(rec) startElement ['" + namespace + "' " +
                              localName + "]");
           }
           
  @@ -95,7 +95,7 @@
           throws SAXException
       {
           if (DEBUG_LOG) {
  -            System.out.println("(rec) endElement ['" + namespace + "' " +
  +            System.err.println("(rec) endElement ['" + namespace + "' " +
                              localName + "]");
           }
   
  @@ -106,7 +106,7 @@
           throws SAXException
       {
           if (DEBUG_LOG) {
  -            System.out.println("(rec) characters ['" +
  +            System.err.println("(rec) characters ['" +
                                  new String(chars, start, length) + "']");
           }
           
  @@ -123,6 +123,9 @@
           Enumeration e = _events.elements();
           while (e.hasMoreElements()) {
               SAXEvent event = (SAXEvent)e.nextElement();
  +            if (DEBUG_LOG) {
  +                System.err.println("Publishing : " + event);
  +            }
               event.publishToHandler(handler);
           }
       }
  
  
  
  1.11      +3 -0      xml-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MessageElement.java	2001/05/02 02:49:17	1.10
  +++ MessageElement.java	2001/05/03 14:32:17	1.11
  @@ -75,6 +75,7 @@
       protected String    namespaceURI ;
       protected AttributesImpl attributes;
       protected String    id;
  +    protected String    href;
       protected boolean   isRoot = false;
       protected SOAPEnvelope message = null;
       protected DeserializationContext context = null;
  @@ -123,6 +124,8 @@
           if (id != null) {
               context.registerID(id, this);
           }
  +            
  +        href = attributes.getValue(Constants.ATTR_HREF);
         }
       }
       
  
  
  
  1.3       +6 -1      xml-axis/java/src/org/apache/axis/message/RPCElement.java
  
  Index: RPCElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCElement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RPCElement.java	2001/05/02 12:16:07	1.2
  +++ RPCElement.java	2001/05/03 14:32:19	1.3
  @@ -90,6 +90,7 @@
           
           public void startElement(String namespace, String name, String qName,
                                    Attributes attributes)
  +            throws SAXException
           {
               if (!passedMyStart) {
                   passedMyStart = true;
  @@ -98,6 +99,7 @@
               
               // Start of an arg...
               RPCParam param = new RPCParam(namespace, name, attributes, context);
  +            
               params.addElement(param);
               if (param.getType() == null) {
                   // No type inline, so check service description.
  @@ -114,7 +116,10 @@
                    */
                   
               }
  -            context.pushElementHandler(param.getContentHandler());
  +            ContentHandler handler = param.getContentHandler();
  +            
  +            handler.startElement(namespace, name, qName, attributes);
  +            context.pushElementHandler(handler);
           }
       }
       public ContentHandler getContentHandler() { return new RPCContentHandler(); }
  
  
  
  1.6       +31 -19    xml-axis/java/src/org/apache/axis/message/RPCParam.java
  
  Index: RPCParam.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCParam.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RPCParam.java	2001/04/30 05:24:16	1.5
  +++ RPCParam.java	2001/05/03 14:32:20	1.6
  @@ -120,6 +120,13 @@
           this.value = value;
       }
       
  +    public RPCParam(String namespace, String name, Object value)
  +    {
  +        this.namespaceURI = namespace;
  +        this.name = name;
  +        this.value = value;
  +    }
  +    
       public void setRPCElement(RPCElement element)
       {
           myRPCElement = element;
  @@ -142,8 +149,9 @@
           // Look up type and return an appropriate deserializer
           if (typeQName != null) {
               deserializer = context.getDeserializer(typeQName);
  -            if (deserializer != null)
  +            if (deserializer != null) {
                   return deserializer;
  +            }
           }
           
           // If we couldn't find one, just record...
  @@ -153,7 +161,9 @@
            * means)?  In that case we want an easy way to
            * squirt these SAX events to a deserializer.
            */
  -        
  +        if (DEBUG_LOG) {
  +            System.err.println("Creating recorder for " + this.getName());
  +        }
           value = new ElementRecorder();
           return (ElementRecorder)value;
       }
  @@ -183,26 +193,34 @@
       
       public void output(SerializationContext context) throws IOException
       {
  -        AttributesImpl attrs = new AttributesImpl();
  +        AttributesImpl attrs;
           if (deserializer != null) getValue();
           
  -        if ((value != null) && (typeQName == null))
  -            typeQName = context.getQNameForClass(value.getClass());
  +        if (value instanceof ElementRecorder) {
  +            try {
  +                ((ElementRecorder)value).publishToHandler(new SAXOutputter(context));
  +            } catch (SAXException ex) {
  +                throw new IOException(ex.getMessage());
  +            }
  +            return;
  +        } else {
  +            if ((value != null) && (typeQName == null)) {
  +                typeQName = context.getQNameForClass(value.getClass());
  +            }
  +        }
           
           if (attributes != null) {
               // Must be writing a message we parsed earlier, so just put out
               // what's already there.
  -            for (int i = 0; i < attributes.getLength(); i++) {
  -                attrs.addAttribute(attributes.getURI(i), attributes.getLocalName(i),
  -                                   attributes.getQName(i), "CDATA",
  -                                   attributes.getValue(i));
  -            }
  +            attrs = new AttributesImpl(attributes);
           } else {
               // Writing a message from memory out to XML...
               // !!! How do we set other attributes when serializing??
  +            attrs = new AttributesImpl();
               
               ServiceDescription desc = getEnvelope().getServiceDescription();
               if ((desc == null) || desc.getSendTypeAttr()) {
  +                
                   if (typeQName != null) {
                       attrs.addAttribute(Constants.URI_SCHEMA_XSI, "type", "xsi:type",
                                          "CDATA",
  @@ -214,16 +232,10 @@
                   attrs.addAttribute(Constants.URI_SCHEMA_XSI, "null", "xsi:null",
                                      "CDATA", "1");
           }
  -        
  -        context.startElement(new QName(getNamespaceURI(), getName()), attrs);
   
  -        // Output the value...
  -        if (value != null)
  -            if (value instanceof ElementRecorder)
  -                ((ElementRecorder)value).output(context);
  -            else
  -                context.writeString(value.toString());
  +        if (typeQName == null)
  +            typeQName = context.getQNameForClass(value.getClass());
           
  -        context.endElement();
  +        context.serialize(new QName(getNamespaceURI(), getName()), attrs, value);
       }
   }
  
  
  
  1.16      +7 -0      xml-axis/java/src/org/apache/axis/message/SOAPHeader.java
  
  Index: SOAPHeader.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPHeader.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SOAPHeader.java	2001/04/26 22:53:40	1.15
  +++ SOAPHeader.java	2001/05/03 14:32:22	1.16
  @@ -55,9 +55,11 @@
   
   package org.apache.axis.message ;
   
  +import java.io.IOException;
   import java.util.* ;
   import org.apache.axis.* ;
   import org.apache.axis.encoding.DeserializationContext;
  +import org.apache.axis.encoding.SerializationContext;
   import org.xml.sax.Attributes;
   
   /** A simple header abstraction.  Extends MessageElement with header-specific
  @@ -117,5 +119,10 @@
   
       public boolean isProcessed() {
           return( processed );
  +    }
  +
  +    public void output(SerializationContext context) throws IOException
  +    {
  +        super.output(context);
       }
   };
  
  
  
  1.5       +5 -0      xml-axis/java/src/org/apache/axis/message/SOAPSAXHandler.java
  
  Index: SOAPSAXHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPSAXHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SOAPSAXHandler.java	2001/05/01 22:04:39	1.4
  +++ SOAPSAXHandler.java	2001/05/03 14:32:23	1.5
  @@ -176,6 +176,11 @@
           return envelope;
       }
       
  +    public DeserializationContext getContext()
  +    {
  +        return context;
  +    }
  +    
       /** Grab a namespace prefix
        */
       public String getNamespaceURI(String prefix)
  
  
  
  1.3       +5 -0      xml-axis/java/src/org/apache/axis/message/events/CharactersEvent.java
  
  Index: CharactersEvent.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/events/CharactersEvent.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CharactersEvent.java	2001/04/28 13:52:16	1.2
  +++ CharactersEvent.java	2001/05/03 14:32:38	1.3
  @@ -91,4 +91,9 @@
       {
           context.writeChars(_characters, _start, _length);
       }
  +    
  +    public String toString()
  +    {
  +        return "[CharactersEvent '" + new String(_characters, _start, _length) + "']";
  +    }
   }
  
  
  
  1.3       +5 -0      xml-axis/java/src/org/apache/axis/message/events/EndElementEvent.java
  
  Index: EndElementEvent.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/events/EndElementEvent.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EndElementEvent.java	2001/04/28 13:52:16	1.2
  +++ EndElementEvent.java	2001/05/03 14:32:40	1.3
  @@ -97,4 +97,9 @@
           context.writeString(_localPart);
           context.writeString(">");
       }
  +    
  +    public String toString()
  +    {
  +        return "[EndElementEvent " + _qName + " ]";
  +    }
   }
  
  
  
  1.3       +5 -0      xml-axis/java/src/org/apache/axis/message/events/StartElementEvent.java
  
  Index: StartElementEvent.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/events/StartElementEvent.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StartElementEvent.java	2001/04/28 13:52:16	1.2
  +++ StartElementEvent.java	2001/05/03 14:32:41	1.3
  @@ -109,4 +109,9 @@
           }
           context.writeString(">");
       }
  +    
  +    public String toString()
  +    {
  +        return "[StartElementEvent " + _qName + " ]";
  +    }
   }
  
  
  

Mime
View raw message