net.sourceforge.wurfl.core.resource
Class DefaultWURFLModel

java.lang.Object
  extended by net.sourceforge.wurfl.core.resource.DefaultWURFLModel
All Implemented Interfaces:
WURFLModel

public class DefaultWURFLModel
extends Object
implements WURFLModel

This is the default WURFLModel implementation. This class store the devicesById in a Map in memory so it is very quick and no need for cache.

Version:
$Id: DefaultWURFLModel.java 432 2010-05-06 12:12:53Z filippo.deluca $
Author:
Fantayeneh Asres Gizaw, Filippo De Luca

Constructor Summary
DefaultWURFLModel(WURFLResource root)
          Build a model by WURFLResource.
DefaultWURFLModel(WURFLResource root, WURFLResources patches)
          Build model by root WURFLResource and patches WURFLResources.
 
Method Summary
 Set getAllCapabilities()
          Return all capabilities name defined by held ModelDevices.
 Set getAllDevices()
          Return all defined devices.
 Set getAllDevicesId()
          Return all defined devices identifiers.
 Set getAllGroups()
          Return all defined group's identifiers.
 Set getCapabilitiesForGroup(String groupId)
          Return the capabilities defined in the given group.
 ModelDevice getDeviceAncestor(ModelDevice device)
          Return a ModelDevice ancestor.
 ModelDevice getDeviceById(String id)
          Returns ModelDevice by his id.
 ModelDevice getDeviceFallback(ModelDevice device)
          Return the device's fallback.
 List getDeviceHierarchy(ModelDevice device)
          Returns device hierarchy.
 Set getDevices(Set devicesIds)
          Return the devices with given identifiers.
 ModelDevice getDeviceWhereCapabilityIsDefined(ModelDevice rootDevice, String name)
          Return a ModelDevice, found iterating a ModelDevice hierarchy, defining the given capability.
protected  ModelDevice getGenericDevice()
           
 String getGroupByCapability(String capabilityName)
          Return the group in which a capability is defined.
 String getVersion()
          Returns the version of backed WURFL repository.
 boolean isCapabilityDefined(String capability)
          Return if a capability is defined by the held ModelDevices.
 boolean isDeviceDefined(String deviceId)
          Return if this model define ModelDevice with given id.
 boolean isGroupDefined(String groupId)
          Return if a group is defined by this model.
 int size()
          Return the size (number of held devices) of this model.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultWURFLModel

public DefaultWURFLModel(WURFLResource root)
Build a model by WURFLResource.

Parameters:
root - resource represents the wurfl main resource.
Throws:
WURFLConsistencyException - if the model is not consistent.

DefaultWURFLModel

public DefaultWURFLModel(WURFLResource root,
                         WURFLResources patches)
Build model by root WURFLResource and patches WURFLResources.

Parameters:
root - resource represents the wurfl main resource.
patches - resources represent the wurfl patches to apply.
Throws:
WURFLConsistencyException - if the model is not consistent.
Method Detail

getVersion

public String getVersion()
Returns the version of backed WURFL repository.

The version string may change by Resource to Resource. For XMLResource the version string is: fileType:filePath:fileVersion where fileType my be Root or Patch.

The version describe all resources loaded by the model, each resource is divided by ";"
ex: Root:/WEB-INF/wurfl.zip:1.2;Patch:/WEB-INF/patch_spv.xml:1.4;Patch:/WEB-INF/patch_web_browser.xml:1.0

Specified by:
getVersion in interface WURFLModel
Returns:
String representing version of underlying WURFL repository.

getDeviceById

public ModelDevice getDeviceById(String id)
                          throws DeviceNotDefinedException
Description copied from interface: WURFLModel
Returns ModelDevice by his id.

Specified by:
getDeviceById in interface WURFLModel
Parameters:
id - The identifier of requested device
Returns:
ModelDevice identified by id.
Throws:
DeviceNotDefinedException - If this model do not manage the device with given id.

getDevices

public Set getDevices(Set devicesIds)
               throws DeviceNotDefinedException
Description copied from interface: WURFLModel
Return the devices with given identifiers.

Specified by:
getDevices in interface WURFLModel
Parameters:
devicesIds - The identifiers of the devices to retrieve.
Returns:
Set of ModelDevice
Throws:
DeviceNotDefinedException - If a device with the passed identifier is not defined in this model.

getAllDevices

public Set getAllDevices()
Description copied from interface: WURFLModel
Return all defined devices.

Specified by:
getAllDevices in interface WURFLModel
Returns:
Set of ModelDevice

getAllDevicesId

public Set getAllDevicesId()
Description copied from interface: WURFLModel
Return all defined devices identifiers.

