com.free2be.dimensions.device.profile
Class DeviceProfileFactory

java.lang.Object
  extended by com.free2be.dimensions.device.DeviceFactory
      extended by com.free2be.dimensions.device.profile.DeviceProfileFactory

public class DeviceProfileFactory
extends DeviceFactory

A factory that reads the x-wap-profile header url and retrieves the .rdf (on the web or cached). All elements in the file will be retrieved through standard device API. For optimal efficiency caching is taking place to minimize parsing since the device characteristics are most likely consistent over time. A local serialized device object will be stored on the filesystem and retrieved keyed by the hashcode of the url that references the rdf. The device is also stored at the applcation scope since there is no session-specific attributes of this device profile.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.free2be.dimensions.device.DeviceFactory
DeviceFactory.ConfidenceLevel
 
Field Summary
static java.lang.String PROFILE_HEADER_KEY
           
 
Fields inherited from class com.free2be.dimensions.device.DeviceFactory
CONTENT, DEFAULT, DEVICE, MINIMUM_LEVEL_FOR_FINAL, MODEL, NONE, OVERRIDE, PRE_DETERMINED, STANDARD
 
Constructor Summary
DeviceProfileFactory()
           
 
Method Summary
protected static java.io.File createFile(java.lang.String deviceProfileUrlValue)
           
protected static void deleteFromCache(java.io.File file)
           
static Device discoverDeviceProfile(java.lang.String deviceProfileUrlValue, javax.servlet.http.HttpServletRequest request)
           
 DeviceFactory.ConfidenceLevel getConfidenceLevel()
          Retrieves the confidence level this factory has in fulfilling the request based on the information provided during intialization.
 Device getDevice()
          Retrieves a device to represent the calling client's device.
 DeviceFactory.ConfidenceLevel getHighestConfidenceLevel()
          Returns the highest confidence level the implementing device factory can provide.
 void initialize(java.lang.Object informationSource)
          Loads device profiles from UAProf .rdf xml files published on the web.
protected static Device loadFromApplicationScope(java.lang.String deviceProfileUrlValue, javax.servlet.http.HttpServletRequest request)
           
protected static Device loadFromLocalCache(java.lang.String deviceProfileUrlValue, javax.servlet.http.HttpServletRequest request)
          Loads the device from local cache if it has already been found.
protected static Device loadFromUrl(java.lang.String deviceProfileUrlValue, javax.servlet.http.HttpServletRequest request)
          Loads a Profile from the url paramaters.
protected static void storeInApplicationScope(Device device, java.lang.String deviceProfileUrlValue, javax.servlet.http.HttpServletRequest request)
           
protected static void storeInLocalCache(Device device, java.lang.String deviceProfileUrlValue)
           
protected static java.lang.String stripOffQuotes(java.lang.String deviceProfileUrlValue)
          Sometimes the url reference is coming with quotes.!!!
 
Methods inherited from class com.free2be.dimensions.device.DeviceFactory
clearPersistantDevice, getDeviceFactory, getFactories, getPersistentFactories
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROFILE_HEADER_KEY

public static final java.lang.String PROFILE_HEADER_KEY
See Also:
Constant Field Values
Constructor Detail

DeviceProfileFactory

public DeviceProfileFactory()
Method Detail

getDevice

public Device getDevice()
Description copied from class: DeviceFactory
Retrieves a device to represent the calling client's device.

Specified by:
getDevice in class DeviceFactory

getConfidenceLevel

public DeviceFactory.ConfidenceLevel getConfidenceLevel()
Description copied from class: DeviceFactory
Retrieves the confidence level this factory has in fulfilling the request based on the information provided during intialization.

Specified by:
getConfidenceLevel in class DeviceFactory

getHighestConfidenceLevel

public DeviceFactory.ConfidenceLevel getHighestConfidenceLevel()
Description copied from class: DeviceFactory
Returns the highest confidence level the implementing device factory can provide. This method should be considered a static method and return a value upon empty construction.

Specified by:
getHighestConfidenceLevel in class DeviceFactory

initialize

public void initialize(java.lang.Object informationSource)
Loads device profiles from UAProf .rdf xml files published on the web. This will look for this defined device in persistent places in the following order:

All references to the persistant files will be keyed off the x-wap-profile http header value which references a url. 1. Application Scope (ServletContext.attribute) for a constructed device already present. 2. Local Persistance where the object has been serialized and saved. 3. URL reference published online by the device manufacturer or carrier.

Specified by:
initialize in class DeviceFactory
Parameters:
informationSource - The HttpRequest object possibly containing x-wap-profile header or a Map containing x-wap-profile as a key and the url of interest as the value of that key and the request identified by key 'request'.

discoverDeviceProfile

public static Device discoverDeviceProfile(java.lang.String deviceProfileUrlValue,
                                           javax.servlet.http.HttpServletRequest request)
                                    throws java.net.MalformedURLException,
                                           DeviceProfileException
Throws:
java.net.MalformedURLException
DeviceProfileException

loadFromLocalCache

protected static Device loadFromLocalCache(java.lang.String deviceProfileUrlValue,
                                           javax.servlet.http.HttpServletRequest request)
Loads the device from local cache if it has already been found. Any problems reading the file will be ignored and the file will be deleted if possible. Let the XML be parsed again.


deleteFromCache

protected static void deleteFromCache(java.io.File file)

createFile

protected static java.io.File createFile(java.lang.String deviceProfileUrlValue)

storeInLocalCache

protected static void storeInLocalCache(Device device,
                                        java.lang.String deviceProfileUrlValue)

loadFromApplicationScope

protected static Device loadFromApplicationScope(java.lang.String deviceProfileUrlValue,
                                                 javax.servlet.http.HttpServletRequest request)

storeInApplicationScope

protected static void storeInApplicationScope(Device device,
                                              java.lang.String deviceProfileUrlValue,
                                              javax.servlet.http.HttpServletRequest request)

stripOffQuotes

protected static java.lang.String stripOffQuotes(java.lang.String deviceProfileUrlValue)
Sometimes the url reference is coming with quotes.!!!


loadFromUrl

protected static Device loadFromUrl(java.lang.String deviceProfileUrlValue,
                                    javax.servlet.http.HttpServletRequest request)
                             throws java.net.MalformedURLException,
                                    DeviceProfileException
Loads a Profile from the url paramaters.

Throws:
java.net.MalformedURLException
DeviceProfileException