private TargetDatabaseMapper getTargetDBMapper() { if (targetDBMapper == null) throw new ConfigurationError("'target' is undefined. " + "Use MemKeyMapper.setTarget() to register the target database"); return targetDBMapper; }
@Override public byte[] convert(String sourceValue) throws ConversionException { try { return sourceValue.getBytes(encoding); } catch (UnsupportedEncodingException e) { throw new ConfigurationError(e); } }
@Override public String convert(byte[] target) throws ConversionException { try { return new String(target, encoding); } catch (UnsupportedEncodingException e) { throw new ConfigurationError(e); } }
public static void close(Statement statement) { if (statement != null) { try { statement.close(); } catch (SQLException e) { throw new ConfigurationError("Closing statement failed", e); } } }
static ScriptFactory getFactory(String engineId, boolean required) { ScriptFactory factory = factories.get(engineId); if (factory == null && required) throw new ConfigurationError("Not a supported script engine: " + engineId); return factory; }
public static Object getFieldValue(Field field, Object target, boolean strict) { try { if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) return field.get(null); else return field.get(target); } catch (IllegalArgumentException e) { throw new ConfigurationError(e); } catch (IllegalAccessException e) { throw new ConfigurationError(e); } }
private static Method getReadMethod(PropertyDescriptor descriptor, Object bean, boolean strict) { Method readMethod = descriptor.getReadMethod(); if (readMethod == null) if (strict) throw new ConfigurationError("No reader for property '" + descriptor.getName() + "' found in class " + bean.getClass()); else return null; return readMethod; }
public static <C, I> Type[] getGenericInterfaceParams(Class<C> checkedClass, Class<I> searchedInterface) { for (Type type : checkedClass.getGenericInterfaces()) { ParameterizedType pt = (ParameterizedType) type; if (searchedInterface.equals(pt.getRawType())) return pt.getActualTypeArguments(); } if (!Object.class.equals(checkedClass.getSuperclass())) return getGenericInterfaceParams(checkedClass.getSuperclass(), searchedInterface); throw new ConfigurationError(checkedClass + " does not implement interface with generic parameters: " + searchedInterface); }
public LocalDiffType(DiffDetailType type, String locator) { if (StringUtil.isEmpty(locator) && type == null) throw new ConfigurationError("At least one of the argument 'locator' and 'type' must be not empty"); this.locator = locator; this.type = type; }
protected static void checkAttributes(Element element, Set<String> supportedAttributes) { for (Map.Entry<String, String> attribute : XMLUtil.getAttributes(element).entrySet()) { if (!supportedAttributes.contains(attribute.getKey())) throw new ConfigurationError("Not a supported import attribute: " + attribute.getKey()); } }
public static <T> T findSingleMatch(Collection<T> candidates, Filter<T> filter) { T result = null; for (T candidate : candidates) if (filter.accept(candidate)) { if (result == null) result = candidate; else throw new ConfigurationError("Found multiple matches: " + candidates); } return result; }
public DataIterator<String> iterator() { try { return new CSVCellIterator(uri, separator, encoding); } catch (Exception e) { throw new ConfigurationError(e); } }
private void parseReservedWords(String resourceName) { logger.debug("reading reserved word from config file " + resourceName); try { for (String word : IOUtil.readTextLines(resourceName, false)) reservedWords.add(word.trim()); } catch (IOException e) { throw new ConfigurationError("Error reading file " + resourceName, e); } }
public static Object getPropertyValue(Object bean, String propertyName, boolean propertyRequired) { PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), propertyName); if (descriptor == null) { if (propertyRequired) throw new ConfigurationError("Property '" + propertyName + "' not found in class " + bean.getClass()); else return null; } return getPropertyValue(bean, descriptor); }
public static Connection connectInMemoryDB(String dbName) throws ConnectFailedException { String driver = DRIVER; try { Class.forName(driver); String url = getInMemoryURL(dbName); String user = DEFAULT_USER; String password = DEFAULT_PASSWORD; return DBUtil.connect(url, DRIVER, user, password, false); } catch (ClassNotFoundException e) { throw new ConfigurationError("JDBC driver not found: " + driver, e); } }
public static JDBCConnectData getConnectData(String environment) { try { String path = environmentFileName(environment); return JDBCConnectData.parseSingleDbProperties(path); } catch (IOException e) { throw new ConfigurationError("Error reading environment data for '" + environment + "'"); } }
@Override public Converter convert(String sourceValue) throws ConversionException { if (StringUtil.isEmpty(sourceValue)) return null; Object result = BeanUtil.newInstance(sourceValue); if (result instanceof Format) return new ParseFormatConverter(Object.class, (Format) result, false); else if (result instanceof Converter) return (Converter) result; else throw new ConfigurationError("Class is neither Converter nor Format: " + result.getClass()); }
private void setTarget(Connection target, String targetDbId) { if (targetDBMapper == null) targetDBMapper = new TargetDatabaseMapper(this, target, targetDbId, database); else if (!(targetDBMapper.getDbId()).equals(targetDbId)) throw new ConfigurationError("'target' has already been set to a different database: " + targetDBMapper.getDbId()); }
public static Document parse(String uri, boolean namespaceAware, EntityResolver resolver, String schemaUri, ClassLoader classLoader) throws IOException { InputStream stream = null; try { stream = IOUtil.getInputStreamForURI(uri); return parse(stream, namespaceAware, resolver, schemaUri, classLoader, DEFAULT_ERROR_HANDLER); } catch (ConfigurationError e) { throw new ConfigurationError("Error parsing " + uri, e); } finally { IOUtil.close(stream); } }
private void readConfigFile(String filename) throws IOException { ReaderLineIterator iterator = new ReaderLineIterator(IOUtil.getReaderForURI(filename)); try { while (iterator.hasNext()) { String className = iterator.next(); registerConverterClass((Class<? extends Converter>) Class.forName(className)); } } catch (ClassNotFoundException e) { throw new ConfigurationError(e); } finally { iterator.close(); } }