public Object getObjectValue(final String key, final boolean mandatory) { Object value = configuration.get(key); if ((value == null) && mandatory) { throw new ComponentException("The value of the mandatory configuration property '" + key + "' is not defined."); } return value; }
public Invalid(ComponentException e) { this.message = e.getMessage(); }
scp.modify(newProps); } catch (ComponentException e) { Activator.log(null, LogService.LOG_ERROR, e.getMessage(), e.getCause()); throw e; } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_MODIFYING_COMPONENT, scp.serviceComponent), t); throw new ComponentException(NLS.bind(Messages.ERROR_MODIFYING_COMPONENT, scp.serviceComponent), t); } finally {
scp.modify(newProps); } catch (ComponentException e) { Activator.log(null, LogService.LOG_ERROR, e.getMessage(), e.getCause()); throw e; } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_MODIFYING_COMPONENT, scp.serviceComponent), t); throw new ComponentException(NLS.bind(Messages.ERROR_MODIFYING_COMPONENT, scp.serviceComponent), t); } finally {
private void assertCreateSingleInstance() { if (!serviceComponent.serviceFactory && !instances.isEmpty()) { throw new ComponentException(NLS.bind(Messages.INSTANCE_ALREADY_CREATED, name)); } }
} catch (ClassCircularityError e) { processSCPInClassCircularityError(scp); throw new ComponentException(NLS.bind(Messages.ERROR_BUILDING_COMPONENT_INSTANCE, scp.serviceComponent), e); } catch (ComponentException e) { Activator.log(null, LogService.LOG_ERROR, e.getMessage(), e.getCause()); Throwable t = e.getCause(); if (t instanceof InvocationTargetException) { Throwable cause = t.getCause(); } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_BUILDING_COMPONENT_INSTANCE, scp.serviceComponent), t); throw new ComponentException(NLS.bind(Messages.ERROR_BUILDING_COMPONENT_INSTANCE, scp.serviceComponent), t); } finally {
public Invalid(ComponentException e) { this.message = e.getMessage(); }
private void assertCreateSingleInstance() { if (!serviceComponent.serviceFactory && !instances.isEmpty()) { throw new ComponentException(NLS.bind(Messages.INSTANCE_ALREADY_CREATED, name)); } }
} catch (ClassCircularityError e) { processSCPInClassCircularityError(scp); throw new ComponentException(NLS.bind(Messages.ERROR_BUILDING_COMPONENT_INSTANCE, scp.serviceComponent), e); } catch (ComponentException e) { Activator.log(null, LogService.LOG_ERROR, e.getMessage(), e.getCause()); Throwable t = e.getCause(); if (t instanceof InvocationTargetException) { Throwable cause = t.getCause(); } catch (Throwable t) { Activator.log(null, LogService.LOG_ERROR, NLS.bind(Messages.ERROR_BUILDING_COMPONENT_INSTANCE, scp.serviceComponent), t); throw new ComponentException(NLS.bind(Messages.ERROR_BUILDING_COMPONENT_INSTANCE, scp.serviceComponent), t); } finally {
private int getMinimumCardinality(Map<String, Object> properties) { Integer minimumCardinality = null; try { minimumCardinality = Coercions.coerceToInteger( properties.get(m_dependencyMetadata.getMinCardinalityName())); } catch (ComponentException e) { m_componentManager.getLogger().log(LogService.LOG_WARNING, "Invalid minimum cardinality property for dependency {0}: {1}", null, getName(), e.getMessage()); } if (minimumCardinality != null && (minimumCardinality < defaultMinimumCardinality(m_dependencyMetadata) || (!m_dependencyMetadata.isMultiple() && minimumCardinality > 1))) { minimumCardinality = null; } if (minimumCardinality == null) { minimumCardinality = defaultMinimumCardinality(m_dependencyMetadata); } return minimumCardinality; }
private static Object firstArrayElement(Object o, Object defaultValue) { if ( o == null || !o.getClass().isArray() ) { throw new ComponentException( "Not an array: " + o ); } if ( Array.getLength( o ) == 0 ) { return defaultValue; } return Array.get( o, 0 ); }
private int getMinimumCardinality(Map<String, Object> properties) { Integer minimumCardinality = null; try { minimumCardinality = Coercions.coerceToInteger( properties.get(m_dependencyMetadata.getMinCardinalityName())); } catch (ComponentException e) { m_componentManager.getLogger().log(LogService.LOG_WARNING, "Invalid minimum cardinality property for dependency {0}: {1}", null, getName(), e.getMessage()); } if (minimumCardinality != null && (minimumCardinality < defaultMinimumCardinality(m_dependencyMetadata) || (!m_dependencyMetadata.isMultiple() && minimumCardinality > 1))) { minimumCardinality = null; } if (minimumCardinality == null) { minimumCardinality = defaultMinimumCardinality(m_dependencyMetadata); } return minimumCardinality; }
private static Object firstCollectionElement(Object raw, Object defaultValue) { if ( !( raw instanceof Collection ) ) { throw new ComponentException( "Not a collection: " + raw ); } Collection<?> c = (Collection<?>) raw; if ( c.isEmpty() ) { return defaultValue; } return c.iterator().next(); }
private static Object firstArrayElement(Object o, Object defaultValue) { if ( o == null || !o.getClass().isArray() ) { throw new ComponentException( "Not an array: " + o ); } if ( Array.getLength( o ) == 0 ) { return defaultValue; } return Array.get( o, 0 ); }
private static Object firstCollectionElement(Object raw, Object defaultValue) { if ( !( raw instanceof Collection ) ) { throw new ComponentException( "Not a collection: " + raw ); } Collection<?> c = (Collection<?>) raw; if ( c.isEmpty() ) { return defaultValue; } return c.iterator().next(); }
/** * This method will instantiate the implementation class! * * @return instance of the component implementation class. If the components * exports some services, the implementation must implement all of * them * @throws Exception * is thrown if the implementation cannot be instantiated for * some reasons. */ final Object createInstance() throws Exception { try { return bundle.loadClass(implementation).newInstance(); } catch (Throwable t) { throw new ComponentException(NLS.bind(Messages.EXCEPTION_CREATING_COMPONENT_INSTANCE, this), t); } }
/** * This method will instantiate the implementation class! * * @return instance of the component implementation class. If the components * exports some services, the implementation must implement all of * them * @throws Exception * is thrown if the implementation cannot be instantiated for * some reasons. */ final Object createInstance() throws Exception { try { return bundle.loadClass(implementation).newInstance(); } catch (Throwable t) { throw new ComponentException(NLS.bind(Messages.EXCEPTION_CREATING_COMPONENT_INSTANCE, this), t); } }
public void applyValue(final String key, final Object value, final Class<?> valueType) { String[] keyParts = key.split("\\."); Object currentBuilderObject = builder; try { for (int i = 0, n = keyParts.length; i < n; i++) { if (i < (n - 1)) { Method method = currentBuilderObject.getClass().getMethod(keyParts[i]); currentBuilderObject = method.invoke(currentBuilderObject); } else { Method method = currentBuilderObject.getClass().getMethod(keyParts[i], valueType); method.invoke(currentBuilderObject, value); } } } catch (NoSuchMethodException e) { throw new ComponentException("Could not set configuration with key " + key, e); } catch (SecurityException e) { throw new ComponentException("Could not set configuration with key " + key, e); } catch (IllegalAccessException e) { throw new ComponentException("Could not set configuration with key " + key, e); } catch (IllegalArgumentException e) { throw new ComponentException("Could not set configuration with key " + key, e); } catch (InvocationTargetException e) { throw new ComponentException("Could not set configuration with key " + key, e); } }
/** * Returns a <code>ComponentException</code> for this component with the * given explanation for failure. * * @param reason The explanation for failing to validate this component. */ ComponentException validationFailure( String reason ) { return new ComponentException( "Component " + getName() + " validation failed: " + reason ); } }
/** * Returns a <code>ComponentException</code> for this component with the * given explanation for failure. * * @param reason The explanation for failing to validate this component. */ ComponentException validationFailure( String reason ) { return new ComponentException( "Component " + getName() + " validation failed: " + reason ); } }