How to set properties that don't have "get/set" methods in the StarTeam SDK using the "Property Editor" property of the "Project" class as an example.
Question: Do you know of a way in the SDK to set the project to require Active Process Items?
This is a real good question. In this post, I'll use the example of this particular project property to illustrate the general technique for setting properties on pretty much any StarTeam SDK object.
It's like this: The Project class does not provide a handy get/set method for "require process item to checkin", and so when you look at the Project class, it appears that there is not a way to do it.
However, there must be a property, right? After all, the knowledge that a process item is required must be stored somewhere in StarTeam... or to say it in java, somewhere in the project object.
So, we look at two things. First, does the Project class have a "put" method that can be given a propertyName object? Yes it does.
[blockquote]put
public java.lang.Object put(java.lang.String propertyName,
java.lang.Object value)
throws NoSuchPropertyException,
java.lang.ClassCastException
Sets the value of the specified property and return the old value.
Parameters:
propertyName - the name of the property to set
value - the new value to set for the specified property
Returns:
the old property value
Throws:
NoSuchPropertyException - if the named property does not exist
java.lang.ClassCastException - if the value is of the wrong type for the specified property
[/blockquote]
In fact, all "Simple Typed Resources" in SDK have get/put methods that take a propertyName object. So, all we need is to figure out the property name.
The second thing we look at is the Server class' getPropertyNames method...
[blockquote]getPropertyNames
public PropertyNames getPropertyNames()
Returns the PropertyNames object for this server. You must have already connected to the server or an IllegalStateException will be thrown.
Returns:
property names for this server.[/blockquote]
And then we find the propertyName for the property we want to "put"
[blockquote]PROJECT_PROCESS_REQUIRED
The "Process Required" property for Items of type Project.
[/blockquote]
So, the code would be something like this....
[blockquote]myProject.put(myProject.getServer().getPropertyNames().PROJECT_PROCESS_REQUIRED,true);[/blockquote]
...and of course, this technique is useful in many many other places where there is a property without a handy get/set method.
Trackback(0)
|