import java.util.Hashtable;
import javax.naming.Context;
import com.oracle.bpel.client.IInstanceHandle;
import com.oracle.bpel.client.Locator;
import com.oracle.bpel.client.ServerException;
import com.oracle.bpel.client.delivery.IDeliveryService;
import com.oracle.bpel.client.util.WhereCondition;
//Additional Imports
import org.w3c.dom.*;
import com.collaxa.xml.XMLHelper;
import com.collaxa.cube.engine.test.*;
import com.collaxa.cube.xml.dom.DOMUtil;
public class AuditRetreiver {
public AuditRetreiver() {
}
public static void main(String[] args) {
Locator locator;
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.PROVIDER_URL,
"ormi://localhost:12401/orabpel");
env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin");
env.put(Context.SECURITY_CREDENTIALS, "welcome1");
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.evermind.server.rmi.RMIInitialContextFactory");
locator = new Locator("default", env );
locator.lookupService(IDeliveryService.SERVICE_NAME);
long cikey = 140001;
WhereCondition whereCikey = new WhereCondition("cikey = ?");
whereCikey.setLong(1, cikey);
IInstanceHandle[] instanceHandles = locator
.listInstances(whereCikey);
for (int i = 0; i < instanceHandles.length; i++) {
IInstanceHandle iInstanceHandle = instanceHandles[i];
//Get the complete audit trail
Element auditTrail = XMLHelper.parse(iInstanceHandle.getAuditTrail());
//In case we want to print the audit trail
System.out.println("Audit Trail : \n"+DOMUtil.toXML(auditTrail).toString());
//Get the list of <details> element from <audit-trail>
NodeList details = auditTrail.getElementsByTagName("details");
//Get the first <details> element - this element would
//indicate if reference details are stored in AUDIT_DETAILS
//(e.g) <details id="0" />
Element detailsElement = (Element)details.item(0);
String detailId = detailsElement.getAttribute("id");
//if detailId!=null , get the details stored in AUDIT_DETAILS table
if (detailId!=null && !(detailId.trim().equals("")) )
{
System.out.println("Getting Audit Details from: AUDIT_DETAILS \n "+ iInstanceHandle.getAuditDetails(0));
}
//if detailId==null ,all details stored in AUDIT_TRAIL itself
//proceed with getting the details from AUDIT_TRAIL
else
{
System.out.println("Getting Audit Details from:AUDIT_TRAIL \n"+ BPELTestUtils.getElementText(detailsElement));
}
}
} catch (ServerException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment