axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bu...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/encoding HexSerializer.java Hex.java XMLType.java SOAPTypeMappingRegistry.java
Date Wed, 10 Oct 2001 12:58:12 GMT
butek       01/10/10 05:58:12

  Modified:    java/src/org/apache/axis/encoding XMLType.java
                        SOAPTypeMappingRegistry.java
  Added:       java/src/org/apache/axis/encoding HexSerializer.java
                        Hex.java
  Log:
  Here are the hexBinary additions from Davanum Srinivas (dims@yahoo.com).  His
  work isn't complete, yet.  For example, line 255 is commented out because it still
  needs some debugging, so it's just a placeholder for now.
  
  Revision  Changes    Path
  1.4       +1 -0      xml-axis/java/src/org/apache/axis/encoding/XMLType.java
  
  Index: XMLType.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/XMLType.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLType.java	2001/10/04 17:25:09	1.3
  +++ XMLType.java	2001/10/10 12:58:11	1.4
  @@ -77,6 +77,7 @@
       public static final XMLType XSD_BYTE = new XMLType(new QName(Constants.URI_CURRENT_SCHEMA_XSD,
"byte"));
       public static final XMLType XSD_DECIMAL = new XMLType(new QName(Constants.URI_CURRENT_SCHEMA_XSD,
"decimal"));
       public static final XMLType XSD_BASE64 = new XMLType(new QName(Constants.URI_2001_SCHEMA_XSD,
"base64Binary"));
  +//    public static final XMLType XSD_HEXBIN = new XMLType(new QName(Constants.URI_2001_SCHEMA_XSD,
