org.jmythapi.protocol.response.impl
Class AMythResponse<E extends Enum<E>>

java.lang.Object
  extended by org.jmythapi.impl.AData<E>
      extended by org.jmythapi.protocol.response.impl.AMythResponse<E>
All Implemented Interfaces:
Cloneable, IPropertyAware<E>, IVersionable, ISendable, IMythResponse<E>
Direct Known Subclasses:
AFreeSpace, AMythEvent, AProgramInfo, ARecordings, FileStatus, FileTransfer, FreeInputsList, FreeSpaceList.Entry, GuideDataThrough, InputInfoFree, InputInfoTuned, Load, MemStats, Pixmap, ProgramInfoList, RecorderChannelInfo, RecorderChannelPrefixStatus, RecorderInfo, RecordingStatus, RemoteEncoderBusyStatus, RemoteEncoderState, RingBuffer, Setting, StorageGroupFile, StorageGroupFileList, Timezone, TunerInfo, Uptime

public abstract class AMythResponse<E extends Enum<E>>
extends AData<E>
implements IMythResponse<E>


Field Summary
 
Fields inherited from class org.jmythapi.impl.AData
logger, propsClass, protoVersion, respArgs
 
Constructor Summary
AMythResponse(Class<E> propsClass, IMythPacket packet)
          A constructor to create a response object from a given packet object.
AMythResponse(ProtocolVersion protoVersion, Class<E> propsClass)
          A constructor to create a response object with an empty response-arguments list.
AMythResponse(ProtocolVersion protoVersion, Class<E> propsClass, List<String> responseArgs)
          A constructor to create a response object from the given response-arguments list.
AMythResponse(ProtocolVersion protoVersion, Class<E> propsClass, String... responseArgs)
          A constructor to create a response object from the given response-arguments array.
 
Method Summary
protected  void checkSize(List<String> responseArgs)
          A function to check if the given response-argument-liste contains all expected arguments.
protected
<T> T
decodeProperty(Class<T> dataType, String dataValue)
           
protected
<S,T> String
encodeProperty(Class<S> propObjectType, S propValue, Class<T> propStringType, String propDefaultValue)
           
protected  int getExpectedSize(List<String> responseArgs)
          This function returns the expected size of the response-argument-list.
 IMythPacket getPacket()
          Converts this response-object into a IMythPacket.
 EnumSet<E> getProperties()
          Returns all supported properties.
 E getProperty(int idx)
          Gets the property for the given index.
 int getPropertyIndex(E prop)
          Gets the index for the given property.
 
Methods inherited from class org.jmythapi.impl.AData
clone, equals, getPropertyClass, getPropertyCount, getPropertyMap, getPropertyValue, getPropertyValue, getPropertyValueObject, getPropertyValueObject, getPropertyValues, getVersionNr, hashCode, init, postProcessArguments, setPropertyValue, setPropertyValue, setPropertyValueObject, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jmythapi.IPropertyAware
getPropertyClass, getPropertyCount, getPropertyMap, getPropertyValue, getPropertyValue, getPropertyValueObject, getPropertyValues, setPropertyValue, setPropertyValue, setPropertyValueObject
 
Methods inherited from interface org.jmythapi.IVersionable
getVersionNr
 

Constructor Detail

AMythResponse

public AMythResponse(ProtocolVersion protoVersion,
                     Class<E> propsClass)
A constructor to create a response object with an empty response-arguments list.

This constructor should be used if the response properties should be set via the corresponding setter methods afterwards.

Parameters:
protoVersion - the protocol version
propsClass - a enumeration class defining all supported response properties

AMythResponse

public AMythResponse(Class<E> propsClass,
                     IMythPacket packet)
A constructor to create a response object from a given packet object.

Parameters:
propsClass - a enumeration class defining all supported response properties.
packet - the packet object.

AMythResponse

public AMythResponse(ProtocolVersion protoVersion,
                     Class<E> propsClass,
                     String... responseArgs)
A constructor to create a response object from the given response-arguments array.

Parameters:
protoVersion - the protocol version.
propsClass - a enumeration class defining all supported response properties
responseArgs - the array of response arguments

AMythResponse

public AMythResponse(ProtocolVersion protoVersion,
                     Class<E> propsClass,
                     List<String> responseArgs)
A constructor to create a response object from the given response-arguments list.

Parameters:
protoVersion - the protocol version.
propsClass - a enumeration class defining all supported response properties
responseArgs - the list of response arguments.
Method Detail

getPacket

public IMythPacket getPacket()

Converts this response-object into a IMythPacket.

Specified by:
getPacket in interface ISendable
Returns:
a packet object that can be send over network

getProperty

public E getProperty(int idx)
Description copied from interface: IPropertyAware
Gets the property for the given index.

This is the reverse operation of IPropertyAware.getPropertyIndex(Enum).

Protocol Version Hint:

Depending on the used protocol version a specific property may be located at a different position.

Usage example:


    for(int i=0; i < object.getPropertyCount(); i++) {
       System.out.println(String.format(
          "Property %02d: %s",
          i, object.getProperty(i)
       ));
    }
 

Specified by:
getProperty in interface IPropertyAware<E extends Enum<E>>
Specified by:
getProperty in class AData<E extends Enum<E>>
Parameters:
idx - the position within the property array
Returns:
the enumeration constant

getPropertyIndex

public int getPropertyIndex(E prop)
Description copied from interface: IPropertyAware
Gets the index for the given property.

This is the reverse operation of IPropertyAware.getProperty(int)

Protocol Version Hint:

If the given property is not supported in the current protocol version, -1 is returned.

Usage example:


    EnumSet<IProgramInfo.Props> props = program.getProperties();
    for(IProgramInfo.Props prop : props) {
       System.out.println(String.format(
          "Property %s is stored at position %d.",
          prop.name(), program.getPropertyIndex(prop)
       ));
    }
 

Specified by:
getPropertyIndex in interface IPropertyAware<E extends Enum<E>>
Specified by:
getPropertyIndex in class AData<E extends Enum<E>>
Parameters:
prop - the property for which the index should be returned
Returns:
the index of the property or -1, if a property is not supported in the currently used protocol version.

getProperties

public EnumSet<E> getProperties()
Description copied from interface: IPropertyAware
Returns all supported properties.

Protocol Version Hint:

Depending on the protocol version, a different set of properties my be returned.

Specified by:
getProperties in interface IPropertyAware<E extends Enum<E>>
Specified by:
getProperties in class AData<E extends Enum<E>>
Returns:
all properties supported in the current protocol version

decodeProperty

protected <T> T decodeProperty(Class<T> dataType,
                               String dataValue)
Specified by:
decodeProperty in class AData<E extends Enum<E>>

encodeProperty

protected <S,T> String encodeProperty(Class<S> propObjectType,
                                      S propValue,
                                      Class<T> propStringType,
                                      String propDefaultValue)
Specified by:
encodeProperty in class AData<E extends Enum<E>>

getExpectedSize

protected int getExpectedSize(List<String> responseArgs)

This function returns the expected size of the response-argument-list.

The expected size may be different depending on the current MythTV-protocol-version.
The default implementation of this function uses EnumUtils#getEnumLength(Class, int) to determine the expected size of the argument-list.

Parameters:
responseArgs - the response-argument-list

checkSize

protected void checkSize(List<String> responseArgs)
                  throws IllegalArgumentException

A function to check if the given response-argument-liste contains all expected arguments.

The expected argument-list-size is calculated using #getExpectedSize(ArrayList).

Parameters:
responseArgs - the response-argument-list
Throws:
IllegalArgumentException - if expected arguments are missing.


Copyright © 2008-2013. All Rights Reserved.