ALDSP Control Dynamic Mediator API Code Reference This page last changed on Jun 23, 2008. .stickable, h1, h2, h3, h4, h5 false true Show Sticky notes Hide Sticky notes sticky_configuringtheldapserverinformation sticky_associatingcustomconditionallogicwithfunctions sticky_aldspapplicationdevelopmentbestpractices sticky_configuringthesampleapplicationtousetheembeddedldapserver sticky_acloserlook Save Cancel edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation ## ALDSP Control Dynamic Mediator API Code Reference This topic the advanced sample project that uses the Dynamic Mediator API to invoke data service operations from ALDSP Controls using a variety of argument and return types.
| Source: `DSPClientSamplesControlDynamic/Java Resources/src/dspControl/DspControlController.java`
#### Topic Map ALDSP Control Dynamic Mediator API Code Reference Using a Complex Argument Using a Complex Argument List Using a Complex Argument with Create-Read-Update-Delete Operations Returning a Simple Element Including Auditing Related Topics 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 creates a query to call the `getServiceCase` operation, using the complex argument, to retrieve the CASE information. ##### Calling an Operation Using a Complex Argument
    commonj.sdo.DataObject profileService =(commonj.sdo.DataObject)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");

    com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
    extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,profileService), true);
    StringBuffer query=new StringBuffer();
    query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
    query.append("declare namespace retailer='urn:retailer';\n");
    query.append("declare variable $profile as element(retailer:PROFILE) external;\n");
    query.append("tns:getServiceCase($profile)");
    Object[] cases=DSPControlFile.executeQuery(query.toString(), extVariables);
### 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 creates a query to call the `getServiceCase` operation, using the argument consisting of the list of complex objects, to retrieve the CASE information. ##### Invoking an Operation Using a List of Complex Arguments
    commonj.sdo.DataObject profileService =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICES");
    com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES");
    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");

    profile = profileService.createDataObject("PROFILE");
    profile.set("CustomerID", "CUSTOMER6");
    profile.set("FirstName", "dummyFirstName");
    profile.set("LastName", "dummyLastName");
    profile.set("CustomerSince", "2001-01-01");
    profile.set("EmailAddress", "dummyEmailAddress");
    profile.set("TelephoneNumber", "8885551212");

    com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
    extVariables.setElement(new javax.xml.namespace.QName("profiles"), dataObject2String(xh,profileService), true);
    StringBuffer query=new StringBuffer();
    query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
    query.append("declare namespace retailer='urn:retailer';\n");
    query.append("declare variable $profiles as element(retailer:PROFILES) external;\n");
    query.append("tns:getServiceCases($profiles)");
    Object[] cases=DSPControlFile.executeQuery(query.toString(), extVariables);