"hexBinary"));
       public static final XMLType XSD_ANYTYPE = new XMLType(new QName(Constants.URI_2001_SCHEMA_XSD,
"anyType"));
       public static final XMLType SOAP_BASE64 = new XMLType(new QName(Constants.URI_SOAP_ENC,
"base64"));
   
  
  
  
  1.37      +7 -0      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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- SOAPTypeMappingRegistry.java	2001/10/04 16:49:08	1.36
  +++ SOAPTypeMappingRegistry.java	2001/10/10 12:58:11	1.37
  @@ -78,6 +78,7 @@
       public static final QName XSD_BYTE = new QName(Constants.URI_CURRENT_SCHEMA_XSD, "byte");
       public static final QName XSD_DECIMAL = new QName(Constants.URI_CURRENT_SCHEMA_XSD,
"decimal");
       public static final QName XSD_BASE64 = new QName(Constants.URI_2001_SCHEMA_XSD, "base64Binary");
  +    public static final QName XSD_HEXBIN = new QName(Constants.URI_2001_SCHEMA_XSD, "hexBinary");
       public static final QName XSD_ANYTYPE = new QName(Constants.URI_2001_SCHEMA_XSD, "anyType");
       public static final QName SOAP_BASE64 = new QName(Constants.URI_SOAP_ENC, "base64");
   
  @@ -191,6 +192,8 @@
       private DeserializerFactory factory = new BasicDeserializerFactory();
       private DeserializerFactory base64Ser = 
          new Base64Serializer.Base64DeserializerFactory();
  +    private DeserializerFactory hexSer =
  +      new HexSerializer.HexDeserializerFactory();
   
       /**
        * Alias common DeserializerFactories across the various popular schemas
  @@ -249,6 +252,7 @@
           addSerializer(java.lang.Byte.TYPE, XSD_BYTE, se);
           addSerializer(java.util.Date.class, XSD_DATE, new DateSerializer());
           addSerializer(byte[].class, XSD_BASE64, new Base64Serializer());
  +//        addSerializer(byte[].class, XSD_HEXBIN, new HexSerializer());
           addSerializer(java.math.BigDecimal.class, XSD_DECIMAL, se);
           
           addDeserializersFor(XSD_STRING, java.lang.String.class, factory);    
  @@ -284,6 +288,9 @@
           // handle the various base64 QNames...
           addDeserializerFactory(SOAP_BASE64, byte[].class, base64Ser);
           addDeserializerFactory(XSD_BASE64, byte[].class, base64Ser);
  +
  +        // handle the hexBinary QName...
  +        addDeserializerFactory(XSD_HEXBIN, byte[].class, hexSer);
   
           // !!! Seems a little weird to pass a null class here...?
           addDeserializerFactory(SOAP_ARRAY, null, ArraySerializer.factory);
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/encoding/HexSerializer.java
  
  Index: HexSerializer.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.encoding;
  
  import org.apache.axis.utils.QName;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  
  /**
   * serializer/deserializerFactory for hexBinary.
   *
   * @author Davanum Srinivas <dims@yahoo.com>
   * @see <a href="http://www.w3.org/TR/2001/PR-xmlschema-2-20010330/#hexBinary">XML
Schema 3.2.16</a>
   */
  public class HexSerializer implements Serializer {
  
      static class HexDeser extends Deserializer {
          public void characters(char [] chars, int start, int end)
              throws SAXException
          {
              value = Hex.decode(chars, start, end);
          }
      }
  
      static public class HexDeserializerFactory
          implements DeserializerFactory 
      {
          public Deserializer getDeserializer(Class cls) {return new HexDeser();}
      }
  
      /** 
       * Serialize a Hex quantity.
       */
      public void serialize(QName name, Attributes attributes,
                            Object value, SerializationContext context)
          throws IOException
      {
          byte[] data = (byte[]) value;
  
          context.startElement(name, attributes);
          context.writeString(Hex.encode(data, 0, data.length));
          context.endElement();
      }
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/encoding/Hex.java
  
  Index: Hex.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.encoding ;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.Writer;
  
  /**
   *
   * @author TAMURA Kent &lt;kent@trl.ibm.co.jp&gt;
   */
  public class Hex {
      private static final char[] S_HEXCHAR = {
          '0', '1', '2', '3', '4', '5', '6', '7',
          '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
      };
      private static final char S_HEXPAD = '=';
      private static final byte[] S_DECODETABLE = new byte[32];
      static {
          for (int i = 0;  i < S_DECODETABLE.length;  i ++)
              S_DECODETABLE[i] = Byte.MAX_VALUE;  // 127
          for (int i = 0;  i < S_HEXCHAR.length;  i ++) // 0 to 15
              S_DECODETABLE[S_HEXCHAR[i]] = (byte)i;
      }
  
      private static int decode0(char[] ibuf, byte[] obuf, int wp) {
          int b0 = S_DECODETABLE[ibuf[0]];
          int b1 = S_DECODETABLE[ibuf[1]];
          obuf[wp] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
          return 1;
      }
  
      /**
       *
       */
      public static byte[] decode(char[] data, int off, int len) {
          char[] ibuf = new char[2];
          int ibufcount = 0;
          byte[] obuf = new byte[len/2*1+1];
          int obufcount = 0;
          for (int i = off;  i < off+len;  i ++) {
              char ch = data[i];
              if (ch == S_HEXPAD
                  || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE)
{
                  ibuf[ibufcount++] = ch;
                  if (ibufcount == ibuf.length) {
                      ibufcount = 0;
                      obufcount += decode0(ibuf, obuf, obufcount);
                  }
              }
          }
          if (obufcount == obuf.length)
              return obuf;
          byte[] ret = new byte[obufcount];
          System.arraycopy(obuf, 0, ret, 0, obufcount);
          return ret;
      }
  
      /**
       *
       */
      public static byte[] decode(String data) {
          char[] ibuf = new char[2];
          int ibufcount = 0;
          byte[] obuf = new byte[data.length()/2*1+1];
          int obufcount = 0;
          for (int i = 0;  i < data.length();  i ++) {
              char ch = data.charAt(i);
              if (ch == S_HEXPAD
                  || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE)
{
                  ibuf[ibufcount++] = ch;
                  if (ibufcount == ibuf.length) {
                      ibufcount = 0;
                      obufcount += decode0(ibuf, obuf, obufcount);
                  }
              }
          }
          if (obufcount == obuf.length)
              return obuf;
          byte[] ret = new byte[obufcount];
          System.arraycopy(obuf, 0, ret, 0, obufcount);
          return ret;
      }
  
      /**
       *
       */
      public static void decode(char[] data, int off, int len, OutputStream ostream) throws
IOException {
          char[] ibuf = new char[2];
          int ibufcount = 0;
          byte[] obuf = new byte[1];
          for (int i = off;  i < off+len;  i ++) {
              char ch = data[i];
              if (ch == S_HEXPAD
                  || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE)
{
                  ibuf[ibufcount++] = ch;
                  if (ibufcount == ibuf.length) {
                      ibufcount = 0;
                      int obufcount = decode0(ibuf, obuf, 0);
                      ostream.write(obuf, 0, obufcount);
                  }
              }
          }
      }
  
      /**
       *
       */
      public static void decode(String data, OutputStream ostream) throws IOException {
          char[] ibuf = new char[2];
          int ibufcount = 0;
          byte[] obuf = new byte[1];
          for (int i = 0;  i < data.length();  i ++) {
              char ch = data.charAt(i);
              if (ch == S_HEXPAD
                  || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE)
{
                  ibuf[ibufcount++] = ch;
                  if (ibufcount == ibuf.length) {
                      ibufcount = 0;
                      int obufcount = decode0(ibuf, obuf, 0);
                      ostream.write(obuf, 0, obufcount);
                  }
              }
          }
      }
  
      /**
       * Returns hex representation of specified byte array.
       */
      public static String encode(byte[] data) {
          return encode(data, 0, data.length);
      }
  
      /**
       * Returns hex representation of specified byte array.
       */
      public static String encode(byte[] data, int off, int len) {
          if (len <= 0)  return "";
          char[] out = new char[len/1*2+2];
          int rindex = off;
          int windex = 0;
          int rest = len-off;
          while (rest >= 1) {
              int i = ((data[rindex]&0xff)<<8)
                      +(data[rindex+1]&0xff);
              out[windex++] = S_HEXCHAR[(i>>6)&0x3f];
              out[windex++] = S_HEXCHAR[i&0x3f];
              rindex += 3;
              rest -= 3;
          }
          if (rest == 1) {
              int i = data[rindex]&0xff;
              out[windex++] = S_HEXCHAR[i>>2];
              out[windex++] = S_HEXPAD;
          }
          return new String(out, 0, windex);
      }
  
      /**
       * Outputs hex representation of the specified byte array to a byte stream.
       */
      public static void encode(byte[] data, int off, int len, OutputStream ostream) throws
IOException {
          if (len <= 0)  return;
          byte[] out = new byte[4];
          int rindex = off;
          int rest = len-off;
          while (rest >= 1) {
              int i = ((data[rindex]&0xff)<<8)
                      +(data[rindex+1]&0xff);
              out[0] = (byte)S_HEXCHAR[(i>>6)&0x3f];
              out[1] = (byte)S_HEXCHAR[i&0x3f];
              ostream.write(out, 0, 2);
              rindex += 1;
              rest -= 1;
          }
          if (rest == 1) {
              int i = data[rindex]&0xff;
              out[0] = (byte)S_HEXCHAR[i>>2];
              out[1] = (byte)S_HEXCHAR[(i<<4)&0x3f];
              ostream.write(out, 0, 2);
          }
      }
  
      /**
       * Outputs hex representation of the specified byte array to a character stream.
       */
      public static void encode(byte[] data, int off, int len, Writer writer) throws IOException
{
          if (len <= 0)  return;
          char[] out = new char[4];
          int rindex = off;
          int rest = len-off;
          int output = 0;
          while (rest >= 1) {
              int i = ((data[rindex]&0xff)<<8)
                      +(data[rindex+1]&0xff);
              out[0] = S_HEXCHAR[(i>>6)&0x3f];
              out[1] = S_HEXCHAR[i&0x3f];
              writer.write(out, 0, 2);
              rindex += 1;
              rest -= 1;
              output += 2;
              if (output % 19 == 0)
                  writer.write("\n");
          }
          if (rest == 1) {
              int i = data[rindex]&0xff;
              out[0] = S_HEXCHAR[i>>2];
              out[1] = S_HEXCHAR[(i<<4)&0x3f];
              writer.write(out, 0, 2);
          }
      }
  }
  
  
  

Mime
View raw message