Content starts here Dynamic Mediator API Code Reference
This page last changed on Jun 23, 2008.

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

Dynamic Mediator API Code Reference

This topic describes the advanced sample project that uses the Dynamic Mediator API to call ALDSP data service operations from client applications using a variety of argument and return types.

You can find the Java source code for this sample dataspace project in the DSPClientSamplesDynamic1/JavaResources/client.java_and_ws.dynamic folder.

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Using a Complex Argument

You can invoke ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using the set method.

The sample then invokes the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientComplexArg.java

Invoking an Operation Using a Complex Argument
commonj.sdo.DataObject profileService = factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER4");

profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getServiceCase", new Object[] { profileService });

Using a Complex Argument List

You can invoke ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using the set method.

The sample then invokes the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientComplexArgList.java

Invoking an Operation Using a List of Complex Arguments
profileServices = factory.create("urn:retailer", "PROFILE_SERVICES");

com.bea.dsp.sdo.SDOUtil.setElementName(profileServices, "urn:retailer", "PROFILES");
profile = profileServices.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER4");
profile.set("FirstName", "dummyFirstName4");
profile.set("LastName", "dummyLastName4");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

profile = profileServices.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER6");
profile.set("FirstName", "dummyFirstName6");
profile.set("LastName", "dummyLastName6");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getServiceCases", new Object[] { profileServices });

Using a Complex Argument with Create-Read-Update-Delete Operations

You can invoke multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using the setElementName method.

The sample then invokes the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile.

If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientComplexArgs_andCRUD.java

Invoking Multiple Operations Using Complex Arguments
profileService = factory.create("urn:retailer", "PROFILE_SERVICE");
profileServices.add(profileService);
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
profile1 = profileService.createDataObject("PROFILE");
profile1.set("CustomerID", "CUSTOMER44");
profile1.set("FirstName", "dummyFirstName44");
profile1.set("LastName", "dummyLastName44");
profile1.set("CustomerSince", "2001-01-01");
profile1.set("EmailAddress", "dummyEmailAddress");
profile1.set("TelephoneNumber", "8885551212");

profileService = factory.create("urn:retailer", "PROFILE_SERVICE");
profileServices.add(profileService);
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
profile2 = profileService.createDataObject("PROFILE");
profile2.set("CustomerID", "CUSTOMER55");
profile2.set("FirstName", "dummyFirstName55");
profile2.set("LastName", "dummyLastName55");
profile2.set("CustomerSince", "2001-01-01");
profile2.set("EmailAddress", "dummyEmailAddress");
profile2.set("TelephoneNumber", "8885551212");

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByCustID", new Object[] { "CUSTOMER44" });

if(!dasResult.hasNext()) {
   out("ADDING: ");

   dasResult = (com.bea.dsp.das.DASResult) das.invoke("createPROFILE", new Object[] { profileServices.toArray() });

   while( dasResult.hasNext()) {
      out("DataObject : " + dataObjectToString(xh,(commonj.sdo.DataObject)dasResult.next()));
   }

} else {
   commonj.sdo.DataObject dObj=(commonj.sdo.DataObject)dasResult.next();
   if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))) {
      out("UPDATING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));
      com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
      dObj.set("PROFILE/LastName", "Smith");
      dasResult = (com.bea.dsp.das.DASResult) das.invoke("updatePROFILE", new Object[] { dObj });
   } else {
      out("DELETING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));
      dasResult = (com.bea.dsp.das.DASResult) das.invoke("deletePROFILE", new Object[] { dObj });
      dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByCustID", new Object[] { "CUSTOMER55" });

      if(dasResult.hasNext()) {
         dObj=(commonj.sdo.DataObject)dasResult.next();
         out("DataObject : " + dataObjectToString(xh,dObj));
         dasResult = (com.bea.dsp.das.DASResult) das.invoke("deletePROFILE", new Object[] { dObj });
      }
   }
}

Returning a Simple Element

You can invoke ALDSP data service operations that return simple types. The example in this section determines the number of orders by invoking the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientSimpleReturn.java

Invoking an Operation that Returns a Simple Type
dasResult = (com.bea.dsp.das.DASResult) das.invoke("getOrderCount", new Object[] {"CUSTOMER4"});

while( dasResult.hasNext()) {
   java.math.BigInteger count = (java.math.BigInteger) dasResult.next();
   out("DataObject : " + count);
}

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getOrderCounts", new Object[] {"CUSTOMER4"});

while( dasResult.hasNext()) {
   java.math.BigInteger count = (java.math.BigInteger) dasResult.next();
   out("DataObject : " + count);
}

Including Auditing

You can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT).

After enabling audit, the example includes the instance of the RequestConfig object as an argument when invoking methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientWithAudit.java

Auditing Operations
com.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig();
reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes);

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByLoginID", new Object[] { "Steve" }, reqConfig);

com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit();
if (dsAudit != null) {
   List l = dsAudit.getAllRecords();
   for (Iterator it = l.iterator(); it.hasNext();) {
      com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next();
      Map propMap = auditRec.getAuditProperties();
      for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) {
         String key = (String) pit.next();
         out("Audit Information: " + key + " = " + propMap.get(key));
      }
   }
}

while( dasResult.hasNext()) {
   out("DataObject : " + dataObjectToString(xh,(commonj.sdo.DataObject)dasResult.next()));
}

Using Filters

You can filter the results of calls to data service operations using the ALDSP RequestConfig. The example in this section creates an instance of the RequestConfig object and then defines a filter based on the customer ID.

After defining the filter, the example sets the filter on the RequestConfig object and passes the instance of RequestConfig as an argument when invoking the method corresponding to data service operation.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientWithAudit.java

Filtering Based on an Identifier
reqConfig = new com.bea.dsp.RequestConfig();
com.bea.ld.filter.FilterXQuery filter=new com.bea.ld.filter.FilterXQuery() ;

filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","$customerID");
com.bea.ld.ExternalVariables externalVariables=new com.bea.ld.ExternalVariables();
externalVariables.setString(new javax.xml.namespace.QName("customerID"), "CUSTOMER5");
filter.setExternalVariables(externalVariables);

/* Or filter with hard-coded value */

// filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","CUSTOMER5");

reqConfig.setFilter(filter);
try {
   dasResult = das.invoke("getProfile", new Object[] {}, reqConfig);
}

Related Topics

Concepts
How Tos
Reference
Document generated by Confluence on Jul 03, 2008 12:11