001 /* 002 * file ReadWritePropertiesDemo.java 003 * 004 * Licensed Materials - Property of IBM 005 * Restricted Materials of IBM - you are allowed to copy, modify and 006 * redistribute this file as part of any program that interfaces with 007 * IBM Rational CM API. 008 * 009 * com.ibm.rational.stp.client.samples.ReadWritePropertiesDemo 010 * 011 * © Copyright IBM Corporation 2008. All Rights Reserved. 012 * Note to U.S. Government Users Restricted Rights: Use, duplication or 013 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 014 */ 015 016 package com.ibm.rational.stp.client.samples.cc; 017 018 import javax.wvcm.PropertyRequestItem.PropertyRequest; 019 020 import com.ibm.rational.wvcm.stp.cc.CcProvider; 021 import com.ibm.rational.wvcm.stp.cc.CcRegistryRegion; 022 import com.ibm.rational.wvcm.stp.cc.CcStream; 023 import com.ibm.rational.wvcm.stp.cc.CcVobTag; 024 025 /** 026 * Demonstrate how to read and write properties of ClearCase resources, 027 * including the use of nested property requests. 028 */ 029 public class ReadWritePropertiesDemo extends CcDemoBase { 030 031 private UcmHelper m_ucmHelper; 032 private CcStream m_stream; 033 private CcProvider m_provider; 034 035 protected void setUp() throws Exception { 036 super.setUp(); 037 m_provider = getClearCaseProvider(); 038 m_ucmHelper = new UcmHelper(this); 039 m_stream = m_ucmHelper.getUcmIntegrationStream(); 040 } 041 042 /** 043 * Demonstrate property request basics by reading several properties 044 * of a UCM stream. 045 */ 046 public void testReadProperties() throws Exception { 047 048 // Instantiate a property request. 049 // This particular request is for several different stream properties. 050 PropertyRequest wantedProps = new PropertyRequest( 051 CcStream.CREATOR_LOGIN_NAME, 052 CcStream.CREATION_DATE, 053 CcStream.DISPLAY_NAME 054 ); 055 056 m_stream = (CcStream) m_stream.doReadProperties(wantedProps); 057 058 trace("Stream name: " + m_stream.getDisplayName()); 059 trace("Stream created by: " + m_stream.getCreatorLoginName()); 060 trace("Stream creation date: " + m_stream.getCreationDate()); 061 } 062 063 public void testReadNestedProperties() throws Exception { 064 065 // Get the default CC registry region 066 CcRegistryRegion defaultRegion = 067 m_provider.doGetDefaultCcRegistryRegion(null); 068 069 // Construct nested property request for getting interesting properties 070 // of all the VOB tags in the registry. 071 PropertyRequest wantedProps = new PropertyRequest( 072 CcRegistryRegion.VOB_TAG_LIST.nest( 073 CcVobTag.DISPLAY_NAME, 074 CcVobTag.IS_PUBLIC, 075 CcVobTag.IS_PROJECT_VOB)); 076 077 // Fetch those properties. 078 defaultRegion = (CcRegistryRegion) defaultRegion.doReadProperties(wantedProps); 079 080 // And print the results 081 for (CcVobTag vobTag : defaultRegion.getVobTagList()) { 082 String tagStr = vobTag.getDisplayName(); 083 if (vobTag.getIsPublic()) { 084 tagStr = tagStr + " (public)"; 085 } 086 if (vobTag.getIsProjectVob()) { 087 tagStr = tagStr + " (pvob)"; 088 } 089 trace(tagStr); 090 } 091 092 // Bonus points if you know why this code throws an exception. 093 try { 094 trace("Default region: " + defaultRegion.getDisplayName()); 095 } catch (Exception ex){ 096 trace("Got exception trying to get display name property"); 097 } 098 } 099 }