com.blackledge.david.tivo.multitasker
Class MultiTaskerApplicationFactory

java.lang.Object
  extended by com.tivo.hme.sdk.Factory
      extended by com.blackledge.david.tivo.multitasker.MultiTaskerApplicationFactory
All Implemented Interfaces:
com.tivo.hme.interfaces.IFactory

public class MultiTaskerApplicationFactory
extends com.tivo.hme.sdk.Factory

Multitasker Factory - handle local files as streams and automatic reformatting of local images as streams. Support handling of "local/" urls to return filestreams of files under the "local file root" as defined in options. and "localimage/" urls to return a stream containing the local image file, but scaled to fit in tivo requirements.




Custom Factories


Custom factories are used for several purposes:
  • Storing data common to all instances of the application – For example, a music player might have a heavyweight database of tracks stored in the factory. Because the database is in the factory, it can be shared across all instances of the application. See Chapter 4 for a discussion of the pictures and music player sample applications.
  • Handling command line arguments – The factory is a convenient place to handle command line arguments.
  • Handling HTTP requests for assets– Sometimes it is necessary to override the default behavior for fetching assets via HTTP. For example, a music player wouldn’t be very interesting if it could only play music that’s in the classpath. The music player can use a custom factory to serve music off the disk in response to HTTP requests.

    Naming a Factory


    You can continue to use the generic Factory’s command line facilities even if your application has a custom factory, as long as you honor a specific naming convention. If an application is named App, then its corresponding factory should be a public inner class named AppFactory. Following this convention makes it possible for HME to automatically find the custom factory class, for example:
     
     package com.foo; public class MP3Player extends Application { public
     static class MP3PlayerFactory extends Factory { … } }
     
     
    getAppFactory() Method
    The static Application.getAppFactory() method can be overridden to return an appropriate factory that doesn’t use the naming pattern described above:
     
     static com.tivo.hme.interfaces.IFactory getAppFactory( java.lang.String
     appClassName, java.lang.ClassLoader loader,
     com.tivo.hme.interfaces.IArgumentList args)
     
     

    Be sure to initialize the custom factory by calling the initFactory() method before returning from the getAppFactory() method

    Version:
    $Revision: 1.1 $

    Field Summary
     
    Fields inherited from class com.tivo.hme.sdk.Factory
    active, assetURI, clazz, factoryData, isActive, listener, loader, title, uri
     
    Fields inherited from interface com.tivo.hme.interfaces.IFactory
    HME_APPLICATION_CLASSNAME, HME_DEBUG_KEY, HME_VERSION_TAG
     
    Constructor Summary
    MultiTaskerApplicationFactory()
              MultiTasker's Application factory.
     
    Method Summary
    protected  void addHeaders(com.tivo.hme.interfaces.IHttpRequest http, String uri)
               
     String getShortMappedUri(String uri)
              Record a short mapping url in the factory that will return the resource that would have been returned by the passed in uri, except it's maybe too long.
     InputStream getStream(String uri2)
              If you override, just be sure to allow this (super) implementation to handle url's that are myapp/local.
     String getUnmappedUri(String shortUri)
              Undo the work of getShortMappedUri(String).
     boolean isHandledUri(String uri)
               
     
    Methods inherited from class com.tivo.hme.sdk.Factory
    addApplication, close, createApplication, destroyFactory, fetchAsset, getActiveCount, getAppName, getAppTitle, getAssetURI, getFactoryData, getQuery, getSeekTime, getTitle, getURI, init, initFactory, isActive, log, removeApplication, removeQueryFromURI, setActive, setAppName, setAppTitle, setAssetURI, setListener, setTitle, setURI, shutdown, toString
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Constructor Detail

    MultiTaskerApplicationFactory

    public MultiTaskerApplicationFactory()
    MultiTasker's Application factory. Handles "local" and "localimage" urls. Subclass this to create your own factory if needed and you still want to support those urls.

    Method Detail

    isHandledUri

    public boolean isHandledUri(String uri)

    getStream

    public InputStream getStream(String uri2)
                          throws IOException
    If you override, just be sure to allow this (super) implementation to handle url's that are myapp/local. And call getUnmappedUri(String) on the uri to handle any short mapping that may have been done.

    Overrides:
    getStream in class com.tivo.hme.sdk.Factory
    Throws:
    IOException
    See Also:
    Factory.getStream(java.lang.String)

    addHeaders

    protected void addHeaders(com.tivo.hme.interfaces.IHttpRequest http,
                              String uri)
                       throws IOException
    Overrides:
    addHeaders in class com.tivo.hme.sdk.Factory
    Throws:
    IOException

    getShortMappedUri

    public String getShortMappedUri(String uri)
    Record a short mapping url in the factory that will return the resource that would have been returned by the passed in uri, except it's maybe too long. Recognizes duplicate requests and returns the same mapping unless the original mapping has been deleted to conserve memory.

    Parameters:
    uri -
    Returns:
    a short uri that will return the result of getting the original uri; or the original uri if it is has no path or is badly formed.

    getUnmappedUri

    public String getUnmappedUri(String shortUri)
    Undo the work of getShortMappedUri(String).

    Parameters:
    shortUri - the result of the call to getShortMappedUri(String)
    Returns:
    the uri originally passed to getShortMappedUri(String) or shortUri if no mapping exists.