de.enough.polish.devices
Class PolishComponent

java.lang.Object
  extended by de.enough.polish.devices.PolishComponent
All Implemented Interfaces:
Comparable<PolishComponent>
Direct Known Subclasses:
Bug, Configuration, Device, DeviceGroup, Library, Platform, PolishProject, Vendor

public class PolishComponent
extends Object
implements Comparable<PolishComponent>

Provides common functionalities for PolishProject, Vendor, DeviceGroup and Device.

Copyright Enough Software 2004 - 2011

Author:
Robert Virkus, robert@enough.de

Field Summary
protected  HashMap<String,String> capabilities
           
protected  CapabilityManager capabilityManager
           
protected  String description
           
protected  HashMap<String,Boolean> features
           
protected  String identifier
           
protected  HashMap<String,Boolean> implicitGroupsByName
           
protected  PolishComponent parent
           
protected  boolean supportsPolishGui
           
 
Constructor Summary
PolishComponent(org.jdom.Element definition)
          Creates a new component.
PolishComponent(PolishComponent parent, CapabilityManager capabilityManager, org.jdom.Element definition)
          Creates a new component.
 
Method Summary
 void addCapability(String name, String value)
          Adds a capability to this component.
 void addComponent(PolishComponent component)
          Adds a sub-component to this component, replacing or appending to existing capabilities during the process.
 void addDirectCapability(String name, String value)
          Adds a capability without changing its name to this component.
 void addDirectCapability(Variable capability)
          Adds a capability without changing its name to this component.
 void addDirectFeature(String name)
          Adds a feature without inserting a ".polish" before the feature-name.
 void addFeature(String name)
          Adds a feature this this component.
protected  void addImplicitGroups(String value)
           
 int compareTo(PolishComponent o)
           
 HashMap<String,String> getCapabilities()
          Retrieves all preprocessing-variables of this component and its parent component.
 String getCapability(String name)
          Retrieves a specific capability of this component.
 String getDescription()
          Retrieves the description of this component.
 HashMap<String,Boolean> getFeatures()
          Retrieves all preprocessing-symbols of this component and its parent component.
 String getFeaturesAsString()
          Retrieves the defined features of this component.
 String getIdentifier()
          Retrieves the identifier or name of this component.
 boolean hasFeature(String name)
          Checks if this component has a specific feature.
protected  void loadCapabilities(org.jdom.Element definition, String componentName, String fileName)
          Loads all found capabilities of this component.
protected  String[] loadGroups(org.jdom.Element definition, DeviceGroupManager groupManager, String invalidGroupMessage)
          Loads all groups to which this component belongs to and sets the capabilities accordingly.
protected  void removeComponent(PolishComponent component)
          Removes a component:
protected  String stripText(String string)
          Converts new lines, tabs and successive whitespace to a single whitespace.
 boolean supportsPolishGui()
          Determines whether this device supports the polish-gui-framework.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

identifier

protected String identifier

parent

protected PolishComponent parent

supportsPolishGui

protected boolean supportsPolishGui

features

protected HashMap<String,Boolean> features

capabilities

protected HashMap<String,String> capabilities

capabilityManager

protected CapabilityManager capabilityManager

implicitGroupsByName

protected final HashMap<String,Boolean> implicitGroupsByName

description

protected String description
Constructor Detail

PolishComponent

public PolishComponent(org.jdom.Element definition)
Creates a new component.

Parameters:
definition - the XML definition, can be null

PolishComponent

public PolishComponent(PolishComponent parent,
                       CapabilityManager capabilityManager,
                       org.jdom.Element definition)
Creates a new component.

Parameters:
parent - the parent, e.g. is the parent of a vendor a project, the parent of a device is a vendor.
capabilityManager - knows about how to deal with capabilities
definition - the XML definition, can be null
Method Detail

stripText

protected String stripText(String string)
Converts new lines, tabs and successive whitespace to a single whitespace.

Parameters:
string - the string to strip. May be null.
Returns:
the striped string or null if the parameter was null.

loadCapabilities

