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 BodyBuilder.java SOAPFaultBuilder.java
Date Mon, 16 Jul 2001 12:03:48 GMT
gdaniels    01/07/16 05:03:48

  Modified:    java/src/org/apache/axis Message.java
               java/src/org/apache/axis/encoding Deserializer.java
               java/src/org/apache/axis/message BodyBuilder.java
                        SOAPFaultBuilder.java
  Log:
  Use callbacks when building faults to handle potential ID/HREFs
  
  Don't default to dynamically using the string deserializer - rather, just
  record the events and if someone asks for a value of a typeless element,
  hand them a string containing the serialized XML.
  
  Revision  Changes    Path
  1.40      +5 -0      xml-axis/java/src/org/apache/axis/Message.java
  
  Index: Message.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Message.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Message.java	2001/07/15 23:38:28	1.39
  +++ Message.java	2001/07/16 12:03:45	1.40
  @@ -147,6 +147,11 @@
           return( currentForm );
       }
       
  +    public String getMessageType()
  +    {
  +        return messageType;
  +    }
  +    
       public void setMessageType(String messageType)
       {
           this.messageType = messageType;
  
  
  
  1.5       +64 -11    xml-axis/java/src/org/apache/axis/encoding/Deserializer.java
  
  Index: Deserializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/Deserializer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Deserializer.java	2001/07/15 16:40:04	1.4
  +++ Deserializer.java	2001/07/16 12:03:46	1.5
  @@ -62,6 +62,7 @@
   import org.apache.axis.message.*;
   import org.apache.axis.utils.QName;
   
  +import java.io.*;
   import java.util.*;
   import java.lang.reflect.*;
   import java.lang.*;
  @@ -131,7 +132,36 @@
               }
           }
       }
  +    
  +    public static class MethodTarget implements Target {
  +        private Object targetObject;
  +        private Method targetMethod;
  +        private static final Class [] objArg = new Class [] { Object.class };
   
  +        public MethodTarget(Object targetObject, String methodName)
  +            throws NoSuchMethodException
  +        {
  +            this.targetObject = targetObject;
  +            Class cls = targetObject.getClass();
  +            targetMethod = cls.getMethod(methodName, objArg);
  +        }
  +        
  +        public void set(Object value) throws SAXException {
  +            try {
  +                targetMethod.invoke(targetObject, new Object [] { value });
  +            } catch (IllegalAccessException accEx) {
  +                accEx.printStackTrace();
  +                throw new SAXException(accEx);
  +            } catch (IllegalArgumentException argEx) {
  +                argEx.printStackTrace();
  +                throw new SAXException(argEx);
  +            } catch (InvocationTargetException targetEx) {
  +                targetEx.printStackTrace();
  +                throw new SAXException(targetEx);
  +            }
  +        }
  +    }
  +
       class CallbackTarget implements Target {
           public ValueReceiver target;
           public Object hint;
  @@ -206,6 +236,9 @@
           }
       }
       
  +    private int startIdx = 0;
  +    private int endIdx = -1;
  +    
       /** Subclasses override this
        */
       public void onStartElement(String namespace, String localName,
  @@ -223,17 +256,18 @@
               // We know we're deserializing, and we can't seem to figure
               // out a type... so let's give them a string.
               // ??? Is this the right thing to do?
  -            if (type == null)
  -                type = SOAPTypeMappingRegistry.XSD_STRING;
  -            
  -            Deserializer dser = 
  -                       context.getTypeMappingRegistry().getDeserializer(type);
  -            if (dser != null) {
  -                dser.copyValueTargets(this);
  -                context.replaceElementHandler(dser);
  -                // And don't forget to give it the start event...
  -                dser.startElement(namespace, localName, qName,
  -                                  attributes, context);
  +            if (type != null) {
  +                Deserializer dser = 
  +                                   context.getTypeMappingRegistry().getDeserializer(type);
  +                if (dser != null) {
  +                    dser.copyValueTargets(this);
  +                    context.replaceElementHandler(dser);
  +                    // And don't forget to give it the start event...
  +                    dser.startElement(namespace, localName, qName,
  +                                      attributes, context);
  +                }
  +            } else {
  +                startIdx = context.getCurrentRecordPos();
               }
           }
       }
  @@ -274,6 +308,25 @@
                              DeserializationContext context)
           throws SAXException
       {
  +        // If we only have SAX events, but someone really wanted a
  +        // value, try sending them the contents of this element
  +        // as a String...
  +        // ??? Is this the right thing to do here?
  +        
  +        if (this.getClass().equals(Deserializer.class) &&
  +            !targets.isEmpty()) {
  +            endIdx = context.getCurrentRecordPos();
  +            
  +            StringWriter writer = new StringWriter();
  +            SerializationContext serContext = 
  +                        new SerializationContext(writer,
  +                                                 context.getMessageContext());
  +            SAXOutputter so = new SAXOutputter(serContext);
  +            context.getRecorder().replay(startIdx + 1,
  +                                         endIdx - 1,
  +                                         so);
  +            value = writer.getBuffer().toString();
  +        }
           valueComplete();
       }
   }
  
  
  
  1.3       +2 -1      xml-axis/java/src/org/apache/axis/message/BodyBuilder.java
  
  Index: BodyBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/BodyBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BodyBuilder.java	2001/07/15 21:10:06	1.2
  +++ BodyBuilder.java	2001/07/16 12:03:47	1.3
  @@ -62,7 +62,8 @@
               namespace.equals(Constants.URI_SOAP_ENV)) {
               element = new SOAPFaultElement(namespace, localName,
                                              attributes, context);
  -            handler = new SOAPFaultBuilder((SOAPFaultElement)element);
  +            handler = new SOAPFaultBuilder((SOAPFaultElement)element,
  +                                           context);
           } else if (!gotRPCElement &&
               isRoot && 
               ((serviceDesc == null) || (serviceDesc.isRPC()))) {
  
  
  
  1.2       +41 -26    xml-axis/java/src/org/apache/axis/message/SOAPFaultBuilder.java
  
  Index: SOAPFaultBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPFaultBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SOAPFaultBuilder.java	2001/07/15 21:10:07	1.1
  +++ SOAPFaultBuilder.java	2001/07/16 12:03:47	1.2
  @@ -59,22 +59,35 @@
   import org.apache.axis.AxisFault;
   import org.apache.axis.encoding.*;
   import org.apache.axis.utils.QFault;
  +import org.apache.axis.utils.QName;
   
  +import java.util.HashMap;
  +
   /** 
    * Build a Fault body element.
    * 
    * @author Sam Ruby (rubys@us.ibm.com)
    * @author Glen Daniels (gdaniels@macromedia.com)
    */
  -public class SOAPFaultBuilder extends SOAPHandler
  +public class SOAPFaultBuilder extends SOAPHandler implements ValueReceiver
   {
  -    String currentSubElement;
  -    Deserializer currentDeser;
  -    
  -    protected SOAPFaultElement element;    
  +    protected SOAPFaultElement element;
  +    protected AxisFault fault;
  +    protected DeserializationContext context;
  +    static HashMap fields = new HashMap();
  +
  +    static {
  +        fields.put("faultcode", SOAPTypeMappingRegistry.XSD_STRING);
  +        fields.put("faultstring", SOAPTypeMappingRegistry.XSD_STRING);
  +        fields.put("faultactor", SOAPTypeMappingRegistry.XSD_STRING);
  +        fields.put("details", null);
  +    }
       
  -    public SOAPFaultBuilder(SOAPFaultElement element) {
  +    public SOAPFaultBuilder(SOAPFaultElement element,
  +                            DeserializationContext context) {
           this.element = element;
  +        this.context = context;
  +        fault = element.getAxisFault();
       }
   
       public SOAPHandler onStartChild(String namespace,
  @@ -83,29 +96,31 @@
                                       DeserializationContext context)
           throws SAXException
       {
  -        currentSubElement = name;
  -        currentDeser = context.getTypeMappingRegistry().
  -                          getDeserializer(SOAPTypeMappingRegistry.XSD_STRING);
  +        Deserializer currentDeser = null;
  +        
  +        QName qName = (QName)fields.get(name);
  +        
  +        if (qName != null) {
  +            currentDeser = context.getTypeMappingRegistry().
  +                          getDeserializer(qName);
  +            currentDeser.registerCallback(this, name);
  +        }
  +        
           return currentDeser;
  -    }
  +    } 
       
  -    public void onEndChild(String namespace, String localName, 
  -                           DeserializationContext context)
  -        throws SAXException
  +    public void valueReady(Object value, Object hint)
       {
  -        AxisFault fault = element.getAxisFault();
  -        String value = currentDeser.getValue().toString();
  -
  -        if (currentSubElement.equals("faultcode")) {
  -            fault.setFaultCode(new QFault(context.getQNameFromString(value)));
  -        } else if (currentSubElement.equals("faultstring")) {
  -            fault.setFaultString(currentDeser.getValue().toString());
  -        } else if (currentSubElement.equals("faultactor")) {
  -            fault.setFaultActor(currentDeser.getValue().toString());
  -        } else if (currentSubElement.equals("details")) {
  -            // !!! Not supported yet
  -            // fault.setFaultDetails(...);
  +        String name = (String)hint;
  +        if (name.equals("faultcode")) {
  +            fault.setFaultCode(
  +                         new QFault(
  +                               context.getQNameFromString((String)value)));
  +        } else if (name.equals("faultstring")) {
  +            fault.setFaultString((String)value);
  +        } else if (name.equals("faultactor")) {
  +            fault.setFaultActor((String)value);
           }
  +        
       }
  -
   }
  
  
  

Mime
View raw message