⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soapmappingregistry.java

📁 JavaWeb服务应用开发详解的配套源码,欢迎下载
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
  };

  /*
    This serializer does not apply escape sequences to its content.
    This serializer should be used for numbers and other things that
    will not have any of the following characters: {&, ", ', <, >}
  */
  Serializer ser = new Serializer()
  {
    public void marshall(String inScopeEncStyle, Class javaType, Object src,
                         Object context, Writer sink, NSStack nsStack,
                         XMLJavaMappingRegistry xjmr, SOAPContext ctx)
      throws IllegalArgumentException, IOException {
      nsStack.pushScope();

      SoapEncUtils.generateStructureHeader(inScopeEncStyle,
                                           javaType,
                                           context,
                                           sink,
                                           nsStack,
                                           xjmr);

      sink.write(src + "</" + context + '>');

      nsStack.popScope();
    }
  };

  Serializer serializers [] = {
    cleanSer,  // String
    ser,       // Integer
    ser,       // int
    ser,       // BigDecimal
    ser,       // Float
    ser,       // float
    ser,       // Double
    ser,       // double
    ser,       // Boolean
    ser,       // boolean
    ser,       // Long
    ser,       // long
    ser,       // Short
    ser,       // short
    ser,       // Byte
    ser,       // byte
    qNameSer,  // QName
    calSer,    // GregorianCalendar
    dateSer,   // Date
    partSer,   // MimeBodyPart
    partSer,   // InputStream
    partSer,   // DataSource
    partSer,   // DataHandler
    null,      // Object
  };

  Deserializer deserializers [] = {
    stringDeser,
    null,
    intDeser,
    decimalDeser,
    null,
    floatDeser,
    null,
    doubleDeser,
    null,
    booleanDeser,
    null,
    longDeser,
    null,
    shortDeser,
    null,
    byteDeser,
    qNameSer,
    calSer,
    dateSer,
    null,
    null,
    null,
    null,
    objDeser,
  };

  public SOAPMappingRegistry()
  {
    this(Constants.NS_URI_CURRENT_SCHEMA_XSD);
  }

  /**
   * Sets up serializers for the specified Schema typeset.
   * @param schemaURI Should be one of Constants.NS_URI_1999_SCHEMA_XSD,
   * Constants.NS_URI_2000_SCHEMA_XSD, or Constants.NS_URI_2001_SCHEMA_XSD.
   */
  public SOAPMappingRegistry(String schemaURI)
  {
    // Set up the correct "current" schema typeset.
    if (schemaURI.equals(Constants.NS_URI_1999_SCHEMA_XSD)) {
      schemaQNames = schema1999QNames;
      mapSchemaTypes(schema2000QNames, false);
      mapSchemaTypes(schema2001QNames, false);
    } else if (schemaURI.equals(Constants.NS_URI_2000_SCHEMA_XSD)) {
      schemaQNames = schema2000QNames;
      mapSchemaTypes(schema1999QNames, false);
      mapSchemaTypes(schema2001QNames, false);
    } else if (schemaURI.equals(Constants.NS_URI_2001_SCHEMA_XSD)) {
      schemaQNames = schema2001QNames;
      mapSchemaTypes(schema1999QNames, false);
      mapSchemaTypes(schema2000QNames, false);
    } else {
      System.err.println("WARNING: Unrecognized Schema URI '" + schemaURI +
                         "' specified.  Defaulting to '" + this.schemaURI +
                         "'.");
    }
    
    mapSchemaTypes(schemaQNames, true);
    
    // Register parameter serializer for SOAP-ENC encoding style.
    mapTypes(soapEncURI, RPCConstants.Q_ELEM_PARAMETER, Parameter.class,
             paramSer, paramSer);

    // Register array deserializer for SOAP-ENC encoding style.
    mapTypes(soapEncURI, arrayQName, null, null, arraySer);

    // Register parameter serializer for literal xml encoding style.
    mapTypes(Constants.NS_URI_LITERAL_XML, RPCConstants.Q_ELEM_PARAMETER,
             Parameter.class, xmlParamSer, xmlParamSer);

    try {
      Class XMISerializer = 
        Class.forName("org.apache.soap.util.xml.XMISerializer");
      Class XMIParameterSerializer =
        Class.forName("org.apache.soap.encoding.xmi.XMIParameterSerializer");

      // Register default serializers for XMI encoding style.
      mapTypes(Constants.NS_URI_XMI_ENC, null, null,
               (Serializer)XMISerializer.newInstance(),
               (Deserializer)XMIParameterSerializer.newInstance());

      // Register serializer for Parameter class - not deserializer!
      mapTypes(Constants.NS_URI_XMI_ENC, null, Parameter.class,
               (Serializer)XMIParameterSerializer.newInstance(), null);
    } catch (IllegalAccessException iae) {
    } catch (InstantiationException ie) {
    } catch (ClassNotFoundException cnfe) {
    } catch (NoClassDefFoundError ncdfe) {
      // If the class can't be loaded, continue without it...
    }

    /*
      Basic collection types - these should map fine to Perl, Python, C++...
      (but an encoding like this needs to be agreed upon)
    */
    mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Vector"),
             Vector.class, vectorSer, vectorSer);
    mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Map"),
             Hashtable.class, hashtableSer, hashtableSer);

    try {
      Class mapClass = Class.forName("java.util.Map");
      MapSerializer mapSer = new MapSerializer();

      mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Map"),
               mapClass, mapSer, mapSer);
    } catch (ClassNotFoundException cnfe) {
    } catch (NoClassDefFoundError ncdfe) {
      // If the class can't be loaded, continue without it...
    }

    /*
      Map a Java byte array to the SOAP-ENC:base64 subtype.
    */
    Base64Serializer base64Ser = new Base64Serializer();
    QName base64QName = new QName(soapEncURI, "base64");
    mapTypes(soapEncURI, base64QName, byte[].class, base64Ser, base64Ser);
  }
  
  /**
   * Map a set of schema types defined in the arrays above.  If
   * the "serialize" arg is set to true, we'll map the serializer
   * side (i.e. when output gets generated it'll be as those QNames),
   * otherwise we just do deserializers.
   */
  public void mapSchemaTypes(QName [] schemaQNames, boolean serialize)
  {    
    for (int i = 0; i < schemaQNames.length; i++) {
      QName qName = schemaQNames[i];
      Class cls = classes[i];
      Serializer ser = serialize ? serializers[i] : null;
      Deserializer dser = deserializers[i];
      
      mapTypes(soapEncURI, qName, cls, ser, dser);
    }
  }

  /**
   * This function overrides the one in XMLJavaMappingRegistry for the sole
   * purpose of returning SOAP-ENC:Array when javaType represents an array.
   * The XMLJavaMappingRegistry will be consulted first, and if no mapping
   * is found, SOAP-ENC:Array is returned. Obviously, this only applies when
   * the encoding style is soap encoding.
   */
  public QName queryElementType(Class javaType, String encodingStyleURI)
    throws IllegalArgumentException
  {
    try
    {
      return super.queryElementType(javaType, encodingStyleURI);
    }
    catch (IllegalArgumentException e)
    {
      if (javaType != null
          && (javaType.isArray())
          && encodingStyleURI != null
          && encodingStyleURI.equals(soapEncURI))
      {
        return arrayQName;
      }
      else
      {
        throw e;
      }
    }
  }

  /**
   * This function overrides the one in XMLJavaMappingRegistry for the sole
   * purpose of returning an ArraySerializer when javaType represents an
   * array. The XMLJavaMappingRegistry will be consulted first, and if no
   * serializer is found for javaType, ArraySerailizer is returned.
   * Obviously, this only applies when the encoding style is soap encoding.
   */
  public Serializer querySerializer(Class javaType, String encodingStyleURI)
    throws IllegalArgumentException
  {
    try
    {
      return super.querySerializer(javaType, encodingStyleURI);
    }
    catch (IllegalArgumentException e)
    {
      if (javaType != null
          && encodingStyleURI != null
          && encodingStyleURI.equals(soapEncURI))
      {
        if (javaType.isArray()) {
          return arraySer;
        }
      }
      throw e;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -