com.cisco.provisioning.cpe.extensions.configuration
Class AbstractTFTPFile

java.lang.Object
  extended by com.cisco.provisioning.cpe.extensions.configuration.AbstractTFTPFile
All Implemented Interfaces:
com.cisco.csrc.encode.Encodable, com.cisco.csrc.util.Displayable, TFTPFile, Externalizable, Serializable
Direct Known Subclasses:
DOCSISTFTPFile, SimpleTFTPFile

public abstract class AbstractTFTPFile
extends Object
implements TFTPFile, Externalizable, com.cisco.csrc.encode.Encodable, com.cisco.csrc.util.Displayable

Abstract TFTPFile class. This class implement the TFTPFile interface and provides an abstract implementation that can be subclassed to provide a concrete implementation of the TFTPFile interface with minimal effort. Subclasses must be serializable.

See Also:
TFTPFile, Serialized Form

Constructor Summary
AbstractTFTPFile()
          No-arg constructor.
AbstractTFTPFile(byte[] fileBytes)
          Use this constructor when no filename tag is used and the configuration file bytes is known at construction time.
AbstractTFTPFile(String filename)
          Use this constructor when the filename is known at construction time, but the configuration file contents are created later.
AbstractTFTPFile(String filename, byte[] fileBytes)
          Use this constructor when the filename and configuration file bytes are known at construction time.
 
Method Summary
 void decode(ByteArrayInputStream in, com.cisco.csrc.encode.DataDecoder decoder)
          Decodes object's data and sets object's variables.
 void display(PrintWriter output, String prefix, List<String> options, boolean verbose)
          Display the contents of this object for debugging.
 void encode(ByteArrayOutputStream out, com.cisco.csrc.encode.DataEncoder encoder)
          Encodes object's data.
 boolean equals(Object object)
          Indicates whether some other object is "equal to" this one.
abstract  void generate()
          Generate the TFTP file.
 byte[] getFile()
          Get the configuration file to be delivered to the device.
 String getFilename()
          Get the filename identifier for the TFTPFile.
 Map<String,Object> getProperties()
          Get the property map.
 Object getProperty(String key)
          Get the named property from the property map.
 int hashCode()
          Returns the hashcode for this AbstractTFTPFile.
abstract  void mix(String ipAddress, CSRCProperties properties)
          Perform DPE mixing.
 String paramString()
          Returns a string representing the state of the TFTPFile object.
 void readExternal(ObjectInput in)
          Externalizable interface.
 void setProperty(String key, Object value)
          Set the named property in the property map.
 String toString()
          Return a string containing the contents of TFTPFile in human-readable form.
abstract  void validate()
          Validate the TFTP file.
 void writeExternal(ObjectOutput out)
          Externalizable interface.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractTFTPFile

public AbstractTFTPFile()
No-arg constructor. Not all TFTPFile objects will have a filename tag or know their configuration file data at construction time. It is expected that addtional methods will be provided by the subclass to create the configuration data.


AbstractTFTPFile

public AbstractTFTPFile(String filename)
Use this constructor when the filename is known at construction time, but the configuration file contents are created later.

Parameters:
filename -

AbstractTFTPFile

public AbstractTFTPFile(byte[] fileBytes)
Use this constructor when no filename tag is used and the configuration file bytes is known at construction time.

Parameters:
fileBytes -

AbstractTFTPFile

public AbstractTFTPFile(String filename,
                        byte[] fileBytes)
Use this constructor when the filename and configuration file bytes are known at construction time.

Parameters:
filename -
fileBytes -
Method Detail

getFilename

public final String getFilename()
Get the filename identifier for the TFTPFile. It is possible there is no filename identifier, in which case null is returned.

Specified by:
getFilename in interface TFTPFile
Returns:
filename or null if no filename defined

getFile

public byte[] getFile()
Get the configuration file to be delivered to the device. This method is invoked by the DPE when the TFTP file is requested by the device. If dynamic file mixing is required then the mix() method must be invoked prior to this method.

