Aug 19, 2014

Android MarshalDouble,MarshalDate

package helper;

import java.io.IOException;
import java.util.Date;

import org.kobjects.isodate.IsoDate;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

public class MarshalDate implements Marshal
{

        public Object readInstance(XmlPullParser parser, String namespace, String name,
                PropertyInfo expected) throws IOException, XmlPullParserException {
           
            return IsoDate.stringToDate(parser.nextText(), IsoDate.DATE_TIME);
           
           
        }


        public void register(SoapSerializationEnvelope cm) {
             cm.addMapping(cm.xsd, "DateTime", Date.class, this);
           
        }


        public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
             writer.text(IsoDate.dateToString((Date) obj, IsoDate.DATE_TIME));
            }
   
}
package helper;

import java.io.IOException;

import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

public class MarshalDouble implements Marshal
{

    @Override
    public Object readInstance(XmlPullParser parser, String namespace, String name,
            PropertyInfo expected) throws IOException, XmlPullParserException {
   
        return Double.parseDouble(parser.nextText());
    }
   
    public void register(SoapSerializationEnvelope cm) {
         cm.addMapping(cm.xsd, "double", Double.class, this);
   
    }
   
    @Override
    public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
           writer.text(obj.toString());
        }          
}

using
// OrderedQuantity
            PropertyInfo propInfo = new PropertyInfo();
            propInfo.setName("OrderedQuantity");
            propInfo.setType(Double.class);
            propInfo.setValue(obj.getOrderedQuantity());
            request.addProperty(propInfo);
SoapSerializationEnvelope envelope = GetEnvelope(request);
            MarshalDouble md = new MarshalDouble();
            md.register(envelope);

0 comments:

Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib