Grouping related behaviour in one class
Related behaviour for several classes can be grouped together in the Visitor class. The behaviour can easily be changed by changing the code in one class, instead of having to change all the visited classes.
Cleaning up the data classes implementations
If classes holding data also implement several different output formats or other (otherwise unrelated) behaviour, they tend to get bloated.
Adding behaviour is easy
Swapping out the visitor class allows easy alterations of behaviour. So on a list of Persons, one Visitor may print address stamps, while another one prints out a phone number list.
Changes in the visited classes are expensive
If one of the visited classes changes (or is added), all visitors must be updated to reflect this change. This may be rather expensive if classes change often.
The visited classes must expose all data required
Visitors may need to use the internals of a class. This may result in fidelling with a objects internals, or a bloated interface in the visited class.
The Iterator decides which object to visit next.
Code generation in SOAP::WSDL means generating various artefacts:
All these behaviours could well be (and have historically been) implemented in the classes holding the WSDL data. This made these classes rather bloated, and made it hard to change behaviour (like supporting SOAP Headers, supporting atomic types, and other features which were missing from early versions of SOAP::WSDL).
For every WSDL definition, a Typemap is created. The Typemap is used later as an aid in parsing the SOAP XML messages.
o Type Classes
For every type defined in the WSDLs schema, a Type Class is generated.
These classes are instantiated later as a result of parsing SOAP XML messages.
o Interface Classes
For every service, a interface class is generated. This class is later used by programmers accessing the service
Both Type Classes and Interface Classes include documentation. Additional documentation may be generated as a hint for programmers, or later for mimicing .NETs .asmx example pages.
Implementing these behaviours in Visitor classes eases adding new behaviours, and reducing the incompletenesses still inherent in SOAP::WSDLs WSDL and XML schema implementation.
SOAP::WSDL::Base defines an accept method which expects a Visitor as only parameter.
The method visit_Foo_Bar is called on the visitor, with the self object as parameter.
The actual method name is constructed this way:
o SOAP::WSDL is stripped from the class name o All remaining :: s are replaced by _
When visiting a SOAP::WSDL::XSD::ComplexType object, the method visit_XSD_ComplexType is called on the visitor.
SOAP::WSDL eases writing your own visitor. This might be required if you need some special output format from a WSDL file or want to feed your own serializer/deserializer pair with custom configuration data. Or maybe you want to generate C# code from it...
In your Visitor, you must implement visit_Foo methods for all classes you wish to visit.
o visit_Definitions o visit_Binding o visit_Message o visit_Operation o visit_OpMessage o visit_Part o visit_Port o visit_PortType o visit_Service o visit_SoapOperation o visit_Types o visit_XSD_Schema o visit_XSD_ComplexType o visit_XSD_Element o visit_XSD_SimpleType
The SOAP::WSDL::Generator::Visitor implementations include part of their own Iterator (which means they know how to find the next objects to visit). You may or may not choose to implement a separate Iterator.
Letting a visitor implementing its own Iterator visit a WSDL definition is as easy as writing something like this:
my $visitor = MyVisitor->new(); my $parser = SOAP::WSDL::Expat::WSDLParser->new(); my $definitions = $parser->parse_file(my.wsdl): $definitions->_accept( $visitor );
Erich Gamma, Richard Helm, Ralph E. Johnson, John Vlissides, (1995): Design Patterns. Elements of Reusable Object-Oriented Software. Addison-Wesley Longman, Amsterdam.
Copyright 2004-2008 Martin Kutter.
This file is part of SOAP-WSDL. You may distribute/modify it under the same terms as perl itself
Martin Kutter <martin.kutter fen-net.de>
|perl v5.20.3||SOAP::WSDL::GENERATOR::VISITOR (3)||2015-04-02|