Specified by:
getFile in interface TFTPFile
Returns:
the configuration file

getProperty

public final Object getProperty(String key)
Get the named property from the property map.

Specified by:
getProperty in interface TFTPFile
Parameters:
key - property name
Returns:
property value, or null if no property matching key found

setProperty

public final void setProperty(String key,
                              Object value)
Set the named property in the property map. If the property key already exists it is replaced with the given property value.

Specified by:
setProperty in interface TFTPFile
Parameters:
key - property name
value - property value
Throws:
IllegalArgumentException - if key or value is invalid

getProperties

public final Map<String,Object> getProperties()
Get the property map. A read-only version of the property map contained in the TFTP File object is returned.

Specified by:
getProperties in interface TFTPFile
Returns:
property map

validate

public abstract void validate()
                       throws InvalidConfigException
Validate the TFTP file. This method implements any validation of the TFTP file that is required during RDU configuration generation. Optional.

Specified by:
validate in interface TFTPFile
Throws:
InvalidConfigException - if any errors are encountered during the validation.

generate

public abstract void generate()
                       throws InvalidConfigException
Generate the TFTP file. This method implements any post-processing of the TFTP file that is required during RDU configuration generation. Optional.

Specified by:
generate in interface TFTPFile
Throws:
InvalidConfigException - if any errors are encountered during the generation.

mix

public abstract void mix(String ipAddress,
                         CSRCProperties properties)
                  throws InvalidConfigException
Perform DPE mixing. This method is invoked prior to the file being sent to the device. Perform any mixing operations required. Optional.

Specified by:
mix in interface TFTPFile
Parameters:
ipAddress - of the device requesting the TFTP file
properties - relevant to mixing operation
Throws:
InvalidConfigException - if any errors are encountered during the mixing.

hashCode

public int hashCode()
Returns the hashcode for this AbstractTFTPFile.

Overrides:
hashCode in class Object
Returns:
the hashcode for this AbstractTFTPFile.

equals

public boolean equals(Object object)
Indicates whether some other object is "equal to" this one. We override this method to compare all the fields of DHCPData.

Overrides:
equals in class Object
Parameters:
object - to compare
Returns:
true if equal

toString

public final String toString()
Return a string containing the contents of TFTPFile in human-readable form. This is mainly a debugging tool. The contents of the output string is read from paramString().

Overrides:
toString in class Object
Returns:
String

paramString

public String paramString()
Returns a string representing the state of the TFTPFile object. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null. Subclasses should override to provide additional fields in the output string.

Returns:
String

display

public void display(PrintWriter output,
                    String prefix,
                    List<String> options,
                    boolean verbose)
Display the contents of this object for debugging.

The output from this method is expected to be easier to read, with possibly less detail than is produced by toString. The output can be multi-line if that makes it easier to read.

Specified by:
display in interface com.cisco.csrc.util.Displayable
Parameters:
output - the resulting output is written to this parameter.
prefix - string to output before each line, usually blanks to indent this output to show association with parent object.
options - list of string options to control output.
verbose - true indicates detailed output desired.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Externalizable interface. The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Specified by:
readExternal in interface Externalizable
Parameters:
in - the stream to read data from in order to restore the object
Throws:
IOException - if I/O errors occur
ClassNotFoundException - If the class for an object being restored cannot be found.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Externalizable interface. The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Specified by:
writeExternal in interface Externalizable
Parameters:
out - the stream to write the object to
Throws:
IOException - Includes any I/O exceptions that may occur

encode

public void encode(ByteArrayOutputStream out,
                   com.cisco.csrc.encode.DataEncoder encoder)
Encodes object's data.

Specified by:
encode in interface com.cisco.csrc.encode.Encodable
Parameters:
out - the output stream to write to
encoder - the encoder to use

decode

public void decode(ByteArrayInputStream in,
                   com.cisco.csrc.encode.DataDecoder decoder)
Decodes object's data and sets object's variables.

Specified by:
decode in interface com.cisco.csrc.encode.Encodable
Parameters:
in - the input stream to write to
decoder - the decoder to use