Class: SOAP::Generator

### Home Classes Methods

### In Files

- lib/soap/generator.rb

### Parent

Object

### Namespace

- CLASS SOAP::Generator::FormatEncodeError

### Methods

- ::assign_ns
- ::assign_ns!
- ::new
- #add_reftarget
- #element_local?
- #encode_child
- #encode_data
- #encode_element
- #encode_name
- #encode_name_end
- #encode_rawstring
- #encode_string
- #encode_tag
- #encode_tag_end
- #generate

### Included Modules

- SOAP
- XSD::CodeGen::GenSupport

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- SOAP
- SOAP::ArrayIndexOutOfBoundsError
- SOAP::ArrayStoreError
- SOAP::Attachment
- SOAP::AttrProxy
- SOAP::AttrProxy::AttrProxyClassSupport
- SOAP::EmptyResponseError
- SOAP::EncodingStyle
- SOAP::EncodingStyle::ASPDotNetHandler
- SOAP::EncodingStyle::ASPDotNetHandler::SOAPTemporalObject
- SOAP::EncodingStyle::ASPDotNetHandler::SOAPUnknown
- SOAP::EncodingStyle::Handler
- SOAP::EncodingStyle::Handler::EncodingStyleError
- SOAP::EncodingStyle::LiteralHandler
- SOAP::EncodingStyle::SOAPHandler
- SOAP::EncodingStyle::SOAPHandler::SOAPTemporalObject
- SOAP::EncodingStyle::SOAPHandler::SOAPUnknown
- SOAP::Env
- SOAP::Error
- SOAP::FaultCode
- SOAP::FaultError
- SOAP::Filter
- SOAP::Filter::FilterChain
- SOAP::Filter::Handler
- SOAP::Filter::StreamHandler
- SOAP::Generator
- SOAP::Generator::FormatEncodeError
- SOAP::HTTPConfigLoader
- SOAP::HTTPStreamError
- SOAP::HTTPStreamHandler
- SOAP::HTTPStreamHandler::Client
- SOAP::HTTPStreamHandler::HttpPostRequestFilter
- SOAP::Header
- SOAP::Header::Handler
- SOAP::Header::HandlerSet
- SOAP::Header::MappingHandler
- SOAP::Header::SimpleHandler
- SOAP::MIMEMessage
- SOAP::MIMEMessage::Header
- SOAP::MIMEMessage::Headers
- SOAP::MIMEMessage::MIMEMessageError
- SOAP::MIMEMessage::Part
- SOAP::MPostUnavailableError
- SOAP::Mapping
- SOAP::Mapping::ArrayFactory_
- SOAP::Mapping::AttachmentFactory
- SOAP::Mapping::Base64Factory_
- SOAP::Mapping::BasetypeFactory_
- SOAP::Mapping::DateTimeFactory_
- SOAP::Mapping::EncodedRegistry
- SOAP::Mapping::EncodedRegistry::Map
- SOAP::Mapping::Factory
- SOAP::Mapping::FixnumFactory_
- SOAP::Mapping::HashFactory_
- SOAP::Mapping::LiteralRegistry
- SOAP::Mapping::MappedException
- SOAP::Mapping::MappingError
- SOAP::Mapping::Object
- SOAP::Mapping::Registry
- SOAP::Mapping::RegistrySupport
- SOAP::Mapping::RubytypeFactory
- SOAP::Mapping::SOAPException
- SOAP::Mapping::SchemaChoiceDefinition
- SOAP::Mapping::SchemaComplexTypeDefinition
- SOAP::Mapping::SchemaDefinition
- SOAP::Mapping::SchemaElementDefinition
- SOAP::Mapping::SchemaEmptyDefinition
- SOAP::Mapping::SchemaSequenceDefinition
- SOAP::Mapping::StringFactory_
- SOAP::Mapping::TraverseSupport
- SOAP::Mapping::TypedArrayFactory_
- SOAP::Mapping::TypedStructFactory_
- SOAP::Mapping::URIFactory_
- SOAP::Mapping::WSDLEncodedRegistry
- SOAP::Mapping::WSDLLiteralRegistry
- SOAP::Marshal
- SOAP::Marshal
- SOAP::Marshallable
- SOAP::NS
- SOAP::NestedException
- SOAP::NetHttpClient
- SOAP::NetHttpClient::Response
- SOAP::NetHttpClient::SessionManager
- SOAP::Parser
- SOAP::Parser::FormatDecodeError
- SOAP::Parser::ParseError
- SOAP::Parser::ParseFrame
- SOAP::Parser::ParseFrame::NodeContainer
- SOAP::Parser::UnexpectedElementError
- SOAP::PostUnavailableError
- SOAP::Processor
- SOAP::Property
- SOAP::Property::Util
- SOAP::RPC
- SOAP::RPC::CGIStub
- SOAP::RPC::CGIStub::SOAPFCGIRequest
- SOAP::RPC::CGIStub::SOAPRequest
- SOAP::RPC::CGIStub::SOAPStdinRequest
- SOAP::RPC::Driver
- SOAP::RPC::HTTPServer
- SOAP::RPC::MethodDef
- SOAP::RPC::MethodDef::Parameter
- SOAP::RPC::MethodDefinitionError
- SOAP::RPC::ParameterError
- SOAP::RPC::Proxy
- SOAP::RPC::Proxy::Operation
- SOAP::RPC::RPCError
- SOAP::RPC::Router
- SOAP::RPC::Router::ApplicationScopeOperation
- SOAP::RPC::Router::Operation
- SOAP::RPC::Router::RequestScopeOperation
- SOAP::RPC::SOAPMethod
- SOAP::RPC::SOAPMethodRequest
- SOAP::RPC::SOAPMethodResponse
- SOAP::RPC::SOAPVoid
- SOAP::RPC::SOAPlet
- SOAP::RPC::StandaloneServer
- SOAP::RPCRoutingError
- SOAP::ResponseFormatError
- SOAP::SOAPAnySimpleType
- SOAP::SOAPAnyURI
- SOAP::SOAPArray
- SOAP::SOAPAttachment
- SOAP::SOAPBase64
- SOAP::SOAPBasetype
- SOAP::SOAPBody
- SOAP::SOAPBoolean
- SOAP::SOAPByte
- SOAP::SOAPCompoundtype
- SOAP::SOAPDate
- SOAP::SOAPDateTime
- SOAP::SOAPDecimal
- SOAP::SOAPDouble
- SOAP::SOAPDuration
- SOAP::SOAPENTITIES
- SOAP::SOAPENTITY
- SOAP::SOAPElement
- SOAP::SOAPEnvelope
- SOAP::SOAPEnvelopeElement
- SOAP::SOAPExternalReference
- SOAP::SOAPFault
- SOAP::SOAPFloat
- SOAP::SOAPGDay
- SOAP::SOAPGMonth
- SOAP::SOAPGMonthDay
- SOAP::SOAPGYear
- SOAP::SOAPGYearMonth
- SOAP::SOAPHeader
- SOAP::SOAPHeaderItem
- SOAP::SOAPHexBinary
- SOAP::SOAPID
- SOAP::SOAPIDREF
- SOAP::SOAPIDREFS
- SOAP::SOAPInt
- SOAP::SOAPInteger
- SOAP::SOAPLanguage
- SOAP::SOAPLong
- SOAP::SOAPModuleUtils
- SOAP::SOAPNCName
- SOAP::SOAPNMTOKEN
- SOAP::SOAPNMTOKENS
- SOAP::SOAPName
- SOAP::SOAPNameAccessible
- SOAP::SOAPNegativeInteger
- SOAP::SOAPNil
- SOAP::SOAPNonNegativeInteger
- SOAP::SOAPNonPositiveInteger
- SOAP::SOAPNormalizedString
- SOAP::SOAPPositiveInteger
- SOAP::SOAPQName
- SOAP::SOAPREXMLElementWrap
- SOAP::SOAPRawData
- SOAP::SOAPRawString
- SOAP::SOAPReference
- SOAP::SOAPShort
- SOAP::SOAPString
- SOAP::SOAPStruct
- SOAP::SOAPTime
- SOAP::SOAPToken
- SOAP::SOAPType
- SOAP::SOAPUnsignedByte
- SOAP::SOAPUnsignedInt
- SOAP::SOAPUnsignedLong
- SOAP::SOAPUnsignedShort
- SOAP::StreamError
- SOAP::StreamHandler
- SOAP::StreamHandler::ConnectionData
- SOAP::UnhandledMustUnderstandHeaderError
- SOAP::WSDLDriverFactory
- SOAP::WSDLDriverFactory::FactoryError
- WSDL
- WSDL::Binding
- WSDL::Definitions
- WSDL::Documentation
- WSDL::Error
- WSDL::Import
- WSDL::Importer
- WSDL::Info
- WSDL::Message
- WSDL::Operation
- WSDL::OperationBinding
- WSDL::OperationBinding::BoundId
- WSDL::OperationBinding::OperationInfo
- WSDL::OperationBinding::Part
- WSDL::Param
- WSDL::Parser
- WSDL::Parser::AttributeConstraintError
- WSDL::Parser::ElementConstraintError
- WSDL::Parser::FormatDecodeError
- WSDL::Parser::ParseError
- WSDL::Parser::ParseFrame
- WSDL::Parser::UnexpectedElementError
- WSDL::Parser::UnknownAttributeError
- WSDL::Parser::UnknownElementError
- WSDL::Part
- WSDL::Port
- WSDL::PortType
- WSDL::SOAP
- WSDL::SOAP::Address
- WSDL::SOAP::Binding
- WSDL::SOAP::Body
- WSDL::SOAP::CGIStubCreator
- WSDL::SOAP::ClassDefCreator
- WSDL::SOAP::ClassDefCreatorSupport
- WSDL::SOAP::ClassNameCreator
- WSDL::SOAP::ClientSkeltonCreator
- WSDL::SOAP::DriverCreator
- WSDL::SOAP::EncodedMappingRegistryCreator
- WSDL::SOAP::Fault
- WSDL::SOAP::Header
- WSDL::SOAP::HeaderFault
- WSDL::SOAP::LiteralMappingRegistryCreator
- WSDL::SOAP::MappingRegistryCreator
- WSDL::SOAP::MappingRegistryCreatorSupport
- WSDL::SOAP::MethodDefCreator
- WSDL::SOAP::Operation
- WSDL::SOAP::Operation::ParamInfo
- WSDL::SOAP::ServantSkeltonCreator
- WSDL::SOAP::ServletStubCreator
- WSDL::SOAP::StandaloneServerStubCreator
- WSDL::SOAP::WSDL2Ruby
- WSDL::Service
- WSDL::Types
- WSDL::XMLSchema
- WSDL::XMLSchema::All
- WSDL::XMLSchema::Annotation
- WSDL::XMLSchema::Any
- WSDL::XMLSchema::AnyAttribute
- WSDL::XMLSchema::Attribute
- WSDL::XMLSchema::AttributeGroup
- WSDL::XMLSchema::Choice
- WSDL::XMLSchema::ComplexContent
- WSDL::XMLSchema::ComplexExtension
- WSDL::XMLSchema::ComplexRestriction
- WSDL::XMLSchema::ComplexType
- WSDL::XMLSchema::Content
- WSDL::XMLSchema::Element
- WSDL::XMLSchema::Enumeration
- WSDL::XMLSchema::FractionDigits
- WSDL::XMLSchema::Group
- WSDL::XMLSchema::Import
- WSDL::XMLSchema::ImportHandler
- WSDL::XMLSchema::Importer
- WSDL::XMLSchema::Include
- WSDL::XMLSchema::Length
- WSDL::XMLSchema::List
- WSDL::XMLSchema::MaxExclusive
- WSDL::XMLSchema::MaxInclusive
- WSDL::XMLSchema::MaxLength
- WSDL::XMLSchema::MinExclusive
- WSDL::XMLSchema::MinInclusive
- WSDL::XMLSchema::MinLength
- WSDL::XMLSchema::Parser
- WSDL::XMLSchema::Parser::AttributeConstraintError
- WSDL::XMLSchema::Parser::ElementConstraintError
- WSDL::XMLSchema::Parser::FormatDecodeError
- WSDL::XMLSchema::Parser::ParseError
- WSDL::XMLSchema::Parser::ParseFrame
- WSDL::XMLSchema::Parser::UnexpectedElementError
- WSDL::XMLSchema::Parser::UnknownAttributeError
- WSDL::XMLSchema::Parser::UnknownElementError
- WSDL::XMLSchema::Pattern
- WSDL::XMLSchema::Ref
- WSDL::XMLSchema::Ref::RefClassSupport
- WSDL::XMLSchema::Schema
- WSDL::XMLSchema::Sequence
- WSDL::XMLSchema::SimpleContent
- WSDL::XMLSchema::SimpleExtension
- WSDL::XMLSchema::SimpleRestriction
- WSDL::XMLSchema::SimpleType
- WSDL::XMLSchema::TotalDigits
- WSDL::XMLSchema::Union
- WSDL::XMLSchema::Unique
- WSDL::XMLSchema::WhiteSpace
- WSDL::XMLSchema::XSD2Ruby
- XSD
- XSD::Charset
- XSD::Charset::CharsetConversionError
- XSD::Charset::CharsetError
- XSD::Charset::UnknownCharsetError
- XSD::Charset::XSDError
- XSD::CodeGen
- XSD::CodeGen::ClassDef
- XSD::CodeGen::CommentDef
- XSD::CodeGen::GenSupport
- XSD::CodeGen::MethodDef
- XSD::CodeGen::ModuleDef
- XSD::Error
- XSD::FloatConstants
- XSD::IconvCharset
- XSD::Mapping
- XSD::Mapping::Mapper
- XSD::NS
- XSD::NS::Assigner
- XSD::NS::FormatError
- XSD::NSDBase
- XSD::NamedElements
- XSD::QName
- XSD::ValueSpaceError
- XSD::XMLParser
- XSD::XMLParser::LibXMLParser
- XSD::XMLParser::Parser
- XSD::XMLParser::Parser::ElementConstraintError
- XSD::XMLParser::Parser::FormatDecodeError
- XSD::XMLParser::Parser::ParseError
- XSD::XMLParser::Parser::ParserError
- XSD::XMLParser::Parser::UnexpectedElementError
- XSD::XMLParser::Parser::UnknownAttributeError
- XSD::XMLParser::Parser::UnknownElementError
- XSD::XMLParser::REXMLParser
- XSD::XMLParser::XMLParser
- XSD::XMLParser::XMLParser::Listener
- XSD::XMLParser::XMLScanner
- XSD::XSDAnySimpleType
- XSD::XSDAnyURI
- XSD::XSDBase64Binary
- XSD::XSDBoolean
- XSD::XSDByte
- XSD::XSDDate
- XSD::XSDDateTime
- XSD::XSDDateTimeImpl
- XSD::XSDDecimal
- XSD::XSDDouble
- XSD::XSDDuration
- XSD::XSDENTITIES
- XSD::XSDENTITY
- XSD::XSDFloat
- XSD::XSDGDay
- XSD::XSDGMonth
- XSD::XSDGMonthDay
- XSD::XSDGYear
- XSD::XSDGYearMonth
- XSD::XSDHexBinary
- XSD::XSDID
- XSD::XSDIDREF
- XSD::XSDIDREFS
- XSD::XSDInt
- XSD::XSDInteger
- XSD::XSDLanguage
- XSD::XSDLong
- XSD::XSDNCName
- XSD::XSDNMTOKEN
- XSD::XSDNMTOKENS
- XSD::XSDName
- XSD::XSDNegativeInteger
- XSD::XSDNil
- XSD::XSDNonNegativeInteger
- XSD::XSDNonPositiveInteger
- XSD::XSDNormalizedString
- XSD::XSDPositiveInteger
- XSD::XSDQName
- XSD::XSDShort
- XSD::XSDString
- XSD::XSDTime
- XSD::XSDToken
- XSD::XSDUnsignedByte
- XSD::XSDUnsignedInt
- XSD::XSDUnsignedLong
- XSD::XSDUnsignedShort
- Object
- Object::SOAPMarshal
- WEBrick
- WEBrick::Log
- Enumerable
- Hash
- Kernel

