| |

Lesson 17: Working with serializers

Lesson objective

The objective of this lesson is to learn how to work with serializers and turn any Ruddi data structure to an UDDI-compliant XML stream.

Reference material

Source code of reference: UDDISerializerExample.java

Related lessons

Ruddi uses serializers "behind the scene" in all interactions with an UDDI registry. It is in particular the case in all lessons.

Review of concepts

Ruddi data structures allow the developer to manipulate UDDI notions using objects. Ruddi comes, among other examples, with a BusinessEntity class representing the businessEntity UDDI notion. When interacting with an UDDI registry, Ruddi objects have to be somewhat translated in an UDDI-compliant XML stream. This is the role of Ruddi serializers.

Code snippets

We create an UDDI serializer for a given version of UDDI by invoking the createSerializer(int) factory method on the UDDISerializer class. The following example creates an UDDI 2.0 serializer:

UDDISerializer serializer = UDDISerializer.createSerializer(UDDIConstants.UDDI_V2);

To serialize any UDDI data structure to an output stream, just pass the data structure and the output stream to the serialize(UDDIElement, OutputStream) . For example, the following serializes an UDDI contact to the standard output:

Contact contact = new Contact("John Doe");

EMail email = new EMail("john.doe@somewhere.com");

contact.addEMail(email)

serializer.serialize(contact, System.out);

What gives:

<contact>
<personName>John Doe</personName>
<email>john.doe@somewhere.com</email>
</contact>

 

 

| |

(c) INSPIRE IT, 2003 | Send us your feedback: developers@ruddi.biz