CM API 用于区别 CcFile(它是视图中的文件,用于执行上述操作)和与其相关联的底层 ClearCase 元素和版本(CcElement 和 CcVersion)。
CcFile.doVersionControl() 方法将创建 CcElement 资源和初始的 CcVersion 资源,它们将与 CcFile 具有相同的内容。
// Get the ClearCase provider.
CcProvider provider = ...;
// Create a CcFile proxy for the file to be checked out.
// First, create a plain old Java "File" instance from the file's path.
// Then create an StpLocation instance from that file.
// Finally, create a CcFile proxy from the location.
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);
// Create a property request for the file's properties that we're
// interested in. Read those properties. Note that the resulting
// property values are available *only* in the CcFile proxy returned by
// doReadProperties(), not in the original proxy.
PropertyRequest wantedProps = new PropertyRequest(
CcFile.IS_VERSION_CONTROLLED,
CcFile.IS_CHECKED_OUT);
testFile = (CcFile) testFile.doReadProperties(wantedProps);
if ( ! testFile.getIsVersionControlled()) {
// The file is not yet under version control, so control it.
// At the same time, re-read the properties we're interested in.
testFile = (CcFile) testFile.doVersionControl(wantedProps);
}
if ( ! testFile.getIsCheckedOut()) {
// The file is not yet checked out, so check it out.
// At the same time, re-read the properties we're interested in.
testFile = testFile.doCcCheckout(null, wantedProps);
}
// Verify that the file is now version controlled and checked out.
assert(testFile.getIsVersionControlled() == true);
assert(testFile.getIsCheckedOut() == true);
对本地 Web 视图中资源的特定操作可以与服务器交互。例如:
Resource 接口本身不提供创建底层资源的方法,因为某些资源不能由用户创建。请注意创建代理与创建资源之间的区别,前者是实例化 Resource 对象,而后者必须通过调用 doCreateResource() 或 doCreateVersionControlledResource() 方法才能完成。