No matching classes.

# SOAP::Generator

CAUTION: MT-unsafe

### Constants

ENCODE_CHAR_REGEXP
EncodeMap

### Attributes

charset[RW]
default_encodingstyle[RW]
generate_explicit_type[RW]
use_default_namespace[RW]
use_numeric_character_reference[RW]

### Public Class Methods

assign_ns(attrs, ns, namespace, tag = nil) click to toggle source

    # File lib/soap/generator.rb, line 217
    def self.assign_ns(attrs, ns, namespace, tag = nil)
      if namespace.nil?
        raise FormatEncodeError.new("empty namespace")
      end
      override_default_ns = (tag == '' and namespace != ns.default_namespace)
      if override_default_ns or !ns.assigned?(namespace)
        assign_ns!(attrs, ns, namespace, tag)
      end
    end

assign_ns!(attrs, ns, namespace, tag = nil) click to toggle source

    # File lib/soap/generator.rb, line 227
    def self.assign_ns!(attrs, ns, namespace, tag = nil)
      tag = ns.assign(namespace, tag)
      if tag == ''
        attr = 'xmlns'
      else
        attr = "xmlns:#{tag}"
      end
      attrs[attr] = namespace
    end

new(opt = {}) click to toggle source

    # File lib/soap/generator.rb, line 36
    def initialize(opt = {})
      @reftarget = nil
      @handlers = {}
      @charset = opt[:charset] || XSD::Charset.xml_encoding_label
      @default_encodingstyle = opt[:default_encodingstyle] || EncodingNamespace
      @generate_explicit_type =
        opt.key?(:generate_explicit_type) ? opt[:generate_explicit_type] : true
      @use_default_namespace = opt[:use_default_namespace]
      @attributeformdefault = opt[:attributeformdefault]
      @use_numeric_character_reference = opt[:use_numeric_character_reference]
      @indentstr = opt[:no_indent] ? '' : '  '
      @buf = @indent = @curr = nil
      @default_ns = opt[:default_ns]
      @default_ns_tag = opt[:default_ns_tag]
    end

