com.tek42.perforce.parse
Class AbstractFormBuilder<T>

java.lang.Object
  extended by com.tek42.perforce.parse.AbstractFormBuilder<T>
All Implemented Interfaces:
Builder<T>
Direct Known Subclasses:
GroupBuilder, LabelBuilder, UserBuilder, WorkspaceBuilder

public abstract class AbstractFormBuilder<T>
extends java.lang.Object
implements Builder<T>

Abstract class that parses the stringbuilder into key/value pairs and then sends them to a abstract method responsible for building the object. If you extend this class, you do NOT override build(StringBuilder) but buildForm(Map).

Useful for all perforce objects that are editable via forms. i.e., User, Workspace, Jobspec, etc.

Author:
Mike Wille

Constructor Summary
AbstractFormBuilder()
           
 
Method Summary
 T build(java.lang.StringBuilder sb)
          This should assemble an object from a string value.
abstract  T buildForm(java.util.Map<java.lang.String,java.lang.String> fields)
          Should return a new object set with the data from fields.
protected  java.lang.String getField(java.lang.String key, java.util.Map<java.lang.String,java.lang.String> fields)
          Test for null and returns an empty string if the key is not present.
protected  java.util.List<java.lang.String> getFieldAsList(java.lang.String key, java.util.Map<java.lang.String,java.lang.String> fields)
          Like getField(String, Map) except that it assumes the value of the field is a String containing a delimited list of values.
 boolean requiresStandardInput()
          Default implementation for most Perforce operations is to use stdin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.tek42.perforce.parse.Builder
getBuildCmd, getSaveCmd, save
 

Constructor Detail

AbstractFormBuilder

public AbstractFormBuilder()
Method Detail

build

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

Specified by:
build in interface Builder<T>
Parameters:
sb - The StringBuilder containing the string value.
Returns:
The resulting object
Throws:
PerforceException - If the format is invalid or other errors occur.

getField

protected java.lang.String getField(java.lang.String key,
                                    java.util.Map<java.lang.String,java.lang.String> fields)
Test for null and returns an empty string if the key is not present. Otherwise, returns the value.

Parameters:
key -
fields -
Returns:

getFieldAsList

protected java.util.List<java.lang.String> getFieldAsList(java.lang.String key,
                                                          java.util.Map<java.lang.String,java.lang.String> fields)
Like getField(String, Map) except that it assumes the value of the field is a String containing a delimited list of values. It parses the string into a string list. Assumes new line as separator.

Parameters:
key - The name of the field.
fields - The map of field/value pairs.
Returns:
A List of strings.

requiresStandardInput

public boolean requiresStandardInput()
Default implementation for most Perforce operations is to use stdin. This will return true.

Specified by:
requiresStandardInput in interface Builder<T>
Returns:
True always

buildForm

public abstract T buildForm(java.util.Map<java.lang.String,java.lang.String> fields)
                     throws PerforceException
Should return a new object set with the data from fields.

Parameters:
fields -
Returns:
Throws:
PerforceException


Copyright © 2009. All Rights Reserved.