com.tek42.perforce.parse
Interface Builder<T>

All Known Implementing Classes:
AbstractFormBuilder, ChangelistBuilder, CounterBuilder, GroupBuilder, LabelBuilder, UserBuilder, WorkspaceBuilder

public interface Builder<T>

Interface for parsing perforce output into a concrete object and also for saving the object back to perforce.

The pattern for using this template to build an object is:

  1. Retrieve commands to execute via getBuildCmd(String)
  2. Execute those commands and capture the output.
  3. Pass the output to build(StringBuilder)

And conversely for saving:

  1. Retrieve commands to execute via getSaveCmd(Object)
  2. Execute those commands and retrieve a Writer for I/O
  3. Pass the writer and the object to save to save(Object, Writer)

Author:
Mike Wille

Method Summary
 T build(java.lang.StringBuilder sb)
          This should assemble an object from a string value.
 java.lang.String[] getBuildCmd(java.lang.String id)
          This should return the command line tokens to execute for retrieving an object from Perforce.
 java.lang.String[] getSaveCmd(T obj)
          The converse of getBuildCmd(String) this should return the command line tokens to execute for saving an object to Perforce.
 boolean requiresStandardInput()
          Tells the AbstractPerforceTemplate whether or not this builder will write data on Standard Input to the perforce command specified in getSaveCmd().
 void save(T obj, java.io.Writer writer)
          The converse of build(StringBuilder) this should take an object and disassemble it for writing to the Perforce server.
 

Method Detail

getBuildCmd

java.lang.String[] getBuildCmd(java.lang.String id)
This should return the command line tokens to execute for retrieving an object from Perforce. For example: String[] { "p4", "user", "-o", "mwille" }

Parameters:
id - The ID or Name of the object we are working on. In the case of a changelist, the changelist number. In the case of a user, the username.
Returns:
A 1D string array of tokens to execute.

build

T build(java.lang.StringBuilder sb)
        throws PerforceException
This should assemble an object from a string value. Format of the string is dependent on the object we are building and is unspecified.

Parameters:
sb - The StringBuilder containing the string value.
Returns:
The resulting object
Throws:
PerforceException - If the format is invalid or other errors occur.

getSaveCmd

java.lang.String[] getSaveCmd(T obj)
The converse of getBuildCmd(String) this should return the command line tokens to execute for saving an object to Perforce. For example: String[] { "p4", "user", "-i", "mwille" }

Note, although the object being saved is passed to this method, this method does not need to do anything with it.

Parameters:
obj - The object that is being saved, useful if propert(ies) are needed for the save command to be generated.
Returns:
A 1D string array of tokens to execute

requiresStandardInput

boolean requiresStandardInput()
Tells the AbstractPerforceTemplate whether or not this builder will write data on Standard Input to the perforce command specified in getSaveCmd(). Currently, this only applies to saving as their is no writing required for building.

Returns:
True if standard input should be opened and this builder's save() method called. False otherwise.

save

void save(T obj,
          java.io.Writer writer)
          throws PerforceException
The converse of build(StringBuilder) this should take an object and disassemble it for writing to the Perforce server. The specification of what is written to the Writer is dependant on the object being saved.

Parameters:
obj - The object to be saved
writer - The Writer to write the string representation to
Throws:
PerforceException - If the object is invalid or there is an issue with writing


Copyright © 2009. All Rights Reserved.