### Public Instance Methods

add_reftarget(name, node) click to toggle source

    # File lib/soap/generator.rb, line 119
    def add_reftarget(name, node)
      unless @reftarget
        raise FormatEncodeError.new("Reftarget is not defined.")
      end
      @reftarget.add(name, node)
    end

element_local?(element) click to toggle source

    # File lib/soap/generator.rb, line 213
    def element_local?(element)
      element.elename.namespace.nil?
    end

encode_child(ns, child, parent) click to toggle source

    # File lib/soap/generator.rb, line 126
    def encode_child(ns, child, parent)
      indent_backup, @indent = @indent, @indent + @indentstr
      encode_data(ns.clone_ns, child, parent)
      @indent = indent_backup
    end

encode_data(ns, obj, parent) click to toggle source

    # File lib/soap/generator.rb, line 84
    def encode_data(ns, obj, parent)
      if obj.respond_to?(:to_xmlpart)
        formatted = trim_eol(obj.to_xmlpart)
        formatted = trim_indent(formatted)
        formatted = formatted.gsub(/^/, @indent).sub(/\n+\z/, '')
        @buf << "\n#{formatted}"
        return
      elsif obj.is_a?(SOAPEnvelopeElement)
        encode_element(ns, obj, parent)
        return
      end
      if @reftarget && !obj.precedents.empty?
        add_reftarget(obj.elename.name, obj)
        ref = SOAPReference.new(obj)
        ref.elename = ref.elename.dup_name(obj.elename.name)
        obj.precedents.clear      # Avoid cyclic delay.
        obj.encodingstyle = parent.encodingstyle
        # SOAPReference is encoded here.
        obj = ref
      end
      encodingstyle = obj.encodingstyle
      # Children's encodingstyle is derived from its parent.
      encodingstyle ||= parent.encodingstyle if parent
      obj.encodingstyle = encodingstyle
      handler = find_handler(encodingstyle || @default_encodingstyle)
      unless handler
        raise FormatEncodeError.new("Unknown encodingStyle: #{ encodingstyle }.")
      end
      if !obj.elename.name
        raise FormatEncodeError.new("Element name not defined: #{ obj }.")
      end
      handler.encode_data(self, ns, obj, parent)
      handler.encode_data_end(self, ns, obj, parent)
    end

