Skip to content

Commit

Permalink
Bug 459781 - Customizable authentication & authorization
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
edgarmueller committed Mar 23, 2015
1 parent 425b8e4 commit 8f8b7fa
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*
* Contributors:
* Otto von Wesendonk - initial API and implementation
******************************************************************************/
Expand All @@ -21,9 +21,9 @@
* It wraps a {@link IConfigurationElement} for convenience purposes.
* As {@link ESExtensionPoint} it can be configured to return null or throw an runtime exception
* {@link ESExtensionPointException}
*
*
* @author wesendon
*
*
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class ESExtensionElement {
Expand All @@ -33,7 +33,7 @@ public final class ESExtensionElement {

/**
* Default constructor.
*
*
* @param element element to be wrapped
*/
public ESExtensionElement(final IConfigurationElement element) {
Expand All @@ -42,18 +42,18 @@ public ESExtensionElement(final IConfigurationElement element) {

/**
* Constructor, allowing to set whether exceptions should be thrown instead of returning null.
*
*
* @param element element to be wrapped
* @param throwExceptions if true exceptions are thrown instead of returning null
*/
public ESExtensionElement(final IConfigurationElement element, final boolean throwExceptions) {
this.element = element;
this.exceptionInsteadOfNull = throwExceptions;
exceptionInsteadOfNull = throwExceptions;
}

/**
* Returns the value of the boolean attribute, if existing, or false otherwise.
*
*
* @param name attribute id
* @return Boolean or an {@link ESExtensionPointException} is thrown
*/
Expand All @@ -63,7 +63,7 @@ public Boolean getBoolean(final String name) {

/**
* Returns the value of the boolean attribute, if existing, or given defaultValue otherwise.
*
*
* @param name attribute id
* @param defaultValue the default value
* @return Boolean or an {@link ESExtensionPointException} is thrown
Expand All @@ -78,35 +78,35 @@ public Boolean getBoolean(final String name, final boolean defaultValue) {

/**
* Returns an Integer attribute.
*
*
* @param name attribute id
* @return Integer, null or an {@link ESExtensionPointException} is thrown
*/
public Integer getInteger(final String name) {
try {
return Integer.parseInt(getAttribute(name));
} catch (NumberFormatException e) {
return (Integer) handleErrorOrNull(exceptionInsteadOfNull, e);
} catch (final NumberFormatException e) {
return (Integer) handleErrorOrNull(exceptionInsteadOfNull, e, Messages.ESExtensionPoint_ValueNotFound);
}
}

/**
* Returns an attribute as string.
*
*
* @param name attribute id
* @return String, null or an {@link ESExtensionPointException} is thrown
*/
public String getAttribute(final String name) {
final String attribute = this.element.getAttribute(name);
final String attribute = element.getAttribute(name);
if (attribute == null) {
handleErrorOrNull(exceptionInsteadOfNull, null);
handleErrorOrNull(exceptionInsteadOfNull, null, Messages.ESExtensionPoint_ValueNotFound);
}
return attribute;
}

/**
* Returns a class, or rather the registered instance of this class.
*
*
* @param classAttributeName attribute name of the class attribute
* @param returnType expected class type
* @param <T> type of class
Expand All @@ -115,40 +115,40 @@ public String getAttribute(final String name) {
@SuppressWarnings("unchecked")
public <T> T getClass(final String classAttributeName, final Class<T> returnType) {
try {
Object executableExtension = this.element.createExecutableExtension(classAttributeName);
final Object executableExtension = element.createExecutableExtension(classAttributeName);
if (returnType.isInstance(executableExtension)) {
return (T) executableExtension;
}
return (T) handleErrorOrNull(exceptionInsteadOfNull, null);
} catch (CoreException e) {
return (T) handleErrorOrNull(exceptionInsteadOfNull, e);
return (T) handleErrorOrNull(exceptionInsteadOfNull, null, Messages.ESExtensionPoint_ValueNotFound);
} catch (final CoreException e) {
return (T) handleErrorOrNull(exceptionInsteadOfNull, e, Messages.ESExtensionPoint_ValueNotFound);
}
}

/**
* Returns the wrapped element.
*
*
* @return {@link IConfigurationElement}
*/
public IConfigurationElement getIConfigurationElement() {
return this.element;
return element;
}

/**
* Set wrapper to throw exceptions or otherwise return null.
*
*
* @param throwException if true, exceptions are thrown
*/
public void setThrowException(boolean throwException) {
this.exceptionInsteadOfNull = throwException;
exceptionInsteadOfNull = throwException;
}

/**
* Returns whether exceptions are thrown or null is returned.
*
*
* @return boolean
*/
public boolean getThrowException() {
return this.exceptionInsteadOfNull;
return exceptionInsteadOfNull;
}
}
Loading

0 comments on commit 8f8b7fa

Please sign in to comment.