org.eclipse.emf.emfstore.common.extensionpoint
Class ESExtensionPoint

java.lang.Object
  extended by org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPoint

public final class ESExtensionPoint
extends Object

This class is a convenience wrapper for eclipse extension points. It can be configured to return null if a value can't be found, but also to throw Exceptions. The latter normally requires a catch block but you don't have to null check.

Author:
wesendon

Constructor Summary
ESExtensionPoint(String id)
          Default constructor.
ESExtensionPoint(String id, boolean throwException)
          Constructor with option of set the throw exception option.
ESExtensionPoint(String id, boolean throwException, Comparator<ESExtensionElement> comparator)
          Constructor with option of set the throw exception option.
 
Method Summary
 String getAttribute(String name)
          Gets an attribute in form of a string from the element with highest priority ( getElementWithHighestPriority(), default getFirst()).
 Boolean getBoolean(String name)
          Returns the value of the boolean attribute, if existing, or given false otherwise, from the element with highest priority (getElementWithHighestPriority(), default getFirst()).
 Boolean getBoolean(String name, boolean defaultValue)
          Returns the value of the boolean attribute, if existing, or given defaultValue otherwise, from the element with highest priority (getElementWithHighestPriority(), default getFirst()).
<T> T
getClass(String classAttributeName, Class<T> returnType)
          Gets a class from the element with highest priority (getElementWithHighestPriority(), default getFirst()).
 ESExtensionElement getElementWithHighestPriority()
          Returns the element with highest priority, by default getFirst() is used.
 List<ESExtensionElement> getExtensionElements()
          Returns the wrapped extension elements.
 ESExtensionElement getFirst()
          Returns the first ESExtensionElement in the list.
 String getId()
          Returns the ID of the extension point.
 Integer getInteger(String name)
          Gets a Integer from the element with highest priority (getElementWithHighestPriority(), default getFirst()).
 void reload()
          Reloads extensions from the registry.
 void setComparator(Comparator<ESExtensionElement> comparator)
          Set a custom comparator which defines the order of the ESExtensionElement.
 ESExtensionPoint setThrowException(boolean b)
          Set whether null should be returned or exception should be thrown by this class.
 int size()
          Returns the number of ESExtensionElement.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ESExtensionPoint

public ESExtensionPoint(String id)
Default constructor.

Parameters:
id - extension point id

ESExtensionPoint

public ESExtensionPoint(String id,
                        boolean throwException)
Constructor with option of set the throw exception option.

Parameters:
id - extension point id
throwException - if true, an ESExtensionPointException is thrown instead of returning null

ESExtensionPoint

public ESExtensionPoint(String id,
                        boolean throwException,
                        Comparator<ESExtensionElement> comparator)
Constructor with option of set the throw exception option.

Parameters:
id - extension point id
throwException - if true, an ESExtensionPointException is thrown instead of returning null
comparator - the comparator which defines the order of the ESExtensionElements
Since:
1.1
Method Detail

reload

public void reload()
Reloads extensions from the registry.


getClass

public <T> T getClass(String classAttributeName,
                      Class<T> returnType)
Gets a class from the element with highest priority (getElementWithHighestPriority(), default getFirst()). Or rather the registered instance of that class.

Type Parameters:
T - the type of the class
Parameters:
classAttributeName - class attribute name
returnType - Class of expected return value
Returns:
the result or either null, or an runtime exception is thrown in the case of setThrowException(boolean) is true.

getBoolean

public Boolean getBoolean(String name)
Returns the value of the boolean attribute, if existing, or given false otherwise, from the element with highest priority (getElementWithHighestPriority(), default getFirst()).

Parameters:
name - attribute id
Returns:
the result or either null, or an runtime exception is thrown in the case of setThrowException(boolean) is true.

getBoolean

public Boolean getBoolean(String name,
                          boolean defaultValue)
Returns the value of the boolean attribute, if existing, or given defaultValue otherwise, from the element with highest priority (getElementWithHighestPriority(), default getFirst()).

Parameters:
name - attribute id
defaultValue - the default value if attribute does not exist
Returns:
the result or either null, or an runtime exception is thrown in the case of setThrowException(boolean) is true.

getInteger

public Integer getInteger(String name)
Gets a Integer from the element with highest priority (getElementWithHighestPriority(), default getFirst()).

Parameters:
name - attribute id
Returns:
the result or either null, or an runtime exception is thrown in the case of setThrowException(boolean) is true.

getAttribute

public String getAttribute(String name)
Gets an attribute in form of a string from the element with highest priority ( getElementWithHighestPriority(), default getFirst()).

Parameters:
name - attribute id
Returns:
the result or either null, or an runtime exception is thrown in the case of setThrowException(boolean) is true.

getElementWithHighestPriority

public ESExtensionElement getElementWithHighestPriority()
Returns the element with highest priority, by default getFirst() is used. This method is intended to be overriden in order to modify default behavior.

Returns:
ESExtensionElement

setComparator

public void setComparator(Comparator<ESExtensionElement> comparator)
Set a custom comparator which defines the order of the ESExtensionElement.

Parameters:
comparator - the comparator

getFirst

public ESExtensionElement getFirst()
Returns the first ESExtensionElement in the list.

Returns:
ESExtensionElement, null or a ESExtensionPointException is thrown, depending on your config ( setThrowException(boolean)

getExtensionElements

public List<ESExtensionElement> getExtensionElements()
Returns the wrapped extension elements.

Returns:
list of ESExtensionElement

setThrowException

public ESExtensionPoint setThrowException(boolean b)
Set whether null should be returned or exception should be thrown by this class.

Parameters:
b - true to throw exceptions
Returns:
returns this, in order to allow chaining method calls

size

public int size()
Returns the number of ESExtensionElement.

Returns:
size

getId

public String getId()
Returns the ID of the extension point.

Returns:
the ID of the extension point


Copyright © 2015. All Rights Reserved.