encode_element(ns, obj, parent) click to toggle source

    # File lib/soap/generator.rb, line 132
    def encode_element(ns, obj, parent)
      attrs = obj.extraattr
      if obj.is_a?(SOAPBody)
        @reftarget = obj
        obj.encode(self, ns, attrs) do |child|
          indent_backup, @indent = @indent, @indent + @indentstr
          encode_data(ns.clone_ns, child, obj)
          @indent = indent_backup
        end
        @reftarget = nil
      else
        if obj.is_a?(SOAPEnvelope)
          Generator.assign_ns(attrs, ns, XSD::InstanceNamespace)
          Generator.assign_ns(attrs, ns, XSD::Namespace)
        end
        obj.encode(self, ns, attrs) do |child|
          indent_backup, @indent = @indent, @indent + @indentstr
          encode_data(ns.clone_ns, child, obj)
          @indent = indent_backup
        end
      end
    end

encode_name(ns, data, attrs) click to toggle source

    # File lib/soap/generator.rb, line 155
    def encode_name(ns, data, attrs)
      if element_local?(data)
        data.elename.name
      else
        if @use_default_namespace
          Generator.assign_ns(attrs, ns, data.elename.namespace, '')
        else
          Generator.assign_ns(attrs, ns, data.elename.namespace)
        end
        ns.name(data.elename)
      end
    end

