Home > DVM, SOA > Oracle SOA 11G DVM from Java Client

Oracle SOA 11G DVM from Java Client

In this post I have given sample to lookup oracle soa 11g dvm functions from java client.

Domain Value Maps (DVM) enable you to map one vocabulary used in the given domain to another vocabulary used in different domain. For example, one domain may represent a City with a long name (Australia), while another domain may represent a City with a short name (AU). In such cases, you can directly map the values by using domain value maps .

This DVM files can be deployed along with SOA Composite applications or can be deployed into MDS Repository. This DVM is a XML file defined based on Oracle SOA DVM contract.

Here I lookup the values by accessing the DVM file through HTTP protocol from Java Client.Because I have deployed the DVM files along with SOA Composite applications.

Jars Required :
1. fabric-common.jar
2. fabric-runtime.jar
3. mdsrt.jar
4. soa-xpath-exts.jar
5. xbean.jar
6. xml.jar
7. xmlparserv2.jar

DVMLocatorUtil.java :

package com.sample.dvm.client;

import java.io.StringWriter;
import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;

import oracle.fabric.common.dvm.DVM;
import oracle.tip.dvm.entity.DVMRTObject;
import oracle.xml.parser.v2.XMLDocument;

import org.w3c.dom.Document;

public class DVMLocatorUtil {
	
    public DVMRTObject getDVMRTObject(String dvmLoc)
    {
        DVMRTObject obj= null;
        try
        {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            dbf.setNamespaceAware(true);
            Document doc = db.parse(new URL(dvmLoc).openStream());
            
            printXML(doc);
            
            XMLDocument xmlDoc = null;
            xmlDoc = new XMLDocument();
            xmlDoc.appendChild(xmlDoc.importNode(doc.getDocumentElement(), true));
            
            printXML(doc);
            
            DVM dvm = new DVM(xmlDoc, "");
            
            obj = (DVMRTObject)dvm.getParsedDVM();
                if (obj == null) 
                {
                  obj = new DVMRTObject(dvm);
                  dvm.setParsedDVM(obj);
                }
            return obj;    
        }
        catch(Exception e)
        {
            e.printStackTrace();
        } 
        return obj; 
    }
	
	public static void printXML(Document doc) throws Exception
    {
        TransformerFactory tfactory = TransformerFactory.newInstance();
        Transformer xform = tfactory.newTransformer();
        javax.xml.transform.Source src=new DOMSource(doc);
        java.io.StringWriter writer = new StringWriter();
        Result result = new javax.xml.transform.stream.StreamResult(writer);
        xform.transform(src, result);
        System.out.println("payload dvm :"+writer.toString());
    }
}

  

DVMClient.java

package com.sample.dvm.client;

import oracle.tip.dvm.entity.DVMRTObject;