Specified by:
getAllDevicesId in interface WURFLModel
Returns:
Set of string representing the devices identifier.

getDeviceHierarchy

public List getDeviceHierarchy(ModelDevice device)
                        throws DeviceNotInModelException
Description copied from interface: WURFLModel
Returns device hierarchy.

A hierarchy is a ordered list of ModelDevice instances, starting form generic to device.

  Generic -> ... -> device
 

Specified by:
getDeviceHierarchy in interface WURFLModel
Parameters:
device - The device to get hierarchy.
Returns:
A List of ModelDevice representing the device's hierarchy.
Throws:
DeviceNotInModelException

getDeviceFallback

public ModelDevice getDeviceFallback(ModelDevice device)
                              throws DeviceNotInModelException
Description copied from interface: WURFLModel
Return the device's fallback.

Specified by:
getDeviceFallback in interface WURFLModel
Parameters:
device - The device to get fallback.
Returns:
A ModelDevice fallback of given device.
Throws:
DeviceNotInModelException - If the given device is not held by this model.

getDeviceAncestor

public ModelDevice getDeviceAncestor(ModelDevice device)
                              throws DeviceNotInModelException
Description copied from interface: WURFLModel
Return a ModelDevice ancestor.

The ancestor is the first root device found iterating over the device hierarchy, from root to generic.

Specified by:
getDeviceAncestor in interface WURFLModel
Parameters:
device - The device from get the ancestor.
Returns:
The root target device parent.
Throws:
DeviceNotInModelException

isDeviceDefined

public boolean isDeviceDefined(String deviceId)
Description copied from interface: WURFLModel
Return if this model define ModelDevice with given id.

Specified by:
isDeviceDefined in interface WURFLModel
Parameters:
deviceId - The identifier to probe.
Returns:
True if the device is defined, false otherwise.

size

public int size()
Description copied from interface: WURFLModel
Return the size (number of held devices) of this model.

Specified by:
size in interface WURFLModel
Returns:
The size of this model.

getAllGroups

public Set getAllGroups()
Description copied from interface: WURFLModel
Return all defined group's identifiers.

Specified by:
getAllGroups in interface WURFLModel

isGroupDefined

public boolean isGroupDefined(String groupId)
Description copied from interface: WURFLModel
Return if a group is defined by this model.

Specified by:
isGroupDefined in interface WURFLModel
Parameters:
groupId - The group to probe.
Returns:
true if the held ModelDevices definig the given group.

getGroupByCapability

public String getGroupByCapability(String capabilityName)
                            throws CapabilityNotDefinedException
Description copied from interface: WURFLModel
Return the group in which a capability is defined.

Specified by:
getGroupByCapability in interface WURFLModel
Parameters:
capabilityName - The capability to find group for.
Returns:
The capability parent group identifier.
Throws:
CapabilityNotDefinedException - If the given capability is not defined by this model.

getAllCapabilities

public Set getAllCapabilities()
Description copied from interface: WURFLModel
Return all capabilities name defined by held ModelDevices.

Specified by:
getAllCapabilities in interface WURFLModel
Returns:
A Set of String containing the capabilities name.

isCapabilityDefined

public boolean isCapabilityDefined(String capability)
Description copied from interface: WURFLModel
Return if a capability is defined by the held ModelDevices.

Specified by:
isCapabilityDefined in interface WURFLModel
Parameters:
capability - The capability to probe.
Returns:
true if the capability is defined, false otherwise.

getCapabilitiesForGroup

public Set getCapabilitiesForGroup(String groupId)
                            throws GroupNotDefinedException
Description copied from interface: WURFLModel
Return the capabilities defined in the given group.

Specified by:
getCapabilitiesForGroup in interface WURFLModel
Parameters:
groupId - The identifier of group to get capabilities from.
Returns:
A Set of capabilities identifiers.
Throws:
GroupNotDefinedException - If the given group is not defined by the held ModelDevices.

getDeviceWhereCapabilityIsDefined

public ModelDevice getDeviceWhereCapabilityIsDefined(ModelDevice rootDevice,
                                                     String name)
                                              throws DeviceNotInModelException,
                                                     CapabilityNotDefinedException
Description copied from interface: WURFLModel
Return a ModelDevice, found iterating a ModelDevice hierarchy, defining the given capability.

Specified by:
getDeviceWhereCapabilityIsDefined in interface WURFLModel
Parameters:
rootDevice - The devices to iterate from.
name - The capability to probe.
Returns:
The ModelDevice defining given capability.
Throws:
DeviceNotInModelException - If the device is not held by this model.
CapabilityNotDefinedException - If the capability to probe is not defined by this model.

getGenericDevice

protected ModelDevice getGenericDevice()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 WURFL-Pro srl. All Rights Reserved.