You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gl...@apache.org on 2002/03/13 16:20:03 UTC

cvs commit: xml-axis/java/src/org/apache/axis/message MessageElement.java SOAPHeader.java

glyn        02/03/13 07:20:03

  Modified:    java     TODO.txt
               java/docs messagemodelclasses.jpg
               java/src/org/apache/axis Constants.java
               java/src/org/apache/axis/client Call.java
               java/src/org/apache/axis/message MessageElement.java
                        SOAPHeader.java
  Log:
  Make MessageElement implement JAXM SOAPElement.
  
  Remove getValue method from SOAPHeader and re-introduce as getObjectValue
  (to avoid clash with SOAPElement.getValue) in MessageElement. This was
  derived from code submitted by Taras Shkvarchuk and addresses one of the
  beta 'must do' items.
  
  Revision  Changes    Path
  1.20      +0 -1      xml-axis/java/TODO.txt
  
  Index: TODO.txt
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/TODO.txt,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TODO.txt	12 Mar 2002 21:29:15 -0000	1.19
  +++ TODO.txt	13 Mar 2002 15:20:01 -0000	1.20
  @@ -13,7 +13,6 @@
   ! <Doug> Doug's issue 1: Attachments are broken
   ! <Russell> Published interfaces must be vetted.
   ! <?> getParameterName() should return a QName
  -! <?> Taras' fix to MessageElement (getValue-like method).
   
   
   MESSAGE PARSING / ENCODING
  
  
  
  1.2       +86 -49    xml-axis/java/docs/messagemodelclasses.jpg
  
  	<<Binary file>>
  
  
  1.56      +1 -0      xml-axis/java/src/org/apache/axis/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Constants.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Constants.java	5 Mar 2002 14:19:57 -0000	1.55
  +++ Constants.java	13 Mar 2002 15:20:01 -0000	1.56
  @@ -380,6 +380,7 @@
       public static final String ATTR_ARRAY_TYPE      = "arrayType";
       public static final String ATTR_OFFSET          = "offset";
       public static final String ATTR_POSITION        = "position";
  +    public static final String ATTR_TYPE            = "type";
       
       // Well-known actor values
       public static final String ACTOR_NEXT = 
  
  
  
  1.92      +9 -4      xml-axis/java/src/org/apache/axis/client/Call.java
  
  Index: Call.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Call.java,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- Call.java	13 Mar 2002 06:02:46 -0000	1.91
  +++ Call.java	13 Mar 2002 15:20:02 -0000	1.92
  @@ -103,6 +103,7 @@
   import javax.xml.rpc.namespace.QName;
   import javax.xml.rpc.JAXRPCException;
   import javax.xml.rpc.ParameterMode;
  +import javax.xml.soap.SOAPException;
   
   import java.beans.IntrospectionException;
   import java.io.PrintWriter;
  @@ -1541,8 +1542,13 @@
           }
   
           // Set both the envelope and the RPCElement encoding styles
  -        body.setEncodingStyle(encodingStyle);
  -        reqEnv.setEncodingStyle(encodingStyle);
  +        try {
  +            body.setEncodingStyle(encodingStyle);
  +            reqEnv.setEncodingStyle(encodingStyle);
  +        } catch (SOAPException e) {
  +            log.debug( JavaUtils.getMessage("exception00"), e );
  +            throw AxisFault.makeFault(e);
  +        }
   
           setRequestMessage(reqMsg);
   
  @@ -1552,8 +1558,7 @@
   
           try {
               invoke();
  -        }
  -        catch( Exception e ) {
  +        } catch (Exception e) {
               log.debug( JavaUtils.getMessage("exception00"), e );
               throw AxisFault.makeFault(e);
           }
  
  
  
  1.83      +297 -3    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.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- MessageElement.java	27 Feb 2002 13:41:28 -0000	1.82
  +++ MessageElement.java	13 Mar 2002 15:20:03 -0000	1.83
  @@ -61,6 +61,7 @@
   import org.apache.axis.encoding.Deserializer;
   import org.apache.axis.encoding.SerializationContext;
   import org.apache.axis.encoding.SerializationContextImpl;
  +import org.apache.axis.encoding.Serializer;
   import org.apache.axis.utils.Mapping;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.XMLUtils;
  @@ -76,14 +77,18 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
   
  +import javax.xml.soap.SOAPElement;
  +import javax.xml.soap.SOAPException;
  +import javax.xml.soap.Name;
   import javax.xml.rpc.namespace.QName;
   import java.io.Reader;
   import java.io.StringReader;
   import java.io.StringWriter;
   import java.util.ArrayList;
   import java.util.Vector;
  +import java.util.Iterator;
   
  -public class MessageElement
  +public class MessageElement implements SOAPElement
   {
       protected static Log log =
           LogFactory.getLog(MessageElement.class.getName());
  @@ -125,6 +130,9 @@
       /** Our encoding style, if any */
       protected String encodingStyle = null;
   
  +    /** Object value, possibly supplied by subclass */
  +    private Object objectValue = null;
  +
       /** No-arg constructor for building messages?
        */
       public MessageElement()
  @@ -234,7 +242,26 @@
       public String getNamespaceURI() { return( namespaceURI ); }
       public void setNamespaceURI(String nsURI) { namespaceURI = nsURI; }
   
  -    public QName getType() { return typeQName; }
  +    public QName getType() {
  +        if (typeQName == null) {
  +            String typeStr = attributes.
  +                getValue(Constants.URI_CURRENT_SCHEMA_XSI,
  +                         Constants.ATTR_TYPE);
  +            if (typeStr != null) {
  +                int colPos = typeStr.indexOf(':');
  +                if (colPos != -1) {
  +                    typeQName = new QName(typeStr.substring(0, colPos),
  +                                          typeStr.substring(colPos + 1));
  +                } else {
  +                    typeQName = new QName("", typeStr);
  +                }
  +            } else {
  +                typeQName = new QName(getNamespaceURI(), getName());
  +            }
  +          }
  +
  +        return typeQName;
  +    }
       public void setType(QName qName) { typeQName = qName; }
   
       public SAX2EventRecorder getRecorder() { return recorder; }
  @@ -261,7 +288,7 @@
        * as above in getEncodingStyle() are to just use the parent's value,
        * but null here means set to "". 
        */
  -    public void setEncodingStyle(String encodingStyle) {
  +    public void setEncodingStyle(String encodingStyle) throws SOAPException {
           if (encodingStyle == null) encodingStyle = "";
           this.encodingStyle = encodingStyle;
   
  @@ -354,6 +381,31 @@
           return null;
       }
   
  +    /**
  +     * Returns value of the node as an object of registered type.
  +     * @return Object of proper type, or null if no mapping could be found.
  +     */
  +    public Object getObjectValue(){
  +        if (objectValue == null) {
  +            try {
  +                objectValue = getValueAsType(getType());
  +            } catch (Exception e) {
  +                log.debug("getValue()", e);
  +            }
  +        }
  +        return objectValue;
  +    }
  +
  +    /**
  +     * Sets value of this node to an Object.
  +     * A serializer needs to be registered for this object class for proper
  +     * operation.
  +     * @param newValue node's value or null.
  +     */
  +    protected void setObjectValue(Object newValue){
  +        this.objectValue = newValue;
  +    }
  +    
       public Object getValueAsType(QName type) throws Exception
       {
           if (context == null)
  @@ -588,4 +640,246 @@
           if (namespaces == null) namespaces = new ArrayList();
           namespaces.add(map);
       }
  +
  +    // JAXM Node methods...
  +
  +    /**
  +     * Text nodes are not supported.
  +     */
  +    public String getValue() {
  +        return null;
  +    }
  +
  +    public void setParentElement(SOAPElement parent) throws SOAPException {
  +        try {
  +            setParent((MessageElement)parent);
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +    }
  +
  +    public SOAPElement getParentElement() {
  +        return getParent();
  +    }
  +
  +    /**
  +     * No-opped.
  +     */
  +    public void detachNode() {}
  +    
  +    /**
  +     * No-opped.
  +     */
  +    public void recycleNode() {}
  +
  +    // JAXM SOAPElement methods...
  +
  +    public SOAPElement addChildElement(Name name) throws SOAPException {
  +        try {
  +            MessageElement child = new MessageElement(name.getURI(),
  +                                                      name.getLocalName());
  +            addChild(child);
  +            return child;
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +    }
  +
  +    public SOAPElement addChildElement(String localName) throws SOAPException {
  +        try {
  +            // Inherit parent's namespace
  +            MessageElement child = new MessageElement(getNamespaceURI(),
  +                                                      localName);
  +            addChild(child);
  +            return child;
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +    }
  +
  +    public SOAPElement addChildElement(String localName,
  +                                       String prefix) throws SOAPException {
  +        try {
  +            MessageElement child = new MessageElement(getNamespaceURI(prefix),
  +                                                      localName);
  +            addChild(child);
  +            return child;
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +    }
  +
  +    public SOAPElement addChildElement(String localName,
  +                                       String prefix,
  +                                       String uri) throws SOAPException {
  +        try {
  +            MessageElement child = new MessageElement(uri, localName);
  +            child.addNamespaceDeclaration(prefix, uri);
  +            addChild(child);
  +            return child;
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +    }
  +
  +    /**
  +     * The added child must be an instance of MessageElement rather than
  +     * an abitrary SOAPElement otherwise a (wrapped) class cast exception
  +     * will be thrown.
  +     */
  +    public SOAPElement addChildElement(SOAPElement element)
  +        throws SOAPException {
  +        try {
  +            addChild((MessageElement)element);
  +            return element;
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +    }
  +
  +    /**
  +     * Text nodes are not supported.
  +     */
  +    public SOAPElement addTextNode(String text) throws SOAPException {
  +        throw new SOAPException("Text nodes not supported"); 
  +    }
  +
  +    public SOAPElement addAttribute(Name name, String value)
  +        throws SOAPException {
  +        try {
  +            addAttribute(name.getURI(), name.getLocalName(), value);
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +        return this;
  +    }
  +
  +    public SOAPElement addNamespaceDeclaration(String prefix,
  +                                               String uri)
  +        throws SOAPException {
  +        try {
  +            Mapping map = new Mapping(uri, prefix);
  +            addMapping(map);
  +        } catch (Throwable t) {
  +            throw new SOAPException(t);
  +        }
  +        return this;
  +    }
  +
  +    public String getAttributeValue(Name name) {
  +        return attributes.getValue(name.getURI(), name.getLocalName());
  +    }
  +
  +    public Iterator getAllAttributes() {
  +        int num = attributes.getLength();
  +        Vector attrs = new Vector(num);
  +        for (int i = 0; i < num; i++) {
  +            String q = attributes.getQName(i);
  +            String prefix = "";
  +            if (q != null) {
  +                int idx = q.indexOf(":");
  +                if (idx > 0)
  +                    prefix = q.substring(0, idx);
  +            }
  +
  +            attrs.add(new NameImpl(attributes.getURI(i),
  +                                   attributes.getLocalName(i),
  +                                   prefix));
  +        }
  +        return attrs.iterator();
  +    }
  +
  +    protected static class NameImpl implements Name {
  +        private QName qName;
  +        private String prefix;
  +
  +        public NameImpl(String uri, String localName, String pre) {
  +            qName = new QName(uri, localName);
  +            prefix = pre;
  +        }
  +
  +        public String getLocalName() {
  +            return qName.getLocalPart();
  +        }
  +
  +        public String getQualifiedName() {
  +            return qName.toString();
  +        }
  +
  +        public String getURI() {
  +            return qName.getNamespaceURI();
  +        }
  +
  +        public String getPrefix() {
  +            return prefix;
  +        }
  +    }
  +
  +    // getNamespaceURI implemented above
  +
  +    public Iterator getNamespacePrefixes() {
  +        int num = namespaces.size();
  +        Vector prefixes = new Vector(num);
  +        for (int i = 0; i < num; i++) {
  +            prefixes.add(((Mapping)namespaces.get(i)).getPrefix());
  +        }
  +        return prefixes.iterator();
  +    }
  +
  +    public Name getElementName() {
  +        return new NameImpl(getNamespaceURI(), getName(), getPrefix());
  +    }
  +
  +    public boolean removeAttribute(Name name) {
  +        boolean removed = false;
  +
  +        for (int i = 0; i < attributes.getLength() && !removed; i++) {
  +            if (attributes.getURI(i).equals(name.getURI()) &&
  +                attributes.getLocalName(i).equals(name.getLocalName())) {
  +                attributes.removeAttribute(i);
  +                removed = true;
  +            }
  +        }
  +        return removed;
  +    }
  +
  +    public boolean removeNamespaceDeclaration(String prefix) {
  +        boolean removed = false;
  +
  +        for (int i = 0; i < namespaces.size() && !removed; i++) {
  +            if (((Mapping)namespaces.get(i)).getPrefix().equals(prefix)) {
  +                namespaces.remove(i);
  +                removed = true;
  +            }
  +        }
  +        return removed;
  +    }
  +
  +    public Iterator getChildElements() {
  +        if (children == null)
  +            children = new ArrayList();
  +        return children.iterator();
  +    }
  +
  +    public Iterator getChildElements(Name name) {
  +        if (children == null)
  +            children = new ArrayList();
  +        int num = children.size();
  +
  +        Vector c = new Vector(num);
  +        for (int i = 0; i < num; i++) {
  +            MessageElement child = (MessageElement)children.get(i);
  +            Name cname = child.getElementName();
  +            if (cname.getURI().equals(name.getURI()) &&
  +                cname.getLocalName().equals(name.getLocalName())) {
  +                c.add(child);
  +            }
  +        }
  +        return c.iterator();
  +    }
  +
  +    // setEncodingStyle implemented above
  +
  +    // getEncodingStyle() implemented above
  +
   }
  
  
  
  1.33      +7 -12     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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- SOAPHeader.java	26 Jan 2002 02:47:22 -0000	1.32
  +++ SOAPHeader.java	13 Mar 2002 15:20:03 -0000	1.33
  @@ -74,7 +74,6 @@
   
       protected String    actor;
       protected boolean   mustUnderstand = false;
  -    protected Object    value = null;
   
       public SOAPHeader() {
       }
  @@ -89,7 +88,7 @@
       {
           setNamespaceURI(namespace);
           setName(localPart);
  -        setValue(value);
  +        setObjectValue(value);
       }
   
       public SOAPHeader(Element elem)
  @@ -137,23 +136,19 @@
           processed = value ;
       }
   
  -    public Object getValue() {
  -        return value;
  -    }
  -
  -    public void setValue(Object value) {
  -        this.value = value;
  -    }
  -
       public boolean isProcessed() {
           return( processed );
       }
   
       protected void outputImpl(SerializationContext context) throws Exception {
  +        Object value = getObjectValue();
           if (value == null) {
               super.outputImpl(context);
           } else {
  -            context.serialize(new QName(namespaceURI,name), attributes, value, value.getClass() );
  +            context.serialize(new QName(namespaceURI,name),
  +                              attributes, 
  +                              value, 
  +                              value.getClass() );
           }
       }
  -};
  +}