import org.apache.xmlbeans.XmlObject;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class DVMClient {
    
public static String lookupValue(String dvmLoc, String srcColumnName, String srcValue, String tgtColumnName, String defaultValue) throws Exception

{
        DVMLocatorUtil util = new DVMLocatorUtil();
        DVMRTObject rtObject= util.getDVMRTObject(dvmLoc);

        String lookedUpValue = rtObject.getValue(srcColumnName, srcValue, tgtColumnName);
        
        if ((lookedUpValue == null) || (lookedUpValue.trim().length() == 0)) 
        {
            if (defaultValue == null)
            {
              defaultValue = "";
            }
          lookedUpValue = defaultValue;
        }
        
        System.out.println("Lookup value : "+ lookedUpValue);
        
        return lookedUpValue;
        
    }

    public static String lookupValue(String dvmLoc, String srcColumnName, String srcValue, String tgtColumnName, String defaultValue, XmlObject qualObject) throws Exception

    {
            DVMLocatorUtil util = new DVMLocatorUtil();
            DVMRTObject rtObject= util.getDVMRTObject(dvmLoc);
            String qualifiers[]=getQualifiersOrTargetColumns(qualObject);

            if ((qualifiers != null) && (qualifiers.length % 2 > 0)) 
            {
              String[] newQualifiers = new String[qualifiers.length + 1];
              System.arraycopy(qualifiers, 0, newQualifiers, 0, qualifiers.length);
              newQualifiers[(newQualifiers.length - 1)] = "";
              qualifiers = newQualifiers;
            }

            String lookedUpValue = rtObject.getValue(srcColumnName, srcValue, tgtColumnName,qualifiers);
            
            if ((lookedUpValue == null) || (lookedUpValue.trim().length() == 0)) 
            {
                if (defaultValue == null)
                {
                  defaultValue = "";
                }
              lookedUpValue = defaultValue;
            }
            
            System.out.println("Lookup value : "+ lookedUpValue);
            return lookedUpValue;
            
    }
    
    /**
     * This method is to retrieve the complete row values for the requested columns
     * @param dvmLoc
     * @param srcColumnName
     * @param srcValue
     * @param targetColumnNames
     * @return
     * @throws Exception
     */
    public static DocumentFragment lookupValue1M(String dvmLoc, String srcColumnName, String srcValue, XmlObject targetColumnNames) throws Exception

    {
        DVMLocatorUtil util = new DVMLocatorUtil();
        DVMRTObject rtObject = util.getDVMRTObject(dvmLoc);
        String columnNameArray[] = getQualifiersOrTargetColumns(targetColumnNames);
        System.out.println("---- got columns velues to be retrieved ------");
        return  rtObject.getValue(srcColumnName, srcValue, columnNameArray);           
    
    }
    /**
     * This method is to convert qualifier XmlObject to String array
     * @param elementArray
     * @return String[]
     */
    private static String[] getQualifiersOrTargetColumns(XmlObject elementArray)
    {
        org.w3c.dom.Node domNode = elementArray.newDomNode();
        Element domElement =(Element)domNode.getChildNodes().item(0);
        NodeList nodeList =domElement.getChildNodes();
        String args[] = new String[nodeList.getLength()];

        for(int i=0; i<nodeList.getLength(); i++)
        {
            Node childNode = nodeList.item(i);
            System.out.println("Name of Element : "+childNode.getNodeName());
            System.out.println("Value of Element : "+childNode.getFirstChild().getNodeValue());
            args[i]= childNode.getFirstChild().getNodeValue();
        }
        return args;
    } 
    
    public static void main (String args[])
    {
        try 
        {
           /**
            *http://<host>:<managedServerPort>/soa-infra/services/<partition-name>/<compositeProjectName>/<dvm-name>.dvm
            */
           String dvmLoc="http://localhost:8001/soa-infra/services/default/DVM/Country.dvm";
           				  							
           String srcColumnName="CityCode";
           String srcColumnVal="SYD";
           String targetColumnName="CityName";
           String defaultVal="NO DATA FOUND";
           System.out.println(" Sample Table for Lookupvalue  "+
        		   			 "==============================" +
        		   			 "|  CityCode  |  CityName      |" +
        		   			  "==============================" +
        		   			 "|    SYD     |  Sydney        |" +
        		   			 "|    CHN     |  Chennai       |" +
        		   			 "|    BLR     |  Bangalore     |" +
        		   			 "|    MUB     |  Mumbai        |" +
        		   			 "-------------------------------");
           
           /**
            * This call is to lookup single target column value
            */
           String lookupVal=lookupValue(dvmLoc,srcColumnName,srcColumnVal,targetColumnName,defaultVal);
           System.out.println("Response lookupValue :->"+lookupVal);
           
           System.out.println("------ Sample Table for Lookupvalue by Qualifiers  -----  "+
		   			 "=========================================" +
		   			 " Country   |  CityCode  |  CityName      |" +
		   			 "(Qualifier)|                             |"+
		   			 "=========================================" +
		   			 "   AU      |    SYD     |  Sydney        |" +
		   			 "   IND     |    CHN     |  Chennai       |" +
		   			 "   IND     |    BLR     |  Bangalore     |" +
		   			 "   IND     |    MUB     |  Mumbai        |" +
		   			 "   AU      |    BLR     |  Banglore      |  " +
		   			 "-----------------------------------------");
           
           XmlObject targetCol =XmlObject.Factory.parse("<qualifiers><qualifierName>Country</qualifierName><qualifierValue>IND</qualifierValue></qualifiers>");

           /**
            * This call is to lookup single target column value by qualifier
            */
           String lookupValbyQualifier=lookupValue(dvmLoc, srcColumnName, srcColumnVal, targetColumnName, defaultVal, targetCol);
           System.out.println("Response lookupValue by Qualifiers :-->"+lookupValbyQualifier);
           
           XmlObject targetCol41M =XmlObject.Factory.parse("<qualifiers><column>Country</column></qualifiers>");
           /**
            * This call is to lookup multiple columns in the same record
            */
           DocumentFragment lookupVal1M=lookupValue1M(dvmLoc,srcColumnName,srcColumnVal,targetCol41M);
           
           System.out.println("Response lookupValue1M :->"+lookupVal1M.getNodeValue());
           
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: