org.apache.felix.metatype.internal
Class LocalizedObjectClassDefinition

java.lang.Object
  extended by org.apache.felix.metatype.internal.LocalizedObjectClassDefinition
All Implemented Interfaces:
ObjectClassDefinition

public class LocalizedObjectClassDefinition
extends Object
implements ObjectClassDefinition

The LocalizedObjectClassDefinition class is the implementation of the ObjectClassDefinition interface. This class delegates calls to the underlying OCD localizing the results of the following methods: getName(), getDescription(), and getIcon(int).

Author:
fmeschbe

Field Summary
 
Fields inherited from interface org.osgi.service.metatype.ObjectClassDefinition
ALL, OPTIONAL, REQUIRED
 
Constructor Summary
LocalizedObjectClassDefinition(Bundle bundle, OCD ocd, Resources resources)
          Creates and instance of this localizing facade.
 
Method Summary
 AttributeDefinition[] getAttributeDefinitions(int filter)
          Return the attribute definitions for this object class.
 String getDescription()
          Return a description of this object class.
 InputStream getIcon(int size)
          Return an InputStream object that can be used to create an icon from.
 String getID()
          Return the id of this object class.
 String getName()
          Return the name of this object class.
protected  Resources getResources()
          Returns the Resources assigned to this instance.
protected  String localize(String string)
          Localizes the string using the ResourceBundle set on this instance if string starts with the percent character (%).
protected  String[] localize(String[] strings)
          Calls localize(String) for each string in the array and returns an array of the resulting localized strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizedObjectClassDefinition

public LocalizedObjectClassDefinition(Bundle bundle,
                                      OCD ocd,
                                      Resources resources)
Creates and instance of this localizing facade.

Parameters:
bundle - The Bundle providing this object class definition.
ocd - The OCD to which calls are delegated.
resources - The Resources used to localize return values of localizable methods.
Method Detail

getAttributeDefinitions

public AttributeDefinition[] getAttributeDefinitions(int filter)
Description copied from interface: ObjectClassDefinition
Return the attribute definitions for this object class.

Return a set of attributes. The filter parameter can distinguish between ALL,REQUIRED or the OPTIONAL attributes.

Specified by:
getAttributeDefinitions in interface ObjectClassDefinition
Parameters:
filter -
Returns:
An array of attribute definitions or null if no attributes are selected
See Also:
ObjectClassDefinition.getAttributeDefinitions(int)

getDescription

public String getDescription()
Description copied from interface: ObjectClassDefinition
Return a description of this object class. The description may be localized.

Specified by:
getDescription in interface ObjectClassDefinition
Returns:
The description of this object class.
See Also:
ObjectClassDefinition.getDescription()

getIcon

public InputStream getIcon(int size)
                    throws IOException
Description copied from interface: ObjectClassDefinition
Return an InputStream object that can be used to create an icon from.

Indicate the size and return an InputStream object containing an icon. The returned icon maybe larger or smaller than the indicated size.

The icon may depend on the localization.

Specified by:
getIcon in interface ObjectClassDefinition
Parameters:
size -
Returns:
An InputStream representing an icon or null
Throws:
IOException
See Also:
ObjectClassDefinition.getIcon(int)

getID

public String getID()
Description copied from interface: ObjectClassDefinition
Return the id of this object class.

ObjectDefintion objects share a global namespace in the registry. They share this aspect with LDAP/X.500 attributes. In these standards the OSI Object Identifier (OID) is used to uniquely identify object classes. If such an OID exists, (which can be requested at several standard organisations and many companies already have a node in the tree) it can be returned here. Otherwise, a unique id should be returned which can be a java class name (reverse domain name) or generated with a GUID algorithm. Note that all LDAP defined object classes already have an OID associated. It is strongly advised to define the object classes from existing LDAP schemes which will give the OID for free. Many such schemes exist ranging from postal addresses to DHCP parameters.

Specified by:
getID in interface ObjectClassDefinition
Returns:
The id of this object class.
See Also:
ObjectClassDefinition.getID()

getName

public String getName()
Description copied from interface: ObjectClassDefinition
Return the name of this object class. The name may be localized.

Specified by:
getName in interface ObjectClassDefinition
Returns:
The name of this object class.
See Also:
ObjectClassDefinition.getName()

getResources

protected Resources getResources()
Returns the Resources assigned to this instance.


localize

protected String[] localize(String[] strings)
Calls localize(String) for each string in the array and returns an array of the resulting localized strings. If strings is null null is returned.

Parameters:
strings - An array of non-null strings to localize.
Returns:
null if strings is null or an array of the same size as the strings array containing localized strings.

localize

protected String localize(String string)
Localizes the string using the ResourceBundle set on this instance if string starts with the percent character (%). If the string is null, does not start with a percent character or the resource whose key is the string without the leading the percent character is not found the string is returned without the leading percent character.

Examples of different localizations:

string Key Resource Result
null - - null
sample - - sample
%sample sample - sample
%sample sample resource resource

Parameters:
string - The string to localize
Returns:
The localized string


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.