### 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 `set` method. The sample then creates a query to call the `getCustomerByCustID` operation using a complex argument and checks whether the customer information is already stored. If not, the sample creates a query to call the `createPROFILE` operation to create the customer profile. If a record already exists for the customer, the sample creates a query to call the `updatePROFILE` operation to store the new information in the `profileService` object. If an existing record does not match, the sample creates a query to call the `deletePROFILE` operation to remove the customer profile. ##### Invoking Multiple Operations Using Complex Arguments
    retailer.PROFILE_SERVICE[] profileServices = new retailer.PROFILE_SERVICE[2];
    commonj.sdo.DataObject profileService1 =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE");
    com.bea.dsp.sdo.SDOUtil.setElementName(profileService1, "urn:retailer", "PROFILE");
    profileServices[0]=(retailer.PROFILE_SERVICE)profileService1;

    commonj.sdo.DataObject profile = profileService1.createDataObject("PROFILE");
    profile.set("CustomerID", "CUSTOMER44");
    profile.set("FirstName", "dummyFirstName");
    profile.set("LastName", "dummyLastName44");
    profile.set("CustomerSince", "2001-01-01");
    profile.set("EmailAddress", "dummyEmailAddress");
    profile.set("TelephoneNumber", "8885551212");

    commonj.sdo.DataObject profileService2 =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE");
    com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE");

    profileServices[1]=(retailer.PROFILE_SERVICE)profileService2;

    profile = profileService2.createDataObject("PROFILE");
    profile.set("CustomerID", "CUSTOMER55");
    profile.set("FirstName", "dummyFirstName");
    profile.set("LastName", "dummyLastName55");
    profile.set("CustomerSince", "2001-01-01");
    profile.set("EmailAddress", "dummyEmailAddress");
    profile.set("TelephoneNumber", "8885551212");

    StringBuffer query=new StringBuffer();
    query.append("declare variable $customerId as xs:string external;\n");
    query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
    query.append("tns:getCustomerByCustID($customerId)");
    com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
    extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER44", true);
    Object[] returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables );

    outputString="";
    if(returnedProfileServices.length==0) {
       outputString=outputString +"ADDING: \n";

       /*
       extVariables=new com.bea.ld.ExternalVariables();
       extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,profileServices), true);
       query=new StringBuffer();
       query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
       query.append("declare namespace retailer='urn:retailer';\n");
       query.append("declare variable $profile as element(retailer:PROFILE)* external;\n");
       query.append("tns:createPROFILE($profile)");
       returnedProfileServices=DSPControlFile.executeProcedure(query.toString(), extVariables);
       */

       returnedProfileServices=DSPControlFile.createPROFILE(profileServices);
       outputString=outputString + dataObjectsToString(returnedProfileServices);
    } else {
       commonj.sdo.DataObject dObj= (commonj.sdo.DataObject)returnedProfileServices[0];
       if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))){
          outputString=outputString +"UPDATING: \n";
          outputString=outputString + dataObjectsToString(profileServices);
          com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
          dObj.set("PROFILE/LastName", "Smith");
          DSPControlFile.updatePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj});

          /*
          extVariables=new com.bea.ld.ExternalVariables();
          extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,dObj), true);
          query=new StringBuffer();
          query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
          query.append("declare namespace retailer='urn:retailer';\n");
          query.append("declare variable $profile as changed-element(retailer:PROFILE)* external;\n");
          query.append("tns:updatePROFILE($profile)");
          DSPControlFile.executeProcedure(query.toString(), extVariables);
          */

       } else {
          outputString=outputString +"DELETING: \n";
          outputString=outputString + dataObjectsToString(returnedProfileServices);
          DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj});

          /*
          extVariables=new com.bea.ld.ExternalVariables();
          extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,returnedProfileServices), true);
          query=new StringBuffer();
          query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
          query.append("declare namespace retailer='urn:retailer';\n");
          query.append("declare variable $profile as element(retailer:PROFILE)* external;\n");
          query.append("tns:deletePROFILE($profile)");
          DSPControlFile.executeProcedure(query.toString(), extVariables);
          */

          query=new StringBuffer();
          query.append("declare variable $customerId as xs:string external;\n");
          query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
          query.append("tns:getCustomerByCustID($customerId)");
          extVariables=new com.bea.ld.ExternalVariables();
          extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER55", true);
          returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables );

          if(returnedProfileServices.length>0) {
             dObj= (commonj.sdo.DataObject)returnedProfileServices[0];
             outputString=outputString + dataObjectsToString(returnedProfileServices);
             DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj});

             /*
             extVariables=new com.bea.ld.ExternalVariables();
             extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,returnedProfileServices), true);
             query=new StringBuffer();
             query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
             query.append("declare namespace retailer='urn:retailer';\n");
             query.append("declare variable $profile as element(retailer:PROFILE)* external;\n");
             query.append("tns:deletePROFILE($profile)");
             DSPControlFile.executeProcedure(query.toString(), extVariables);
             */
          }
       }
    }
### 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 creating a query to call the `getOrderCount` and `getOrderCounts` operations and assigning the results to variables of type `java.math.BigInteger`. ##### Invoking an Operation that Returns a Simple Type
    outputString="";
    StringBuffer query=new StringBuffer();
    query.append("declare variable $customerId as xs:string external;\n");
    query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
    query.append("tns:getOrderCount($customerId)");
    com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
    extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true);
    Object[] returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables);
    outputString=outputString + dataObjectsToString(new Object[]{returnedProfileServices});

    query=new StringBuffer();
    query.append("declare variable $customerId as xs:string external;\n");
    query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
    query.append("tns:getOrderCounts($customerId)");
    extVariables=new com.bea.ld.ExternalVariables();
    extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true);
    returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables );
    outputString=outputString + dataObjectsToString(returnedProfileServices);
### 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 operations. The example then retrieves the audit records and iterates through the results to output for display. ##### 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);

    StringBuffer query=new StringBuffer();
    query.append("declare variable $customerId as xs:string external;\n");
    query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
    query.append("tns:getCustomerByCustID($customerId)");
    com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
    extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true);
    Object[] o=DSPControlFile.executeQuery(query.toString(), extVariables, reqConfig );
    outputString=dataObjectsToString(o);
    /** Dump out the audit information **/
    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();
             outputString=outputString + "Audit Information: " + key + " = " + propMap.get(key)+"\n";
          }
       }
    }
## Related Topics ##### Concepts Advanced API Samples - Mediator, Web Services, and DSP Controls Understanding the Advanced Static Mediator API Sample ##### How Tos Setting Up the Advanced API Sample Projects Running the Mediator API Sample Projects ##### Reference Static Mediator API Code Reference Dynamic Mediator API Code Reference ALDSP Control Static Mediator API Code Reference

Document generated by Confluence on Nov 26, 2008 13:06