4.2. Implementing the WS-Resource factory pattern in pyGridWare

Implementing this design pattern is very similar to the example seen in the previous chapter, with two main differences, highlighted in Figure 4-2 (compare with )

Figure 4-2. Relationships between the Factory Service, the Instance Service, the Resource Home, and the Resource

Let's start by examining three Python modules, generated from the WSDL presented in the last section after removing the comments around the relevant create sections, containing four classes.

Remove the comments in the WSDL by removing all UNCOMMENT sections (or get it from the next section), clean regenerate and install. The crucial parts of the WSDL you just uncommented are explained below.


<xsd:element name="Value" type="xsd:int"/>(1)
<xsd:element name="LastOp" type="xsd:string"/>(2)
<xsd:element name="MathResourceProperties">(3)
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element ref="tns:Value"/>
            <xsd:element ref="tns:LastOp"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>


<portType name="MathPortType"
    wsrp:ResourceProperties="tns:MathResourceProperties">(4)
    ...
    ...
    <operation name="createResource">(5)
            <input message="tns:CreateInputMessage"/>
            <output message="tns:CreateOutputMessage"/>
    </operation>
    
(1)
Value: Resource Property representing the integer value of the service.
(2)
LastOp: Resource Property representing the last operation.
(3)
MathResourceProperties: Resource Property Declaration containing element references to the two Resource Properties.
(4)
Set the wsrp:ResourceProperties attribute to the GED MathResourceProperties. Now the MathPortType is declaring its resource properties.
(5)
New factory method for creating instance services.