1

我有一个下面的代码来检测一个 documentum docbase (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();       

    }
}
4

1 回答 1

1

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

-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();
    }
}
于 2014-05-26T12:58:10.087 回答