encode_name_end(ns, data) click to toggle source

    # File lib/soap/generator.rb, line 168
    def encode_name_end(ns, data)
      if element_local?(data)
        data.elename.name
      else
        ns.name(data.elename)
      end
    end

encode_rawstring(str) click to toggle source

    # File lib/soap/generator.rb, line 205
    def encode_rawstring(str)
      @buf << str
    end

encode_string(str) click to toggle source

    # File lib/soap/generator.rb, line 209
    def encode_string(str)
      @buf << get_encoded(str)
    end

encode_tag(elename, attrs = nil) click to toggle source

    # File lib/soap/generator.rb, line 176
    def encode_tag(elename, attrs = nil)
      if attrs.nil? or attrs.empty?
        @buf << "\n#{ @indent }<#{ elename }>"
        return
      end
      ary = []
      attrs.each do |key, value|
        ary << %[#{ key }="#{ get_encoded(value.to_s) }"]
      end
      case ary.size
      when 0
        @buf << "\n#{ @indent }<#{ elename }>"
      when 1
        @buf << %[\n#{ @indent }<#{ elename } #{ ary[0] }>]
      else
        @buf << "\n#{ @indent }<#{ elename } " <<
          ary.join("\n#{ @indent }#{ @indentstr * 2 }") <<
          '>'
      end
    end

encode_tag_end(elename, cr = nil) click to toggle source

    # File lib/soap/generator.rb, line 197
    def encode_tag_end(elename, cr = nil)
      if cr
        @buf << "\n#{ @indent }</#{ elename }>"
      else
        @buf << "</#{ elename }>"
      end
    end

generate(obj, io = nil) click to toggle source

    # File lib/soap/generator.rb, line 52
    def generate(obj, io = nil)
      @buf = io || ''
      @indent = ''
      @encode_char_regexp = get_encode_char_regexp()

      prologue
      @handlers.each do |uri, handler|
        handler.encode_prologue
      end

      ns = SOAP::NS.new
      if @default_ns
        @default_ns.each_ns do |default_ns, default_tag|
          Generator.assign_ns(obj.extraattr, ns, default_ns, default_tag)
        end
      end
      if @default_ns_tag
        @default_ns_tag.each_ns do |default_ns, default_tag|
          ns.known_tag[default_ns] = default_tag
        end
      end
      @buf << xmldecl
      encode_data(ns, obj, nil)

      @handlers.each do |uri, handler|
        handler.encode_epilogue
      end
      epilogue

      @buf
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.