protected void loadCapabilities(org.jdom.Element definition,
                                String componentName,
                                String fileName)
                         throws InvalidComponentException
Loads all found capabilities of this component.

Parameters:
definition - The xml definition.
componentName - The name of the component, e.g. "Nokia/3650" for a device.
fileName - The name of the source-file, e.g. "devices.xml".
Throws:
InvalidComponentException - when the defintion contains errors.

loadGroups

protected String[] loadGroups(org.jdom.Element definition,
                              DeviceGroupManager groupManager,
                              String invalidGroupMessage)
                       throws InvalidComponentException
Loads all groups to which this component belongs to and sets the capabilities accordingly.

Parameters:
definition - the xml definition
groupManager - the manager of groups
invalidGroupMessage - the message for the InvalidComponentException when a group name is not valid. {0} is for the identifier, {1} for the group name.
Returns:
an array of strings with the names of the groups, null when no groups are used
Throws:
InvalidComponentException - when a group name is not valid

addComponent

public void addComponent(PolishComponent component)
Adds a sub-component to this component, replacing or appending to existing capabilities during the process.

Parameters:
component - The component which definitions should be added

removeComponent

protected void removeComponent(PolishComponent component)
Removes a component:

Parameters:
component -

getFeatures

public HashMap<String,Boolean> getFeatures()
Retrieves all preprocessing-symbols of this component and its parent component. The symbols are arranged in a HashMap, so one can check for the definition of a symbol with if (map.get( "symbol-name") != null) { // symbol is defined.

Symbols can be retrieved in different ways:

Returns:
the HashMap containing all names of the defined symbols as keys.

getCapabilities

public HashMap<String,String> getCapabilities()
Retrieves all preprocessing-variables of this component and its parent component. The values defined by a variable can be retrieved by calling String value = (String) map.get("variable-name").

Variables which are defined in the device-database all start with "polish.":

Returns:
a HashMap containing all names of the defined variables as the keys.

addCapability

public void addCapability(String name,
                          String value)
Adds a capability to this component.

Parameters:
name - the name of the capability
value - the value of the capability

addImplicitGroups

protected void addImplicitGroups(String value)
Parameters:
value -

addDirectCapability

public void addDirectCapability(Variable capability)
Adds a capability without changing its name to this component.

Parameters:
capability - The capability which should be added

addDirectCapability

public void addDirectCapability(String name,
                                String value)
Adds a capability without changing its name to this component.

Parameters:
name - The name of the capability.
value - The value of the capability.

addFeature

public void addFeature(String name)
Adds a feature this this component.

Parameters:
name - the name of the feature

addDirectFeature

public void addDirectFeature(String name)
Adds a feature without inserting a ".polish" before the feature-name.

Parameters:
name - The feature which should be added.

hasFeature

public boolean hasFeature(String name)
Checks if this component has a specific feature. A feature is a capability without a value.

Parameters:
name - the feature which should be defined, e.g. "hardware.camera"
Returns:
true when this feature is defined.

supportsPolishGui

public boolean supportsPolishGui()
Determines whether this device supports the polish-gui-framework. Usually this is the case when the device meets some capabilities like the bits per pixel and the possible size of the heap. Devices can also define this directly by setting the attribute [supportsPolishGui].

Returns:
true when this device supports the polish-gui.

getCapability

public String getCapability(String name)
Retrieves a specific capability of this component.

Parameters:
name - the name of the capability.
Returns:
the value of the capability or null when the given capability is not defined.

getIdentifier

public String getIdentifier()
Retrieves the identifier or name of this component.

Returns:
The identifier of this component, e.g. "Nokia".

getDescription

public String getDescription()
Retrieves the description of this component.

Returns:
the description or null, when none has been defined

getFeaturesAsString

public String getFeaturesAsString()
Retrieves the defined features of this component.

Returns:
the comma separated features which have been set in the appropriate component.xml file

compareTo

public int compareTo(PolishComponent o)
Specified by:
compareTo in interface Comparable<PolishComponent>

toString

public String toString()
Overrides:
toString in class Object