gpt4 book ai didi

java - 如何将存储库名称作为 java 数组传递并在 documentum 代码中迭代它?

转载 作者:太空宇宙 更新时间:2023-11-04 06:46:41 27 4
gpt4 key购买 nike

我有下面的代码来检测一个文档文档库(test1)的状态,以便检查它是否已启动并正在运行。现在我想更改下面的代码来检查同一内容服务器中另外 2 个名为 test2,test3 的存储库的状态。谁能建议我对下面的代码进行更改以实现此目的?

我需要将 docbaseName 名称的这些值作为数组传递,但我不知道如何执行此操作并迭代它以检查三个 docbaseName 中每一个的状态。目前,我只对一个 docbaseName 进行操作,我尝试了以下方法:static String[] docbaseName = {"test1","test2","test3"}; 但它不起作用。任何人都可以建议我需要在这里进行的更改吗?任何示例代码都会有所帮助!

import com.documentum.fc.common.*;
import com.documentum.fc.client.*;
public class DocumentumRepoStatus
{
static IDfSession session;
static final String osFileSeparator = System.getProperty("file.separator");
static String docbaseName = "test1";
static String userName = "user";
static String passWd = "test123";

static void parseArgs( String args[] ) // these are the command line args
{
final int MUST_HAVE_FLAGS = 1;
int i;

if ( args.length < (MUST_HAVE_FLAGS + 1) ) {
System.out.println("Not enough arguments.");

}
else {

for (i=0; i < args.length; i++)
{
if ( ! args[i].startsWith("-") ) {
System.out.println("Error parsing argument: " + args[i]);
System.out.println("Expecting a flag parameter starting with dash ('-')");

}
if ( args[i].equalsIgnoreCase("-docbase_name") ) {
i++;
docbaseName = args[i];
}
if ( args[i].equalsIgnoreCase("-user_name") ) {
i++;
userName = args[i];
}
if ( args[i].equalsIgnoreCase("-password") ) {
i++;
passWd = args[i];
}

} // end of for loop
} // end if if/else

if (docbaseName.length() == 0 ) {
System.out.println("Missing required argument -docbase_name.");

}
// If the user_name argument is not passed in, then trusted host for the Documentum login
// is assumed (login as the OS user). DFC, however requires a user name, so we will
// retrieve the username of the current user using the Java Standard System properties.
//
if (userName.length() == 0 ) {
userName = System.getProperty("user.name");

}
}


static void connectToDocbase()
{
IDfLoginInfo li = new DfLoginInfo();
li.setUser( userName );
li.setPassword( passWd );
li.setDomain( "" );
try
{
IDfClient dfc = DfClient.getLocalClient();
session = dfc.newSession(docbaseName, li );
System.out.println("Successful connection to Docbase " + docbaseName);
}
catch (DfException e)
{
System.out.println("Unable to connect to docbase: " + e.toString() );
System.exit( -1 );
}
}

static void getSessionInfo()
{
try
{
System.out.println("");
System.out.println(" DM Session Properties: " );
System.out.println(" DM Server Version : " + session.getServerVersion() );
System.out.println(" DM Session ID : " + session.getSessionId());
System.out.println(" DM Docbase ID : " + session.getDocbaseId());
System.out.println(" DFC Version : " + DfClient.getDFCVersion() );
System.out.println(" DM OwnerName : " + session.getDocbaseOwnerName() );


}
catch (DfException e)
{
System.out.println("Unable to retrieve DM server info: " + e );
}
}


public static void main (String[] args)
{
connectToDocbase();
getSessionInfo();

}
}

最佳答案

您可以按如下方式更改代码。您需要发送多个文档基本名称。

-docbase_name test1 test2 test3

在命令行中。

import com.documentum.fc.common.*;
import com.documentum.fc.client.*;
public class DocumentumRepoStatus
{
static IDfSession session;
static final String osFileSeparator = System.getProperty("file.separator");
static String[] docbaseNames = new String[] { "test1", "test2", "test3"};
static String userName = "user";
static String passWd = "test123";

static void parseArgs( String args[] ) // these are the command line args
{
final int MUST_HAVE_FLAGS = 1;
int i;

if ( args.length < (MUST_HAVE_FLAGS + 1) ) {
System.out.println("Not enough arguments.");

}
else {

for (i=0; i < args.length; i++)
{
if ( ! args[i].startsWith("-") ) {
System.out.println("Error parsing argument: " + args[i]);
System.out.println("Expecting a flag parameter starting with dash ('-')");

}
if ( args[i].equalsIgnoreCase("-docbase_name") ) {
i++;
docbaseNames = args[i].split(" ");
}
if ( args[i].equalsIgnoreCase("-user_name") ) {
i++;
userName = args[i];
}
if ( args[i].equalsIgnoreCase("-password") ) {
i++;
passWd = args[i];
}

} // end of for loop
} // end if if/else

if (docbaseName.length() == 0 ) {
System.out.println("Missing required argument -docbase_name.");

}
// If the user_name argument is not passed in, then trusted host for the Documentum login
// is assumed (login as the OS user). DFC, however requires a user name, so we will
// retrieve the username of the current user using the Java Standard System properties.
//
if (userName.length() == 0 ) {
userName = System.getProperty("user.name");

}
}


static void connectToDocbase()
{
IDfLoginInfo li = new DfLoginInfo();
li.setUser( userName );
li.setPassword( passWd );
li.setDomain( "" );
for(int i=0;i<docBaseNames.length;i++) {
try
{
IDfClient dfc = DfClient.getLocalClient();
session = dfc.newSession(docbaseNames[i], li );
System.out.println("Successful connection to Docbase " + docbaseName);
getSessionInfo();
}
catch (DfException e)
{
System.out.println("Unable to connect to docbase: " + e.toString() );
continue;
}
}
}

static void getSessionInfo()
{
try
{
System.out.println("");
System.out.println(" DM Session Properties: " );
System.out.println(" DM Server Version : " + session.getServerVersion() );
System.out.println(" DM Session ID : " + session.getSessionId());
System.out.println(" DM Docbase ID : " + session.getDocbaseId());
System.out.println(" DFC Version : " + DfClient.getDFCVersion() );
System.out.println(" DM OwnerName : " + session.getDocbaseOwnerName() );


}
catch (DfException e)
{
System.out.println("Unable to retrieve DM server info: " + e );
}
}


public static void main (String[] args)
{
connectToDocbase();
}
}

关于java - 如何将存储库名称作为 java 数组传递并在 documentum 代码中迭代它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23870368/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com