Refine search
@Activate protected void activate(ComponentContext ctx) throws ConfigurationException { Object value =ctx.getProperties().get(PROEPRTY_INDENT); if(value instanceof Number){ indent = ((Number)value).intValue(); } else if(value != null){ try { indent = Integer.parseInt(value.toString()); } catch(NumberFormatException e){ throw new ConfigurationException(PROEPRTY_INDENT, "The parsed indent MUST BE an Integer number (values <= 0 " + "will deactivate pretty format)"); } } else { indent = DEFAULT_INDENT; } } @Deactivate
@SuppressWarnings("unchecked") public LanguageConfiguration(String property, String[] defaultConfig){ if(property == null || property.isEmpty()){ throw new IllegalArgumentException("The parsed property MUST NOT be NULL nor empty!"); } this.property = property; this.defaultConfig = defaultConfig != null ? Arrays.asList(defaultConfig) : Collections.EMPTY_LIST; try { parseConfiguration(this.defaultConfig); } catch (ConfigurationException e) { throw new IllegalArgumentException("Inalied default configuration " + e.getMessage()); } }
private String getAsString(java.nio.ByteBuffer bytes, String marshalType) { String val = null; try { AbstractType abstractType = TypeParser.parse(marshalType); val = abstractType.getString(bytes); } catch (ConfigurationException e) { e.printStackTrace(); } return val; }
public synchronized void updated(String pid, Properties properties) throws ConfigurationException { try { deleted(pid); configurations.put(pid, new ClusteredConfiguration(properties)); } catch (Exception e) { ConfigurationException configurationException = new ConfigurationException(null, "Unable to parse ActiveMQ configuration: " + e.getMessage()); configurationException.initCause(e); throw configurationException; } }
/** * Convenience method for getting settings from a configuration dictionary. */ @SuppressWarnings("unchecked") private String getNotNull(Dictionary settings, String id, String errorMessage) throws ConfigurationException { String result = (String) settings.get(id); if (result == null) { throw new ConfigurationException(id, errorMessage); } return result; }
/** * Check the existence of the given dictionary. Throw an exception if null. */ public static void checkDictionary(Dictionary properties, ComponentContext componentContext) throws ConfigurationException { if (properties == null) { String dicName = componentContext.getProperties().get("service.pid").toString(); throw new ConfigurationException("*", "Dictionary for " + dicName + " does not exist"); } }
loadedConfig.put("xa", Boolean.toString(xa)); loadedConfig.put(Constants.SERVICE_RANKING, getInt(config, Constants.SERVICE_RANKING, 0) + 1000); loadedConfig.put("pax.jdbc.service.id.ref", config.get(Constants.SERVICE_ID)); pdsfFilter = DataSourceConfigManager.getPooledDSFFilter(loadedConfig); } catch (ConfigurationException e) { throw new IllegalArgumentException(e.getMessage(), e);
/** * Initialise the {@link #entitySearcher} based on the value of the * {@link #REFERENCED_SITE_ID} property in the parsed configuration * @param context * @param configuration * @throws ConfigurationException */ protected void activateEntitySearcher(ComponentContext context, Dictionary<String,Object> configuration) throws ConfigurationException { Object value = configuration.get(REFERENCED_SITE_ID); //init the EntitySource if (value == null) { throw new ConfigurationException(REFERENCED_SITE_ID, "The ID of the Referenced Site is a required Parameter and MUST NOT be NULL!"); } referencedSiteName = value.toString(); if (referencedSiteName.isEmpty()) { throw new ConfigurationException(REFERENCED_SITE_ID, "The ID of the Referenced Site is a required Parameter and MUST NOT be an empty String!"); } //TODO: make limit configurable! if(Entityhub.ENTITYHUB_IDS.contains(referencedSiteName.toLowerCase())){ entitySearcher = new EntityhubSearcher(context.getBundleContext(),10); } else { entitySearcher = new ReferencedSiteSearcher(context.getBundleContext(),referencedSiteName,10); } } /**
@Activate protected void activate(ComponentContext ctx) throws ConfigurationException { String folderName = requireProperty(ctx.getProperties(), DATA_FILES_FOLDER_PROP, String.class); dataFilesFolder = new File(folderName); if(!dataFilesFolder.exists()){ if(!dataFilesFolder.mkdirs()){ throw new ConfigurationException(DATA_FILES_FOLDER_PROP, "Unable to create the configured Directory "+dataFilesFolder); } } else if(!dataFilesFolder.isDirectory()){ throw new ConfigurationException(DATA_FILES_FOLDER_PROP, "The configured DataFile directory "+dataFilesFolder+" does already exists but is not a directory!"); } //else exists and is a directory! }
private String getStringProperty(final Map<String, Object> componentProperties, final String propertyName) throws ConfigurationException { Object value = componentProperties.get(propertyName); if (value == null) { throw new ConfigurationException(propertyName, "property not defined"); } return String.valueOf(value); }
static String getPooledDSFFilter(Dictionary<String, Object> config) throws ConfigurationException { String pool = (String) config.remove(PooledDataSourceFactory.POOL_KEY); boolean isXa = isXa(config); if (pool == null) { if (isXa) { throw new ConfigurationException(null, "Can not create XA DataSource without pooling."); } else { return null; } } return andFilter(eqFilter("objectClass", PooledDataSourceFactory.class.getName()), eqFilter("pool", pool), eqFilter("xa", Boolean.toString(isXa))); }
private URL getURL(Dictionary<String, ?> dictionary, String key) throws ConfigurationException { Object value = dictionary.get(key); if (value == null || !(value instanceof String)) { throw new ConfigurationException(key, "Missing property"); } try { return new URL((String) value); } catch (MalformedURLException e) { throw new ConfigurationException(key, "Is not a valid URL", e); } }
@Override protected void doActivate(ComponentContext context) throws Exception { Dictionary<?, ?> properties = context.getProperties(); maxage = PropertiesUtil.toLong(properties.get(PROP_MAX_AGE), -1); if (maxage < 0) { throw new ConfigurationException(PROP_MAX_AGE, "Max Age must be specified and greater than 0."); } }
loadedConfig.put("xa", Boolean.toString(xa)); loadedConfig.put(Constants.SERVICE_RANKING, getInt(config, Constants.SERVICE_RANKING, 0) + 1000); loadedConfig.put("pax.jdbc.service.id.ref", config.get(Constants.SERVICE_ID)); pdsfFilter = DataSourceConfigManager.getPooledDSFFilter(loadedConfig); } catch (ConfigurationException e) { throw new IllegalArgumentException(e.getMessage(), e);
@Activate protected void activate(ComponentContext ctx) throws ConfigurationException { String folderName = requireProperty(ctx.getProperties(), DATA_FILES_FOLDER_PROP, String.class); dataFilesFolder = new File(folderName); if(!dataFilesFolder.exists()){ if(!dataFilesFolder.mkdirs()){ throw new ConfigurationException(DATA_FILES_FOLDER_PROP, "Unable to create the configured Directory "+dataFilesFolder); } } else if(!dataFilesFolder.isDirectory()){ throw new ConfigurationException(DATA_FILES_FOLDER_PROP, "The configured DataFile directory "+dataFilesFolder+" does already exists but is not a directory!"); } //else exists and is a directory! }
@Override public SSLContext getContext() throws ConfigurationException { try { SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init(null, new TrustManager[] { trustManager }, null); return sslContext; } catch (KeyManagementException | NoSuchAlgorithmException e) { logger.warn("SSL configuration failed", e); throw new ConfigurationException("ssl", e.getMessage()); } } }
/** * activator that reads and validates the {@link EnhancementEngine#PROPERTY_NAME} * property from the {@link ComponentContext#getProperties()}. * @param ctx the component context * @throws ConfigurationException if the required property * {@link EnhancementEngine#PROPERTY_NAME} is missing or empty * @throws A to allow sub classes to throw any kind of exception */ @Activate protected void activate(ComponentContext ctx) throws ConfigurationException, A { Object value = ctx.getProperties().get(PROPERTY_NAME); if(value instanceof String){ name = (String)value; if(name.isEmpty()){ name = null; throw new ConfigurationException(PROPERTY_NAME, "The configured" + "name of an EnhancementEngine MUST NOT be empty!"); } } else { throw new ConfigurationException(PROPERTY_NAME, value == null ? "The name is a required property!" : "The name of an EnhancementEngine MUST be an non empty String " + "(type: "+value.getClass()+" value: "+value+")"); } } /**
public synchronized void updated(Dictionary dictionary) throws ConfigurationException { try { if(dictionary != null) { m_serverURL = new URL((String) dictionary.get(DiscoveryConstants.DISCOVERY_URL_KEY)); } } catch (MalformedURLException e) { throw new ConfigurationException(DiscoveryConstants.DISCOVERY_URL_KEY, "Malformed URL", e); } }
@Override protected void doActivate(ComponentContext context) throws Exception { Dictionary<?, ?> properties = context.getProperties(); String time = PropertiesUtil.toString(properties.get(PROP_EXPIRES_TIME), null); if (StringUtils.isBlank(time)) { throw new ConfigurationException(PROP_EXPIRES_TIME, "Expires Time must be specified."); } SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); sdf.setLenient(false); try { Date date = sdf.parse(time); expiresTime.setTime(date); } catch (ParseException ex) { throw new ConfigurationException(PROP_EXPIRES_TIME, "Expires Time must be specified."); } }
private static Properties DEFAULT_PROPERTIES = SomeUtil.getProperties("myclass.properties"); // Put this in a SomeUtil class. public static Properties getProperties(String filename) { Properties properties = new Properties(); try { properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)); } catch (IOException e) { throw new ConfigurationException("Cannot load " + filename, e); } return properties; }