axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/message MessageElement.java SOAPEnvelope.java
Date Thu, 11 Nov 2004 00:00:49 GMT
gawor       2004/11/10 16:00:49

  Modified:    java/src/org/apache/axis/message MessageElement.java
                        SOAPEnvelope.java
  Added:       java/src/org/apache/axis/encoding
                        TextSerializationContext.java
  Log:
  optimizations to MessageElement.getValue()
  
  Revision  Changes    Path
  1.1                  ws-axis/java/src/org/apache/axis/encoding/TextSerializationContext.java
  
  Index: TextSerializationContext.java
  ===================================================================
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * 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.axis.encoding;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import javax.xml.namespace.QName;
  
  import org.apache.axis.MessageContext;
  import org.apache.axis.utils.Messages;
  
  import org.w3c.dom.Element;
  
  import org.xml.sax.Attributes;
  
  /**
   * For internal use only. Used to get the first text node of an element.
   *
   * @author Jarek Gawor (gawor@apache.org)
   */
  public class TextSerializationContext extends SerializationContext {
  
      private boolean ignore = false;
      private int depth = 0;
  
      public TextSerializationContext(Writer writer)
      {
          super(writer);
      }
  
      public TextSerializationContext(Writer writer, MessageContext msgContext)
      {
          super(writer, msgContext);
      }
  
      public void serialize(QName elemQName,
                            Attributes attributes,
                            Object value,
                            QName xmlType,
                            Boolean sendNull,
                            Boolean sendType)
          throws IOException
      {
          throw new IOException(Messages.getMessage("notImplemented00",
                                                    "serialize"));
      }
  
      public void writeDOMElement(Element el)
          throws IOException
      {
          throw new IOException(Messages.getMessage("notImplemented00",
                                                    "writeDOMElement"));
      }
  
      public void startElement(QName qName, Attributes attributes)
          throws IOException
      {
          depth++;
          if (depth == 2) {
              this.ignore = true;
          }
      }
  
      public void endElement()
          throws IOException
      {
          depth--;
          ignore = true;
      }
  
      public void writeChars(char [] p1, int p2, int p3)
          throws IOException
      {
          if (!this.ignore) {
              super.writeChars(p1, p2, p3);
          }
      }
  
      public void writeString(String string)
          throws IOException
      {
          if (!this.ignore) {
              super.writeString(string);
          }
      }
  
  }
  
  
  
  1.188     +38 -1     ws-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.187
  retrieving revision 1.188
  diff -u -r1.187 -r1.188
  --- MessageElement.java	7 Nov 2004 11:26:37 -0000	1.187
  +++ MessageElement.java	11 Nov 2004 00:00:49 -0000	1.188
  @@ -23,6 +23,7 @@
   import org.apache.axis.encoding.DeserializationContext;
   import org.apache.axis.encoding.Deserializer;
   import org.apache.axis.encoding.SerializationContext;
  +import org.apache.axis.encoding.TextSerializationContext;
   import org.apache.axis.enum.Style;
   import org.apache.axis.soap.SOAPConstants;
   import org.apache.axis.utils.Mapping;
  @@ -2037,7 +2038,8 @@
               if(child.getNodeType()==TEXT_NODE ||
                  child.getNodeType()==CDATA_SECTION_NODE ||
                  child.getNodeType()==COMMENT_NODE ) {
  -                MessageElement childElement = new MessageElement((CharacterData)child);
  +                org.apache.axis.message.Text childElement = 
  +                    new org.apache.axis.message.Text((CharacterData)child);
                   dest.appendChild(childElement);
               } else {
                   PrefixedQName qname = new PrefixedQName(child.getNamespaceURI(),
  @@ -2059,6 +2061,41 @@
        * @see javax.xml.soap.Node#getValue() ;
        */
       public String getValue() {
  +        if ((recorder != null) && (!_isDirty)) {
  +            StringWriter writer = new StringWriter();
  +            TextSerializationContext outputContext = 
  +                new TextSerializationContext(writer);
  +            try {
  +                recorder.replay(startEventIndex,
  +                                endEventIndex,
  +                                new SAXOutputter(outputContext));
  +            } catch (Exception t) {
  +                log.debug("getValue()", t);
  +                return null;
  +            }
  +            String value = writer.toString();
  +            return (value.length() == 0) ? null : value;
  +        } 
  +
  +        if (textRep != null) {
  +            // weird case: error?
  +            return textRep.getNodeValue();
  +        }
  +
  +        if (objectValue != null) {
  +            return getValueDOM();
  +        }
  +
  +        if (children != null && !children.isEmpty()) {
  +            if (children.get(0) instanceof org.apache.axis.message.Text) {
  +                return ((org.apache.axis.message.Text)children.get(0)).getNodeValue();
  +            }
  +        }
  +
  +        return null;
  +    }
  +
  +    protected String getValueDOM() {
           try {
               Element element = getAsDOM();
               if (element.hasChildNodes()) {
  
  
  
  1.104     +5 -0      ws-axis/java/src/org/apache/axis/message/SOAPEnvelope.java
  
  Index: SOAPEnvelope.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPEnvelope.java,v
  retrieving revision 1.103
  retrieving revision 1.104
  diff -u -r1.103 -r1.104
  --- SOAPEnvelope.java	7 Nov 2004 11:26:37 -0000	1.103
  +++ SOAPEnvelope.java	11 Nov 2004 00:00:49 -0000	1.104
  @@ -672,4 +672,9 @@
               setOwnerDocumentForChildren(node.getChildNodes(), sp);  // recursively
       	}
       }
  +
  +    public  String getValue() {
  +        return getValueDOM();
  +    }
  +    
   }
  
  
  

Mime
View raw message