CM API 會區別 CcFile(視圖中的一個檔案,以上的作業就是透過此檔案來執行)及與其相關聯 的基礎 ClearCase 元素和版本(cElement 和 CcVersion)。
CcFile.doVersionControl() 方法可建立 CcElement 資源及起始的 CcVersion 資源,這些資源的內容與 CcFile 的內容相同。
// 取得 ClearCase 提供者。 CcProvider provider = ...; // 為即將移出的檔案建立 CcFile 虛擬物件。 // 首先,從檔案的路徑建立一個單純傳統的 Java "File" 實例。 // 然後,從該檔案建立 StpLocation 實例。 // 最後,從該位置建立 CcFile 虛擬物件。 File file = new File("C:/my_views/example_view/avob/example.txt"); StpLocation fileLoc = provider.filePathLocation(Domain.CLEAR_CASE, file); CcFile testFile = provider.ccFile(fileLoc); // 針對我們需要的檔案內容,建立 // 內容要求。讀取那些內容。請注意,取得的結果 // 內容值「只」存在於 doReadProperties() // 所傳回的 CcFile 虛擬物件中,而不在原始虛擬物件中。 PropertyRequest wantedProps = new PropertyRequest( CcFile.IS_VERSION_CONTROLLED, CcFile.IS_CHECKED_OUT); testFile = (CcFile) testFile.doReadProperties(wantedProps); if ( ! testFile.getIsVersionControlled()) { // 檔案尚未置於版本控制下,請控制檔案。 // 同時,再次讀取我們需要的內容。 testFile = (CcFile) testFile.doVersionControl(wantedProps); } if ( ! testFile.getIsCheckedOut()) { // 檔案尚未移出,請移出檔案。 // 同時,再次讀取我們需要的內容。 testFile = testFile.doCcCheckout(null, wantedProps); } // 驗證檔案現在處於版本控制下且已移出。 assert(testFile.getIsVersionControlled() == true); assert(testFile.getIsCheckedOut() == true);
對於本端 Web 視圖中的資源,某些作業可能會也可能不會與伺服器產生互動。例如:
「資源」介面本身不提供建立基礎資源的方法,因為部分資源無法由使用者建立。 建立虛擬物件是指實例化「資源」物件,而建立資源必須呼叫 doCreateResource() 或 doCreateVersionControlledResource() 方法來完成,請注意兩者的差別。