【问题标题】:How to pass repository names as java arrays and iterate it in documentum code?如何将存储库名称作为 java 数组传递并在 documentum 代码中对其进行迭代?
【发布时间】:2014-05-26 12:38:57
【问题描述】:

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

    }
}

【问题讨论】:

    标签: java arrays documentum documentum6.5 dfc


    【解决方案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();
        }
    }
    

    【讨论】:

    • 感谢 Shazin 的回复,但我在上述代码的 for(String docBaseName:docBaseNames) 行中出现错误。错误消息显示“对于每个语句仅在源级别可用是 5.0"。您能否建议如何纠正此问题?
    • 您使用的是 JDK 1.4。或低版本。然后,您需要更改代码。请检查编辑。
    • 完美,我现在明白了...非常感谢 Shazin,您的建议真的很有帮助,也澄清了我的概念
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多