Code Example Interface PresenceSupplier, Operation: publish and Oracle Specific Unpublish

Parlay X Presence Web Services 8-9 import oracle.sdp.presence.integration.BuddyListManager; import oracle.sdp.presence.integration.BuddyListManagerFactory; import oracle.sdp.presence.integrationimpl.BuddyListManagerImpl;

8.7.1.1 Obtaining the BuddyListManagerFactory

The BuddyListManagerFactory itself follows the singleton pattern, and there is only one instance of a factory per XDMSXDMC combination. That is, when creating a BuddyListManagerFactory, you must supply the XCAP root URL to the XDMS from where documents are downloaded, as well as supplying the URL to the XDM Client Service that is running on the client side; the XDMC Service URL is passed in through the BindingProvider.ENDPOINT_ADDRESS_PROPERTY property. For each such combination of XCAP root URL and XDM Client Service endpoint, there can only exist exactly one BuddyListManagerFactory instance. Therefore it is possible to create different factories pointing to the different XDMSXDMC Service combinations. Example 8–1 Obtaining an instance of the BuddyListManagerFactory Create the URI pointing to the XDMS. URI xcapRoot = new URIhttp:localhost:8001services; Location of where the XDM Client webservice is. String wsUrl = http:localhost:8001XdmClientServiceservicesXdmClient; String sWsSecurityPolicy = new String[]{oraclewss11_saml_token_with_message_ protection_client_policy}; MapString, Object params = new HashMapString,Object; params.putBindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsUrl; params.putBindingProvider.USERNAME_PROPERTY, alice; params.putParlayXConstants.POLICIES, sWsSecurityPolicy; Obtain the instance to the factory BuddyListManagerFactory factory = BuddyListManagerFactory.getInstancexcapRoot, params; Example 8–1 shows how to obtain a reference to a factory pointing to the XCAP root of localhost:8001 services. Every operation performed on this factory is in the context of this particular XCAP root. Hence, when creating a BuddyListManager for a particular user, that BuddyListManagers XCAP root is the one of the factory through which it was created.

8.7.1.2 Creating a BuddyListManager

It is important to realize that a BuddyListManager BLM is acting on behalf of a particular user. Therefore, if a BLM is created for user Alice, all operations performed on that particular BLM are on behalf of Alice and manipulate her documents. Example 8–2 shows how to create a BLM for Alice through the factory created in the previous section. Example 8–2 Obtaining a BuddyListManager for the user Alice URI user = new URIsip:aliceexample.com; MapString, Object params = new HashMapString,Object; params.putXDMClientFactory.PROP_ASSERTED_IDENTITY, assertedId; BuddyListManager manager = factory.createBuddyListManageruser, params; Example 8–2 shows how to create a BLM for the user Alice with SIP address of sip:aliceexample.com. If manipulation of the buddy list and presence rules document of another user is required, then a separate BLM must be created with the appropriate SIP address. 8-10 Developers Guide

8.7.1.3 Adding a Buddy to a Buddy List and Retrieving the List

Adding a buddy to a buddy list is done by first creating a buddy, setting the information needed on that buddy and then using the BLM to add it to the buddy list. Example 8–3 shows how to use the BLM representing Alice to add Bob as a new buddy of Alice and then getting the updated list back. Example 8–3 Adding a New Buddy to the Buddy List of Alice URI uri = new URIsip:bobexample.com; Buddy bob = manager.createBuddyuri; Optionally, setting additional information. manager.setDisplaynameBobby; VCard vcard = bob.getVCard; vcard.setCitySan Francisco; vcard.setCountryUSA; very important to set the VCard back on the buddy again bob.setVCardvcard; Update the buddy info using the BLM manager.updateBuddybob; Getting the updated buddy list ListBuddy buddies = manager.getBuddies; Example 8–3 shows how to create a new Buddy, Bob, and how that buddy is added to Alices buddy list by using the BLM representing Alice. To add more information about the user Bob, such as the address and other information, access Bobs Vcard information and then set the appropriate properties.

8.7.1.4 Removing a Buddy from a Buddy List

Removing a buddy is very similar to adding a buddy. Use the method removeBuddy and pass in the buddy that is to be removed. If there are many buddies to remove, use the removeBuddies method and pass in the list of buddies to remove. Example 8–4 shows how Bob is removed from Alices buddy list. Example 8–4 Removing a Buddy URI uri = new URIsip:bobexample.com; Buddy bob = manager.createBuddyuri; manager.removeBuddybob;

8.7.1.5 Manipulating your presence rules document

To allow a watcher to view the presence status, use the method allowWatcherString watcher to add the watcher to the allow list. Use blockWatcherString watcher to block someone from viewing your presence status. Example 8–5 Allowing or blocking watchers manager.allowWatchersip:bobexample.com; manager.blockWatchersip:carolexample.com; Note: Since the method getVCard is actually returning a clone of the VCard, the method setVCard must be called on the buddy again in order for the information to be updated.