/*
* Created on Jan 25, 2006
*
* EMC Documentum Developer Program 2005
*/
package com.documentum.devprog.snippets;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.IDfId;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.client.IDfVirtualDocument;
import com.documentum.fc.client.IDfVirtualDocumentNode;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
public class VirtualDocumentWalkthrough
{
public static void main(String[] args)
{
String username = "dmadmin";
String password = "dmadmin";
String repoName = "devprog53sp1";
String vdocId = "09000001805f0344";
try
{
IDfSessionManager sessMgr = createSessionManager();
addIdentity(sessMgr, username, password, repoName);
printVirtualDocumentTree(sessMgr, repoName, vdocId);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private static void printVirtualDocumentTree(IDfSessionManager sessMgr,
String repo, String vdocId) throws DfException
{
IDfSession sess = null;
try
{
sess = sessMgr.getSession(repo);
IDfId rootId = new DfId(vdocId);
IDfSysObject sObj = (IDfSysObject) sess.getObject(rootId);
// get the sysobject as a virtual document. false implies don't
// get assembly
IDfVirtualDocument vDoc = sObj.asVirtualDocument("CURRENT", false);
IDfVirtualDocumentNode rootNode = vDoc.getRootNode();
printChildren(rootNode, 0);
}
finally
{
if (sess != null)
{
sessMgr.release(sess);
}
}
}
private static void printChildren(IDfVirtualDocumentNode node, int depth)
throws DfException
{
for (int j = 0; j < (depth + 1); j++)
{
System.out.print("-");
}
IDfSysObject sobj = node.getSelectedObject();
System.out.println(sobj.getObjectId() + ":" + sobj.getChronicleId()
+ ":" + sobj.getObjectName());
//Get children an recurse
if (node.isVirtualDocument())
{
int childCnt = node.getChildCount();
for (int i = 0; i < childCnt; i++)
{
IDfVirtualDocumentNode childNode = node.getChild(i);
printChildren(childNode, depth + 1);
}
}
}
/**
* Creates a new session manager instance. The session manager does not have
* any identities associated with it.
*
* @return a new session manager object.
* @throws DfException
*/
private static IDfSessionManager createSessionManager() throws DfException
{
IDfClientX clientX = new DfClientX();
IDfClient localClient = clientX.getLocalClient();
IDfSessionManager sessMgr = localClient.newSessionManager();
return sessMgr;
}
/**
* Adds a new identity to the session manager.
*/
private static void addIdentity(IDfSessionManager sm, String username,
String password, String repoName) throws DfException
{
IDfClientX clientX = new DfClientX();
IDfLoginInfo li = clientX.getLoginInfo();
li.setUser(username);
li.setPassword(password);
// check if session manager already has an identity.
// if yes, remove it.
if (sm.hasIdentity(repoName))
{
sm.clearIdentity(repoName);
}
sm.setIdentity(repoName, li);
}
}
|