@Override public LocalCategoryMemberDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("live")) { return null; } try { return new LocalCategoryMemberLiveDao(); } catch (DaoException e) { throw new ConfigurationException(e); } } }
public static void main(String[] args) { SRResult s = null; try { Env env = new EnvBuilder().build(); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); Language simple = Language.getByLangCode("simple"); SRMetric sr = conf.get( SRMetric.class, "ensemble", "language", simple.getLangCode()); s = sr.similarity("cat","kitty",true); } catch (ConfigurationException e) { System.out.println("Configuration Exception: "+e.getMessage()); } catch (DaoException e) { System.out.println("Dao Exception: "+e.getMessage()); } System.out.println("The score for this two pages:"+s.getScore()); } }
public static void main(String[] args) { SRResult s = null; try { Env env = new EnvBuilder().build(); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); Language simple = Language.getByLangCode("simple"); SRMetric sr = conf.get( SRMetric.class, "ensemble", "language", simple.getLangCode()); s = sr.similarity("cat","kitty",true); } catch (ConfigurationException e) { System.out.println("Configuration Exception: "+e.getMessage()); } catch (DaoException e) { System.out.println("Dao Exception: "+e.getMessage()); } System.out.println("The score for this two pages:"+s.getScore()); } }
@Override public LocalPageDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("live")) { return null; } try { return new LocalPageLiveDao(); } catch (DaoException e) { throw new ConfigurationException(e); } } }
@Override public LocalLinkDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("live")) { return null; } try { return new LocalLinkLiveDao(); } catch (DaoException e) { throw new ConfigurationException(e); } } }
@Override public RedirectDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("live")) { return null; } try { return new RedirectLiveDao(); } catch (DaoException e) { throw new ConfigurationException(e); } } }
private <T> Pair<Provider, T> constructInternal(Class<T> klass, String name, Config conf, Map<String, String> runtimeParams) throws ConfigurationException { if (!providers.containsKey(klass)) { throw new ConfigurationException("No registered providers for components with class " + klass); } List<Provider> pset = providers.get(klass).providers; for (Provider p : pset) { Object o = p.get(name, conf, runtimeParams); if (o != null) { return Pair.of(p, (T) o); } } throw new ConfigurationException( "None of the " + pset.size() + " providers claimed ownership of component " + "with class " + klass + ", name '" + name + "' and configuration '" + conf + "'" ); }
private <T> Pair<Provider, T> constructInternal(Class<T> klass, String name, Config conf, Map<String, String> runtimeParams) throws ConfigurationException { if (!providers.containsKey(klass)) { throw new ConfigurationException("No registered providers for components with class " + klass); } List<Provider> pset = providers.get(klass).providers; for (Provider p : pset) { Object o = p.get(name, conf, runtimeParams); if (o != null) { return Pair.of(p, (T) o); } } throw new ConfigurationException( "None of the " + pset.size() + " providers claimed ownership of component " + "with class " + klass + ", name '" + name + "' and configuration '" + conf + "'" ); }
@Override public DiagnosticDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { try { File tokenFile = new File(config.getString("tokenFile")); if (!tokenFile.isFile()) { Random random = new Random(); FileUtils.write(tokenFile, "" + Math.abs(random.nextLong())); } String token = FileUtils.readFileToString(tokenFile).trim(); String appId = config.getString("appId"); String restApiId = config.getString("restApiId"); File logFile = new File(config.getString("log")); return new DiagnosticDao(appId, restApiId, token, logFile); } catch (IOException e) { throw new ConfigurationException(e); } } }
@Override public DiagnosticDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { try { File tokenFile = new File(config.getString("tokenFile")); if (!tokenFile.isFile()) { Random random = new Random(); FileUtils.write(tokenFile, "" + Math.abs(random.nextLong())); } String token = FileUtils.readFileToString(tokenFile).trim(); String appId = config.getString("appId"); String restApiId = config.getString("restApiId"); File logFile = new File(config.getString("log")); return new DiagnosticDao(appId, restApiId, token, logFile); } catch (IOException e) { throw new ConfigurationException(e); } } }
private void initScorers() throws ConfigurationException { this.scorers = new ArrayList<AbstractMatchScorer>(); for (Config scorerConfig : config.getConfigList("scorers")) { String type = scorerConfig.getString("type"); if (type.equals("instanceOf")) { scorers.add(new InstanceOfMatchScorer(env, scorerConfig)); } else if (type.equals("wikidataValue")) { scorers.add(new WikidataValueScorer(env, scorerConfig)); } else if (type.equals("contains")) { scorers.add(new ContainsPointScorer(env, scorerConfig)); } else { throw new ConfigurationException("Unknown score type: " + type); } } }
private void initScorers() throws ConfigurationException { this.scorers = new ArrayList<AbstractMatchScorer>(); for (Config scorerConfig : config.getConfigList("scorers")) { String type = scorerConfig.getString("type"); if (type.equals("instanceOf")) { scorers.add(new InstanceOfMatchScorer(env, scorerConfig)); } else if (type.equals("wikidataValue")) { scorers.add(new WikidataValueScorer(env, scorerConfig)); } else if (type.equals("contains")) { scorers.add(new ContainsPointScorer(env, scorerConfig)); } else { throw new ConfigurationException("Unknown score type: " + type); } } }
@Override public MatrixLocalLinkDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("matrix")) { return null; } try { return new MatrixLocalLinkDao( getConfigurator().get( LocalLinkDao.class, config.getString("delegate")), new File(config.getString("path")) ); } catch (DaoException e) { throw new ConfigurationException(e); } } }
/** * Returns the config object associated with the given class and name. * @param klass The generic interface or superclass, not the specific implementation. * @param name The name of the class as it appears in the config file. If name is null, * the configurator tries to guess by looking for a "default" entry in * the config that provides the name for a default implementation or, if * there is exactly one implementation returning it. Otherwise, if name is * null it throws an error. * @return The requested config object. * @throws ConfigurationException */ public Config getConfig(Class klass, String name) throws ConfigurationException { if (!providers.containsKey(klass)) { throw new ConfigurationException("No registered providers for components with class " + klass); } ProviderSet pset = providers.get(klass); name = resolveComponentName(klass, name); String path = pset.path + "." + name; if (!conf.get().hasPath(path)) { throw new ConfigurationException("Configuration path " + path + " does not exist"); } return conf.get().getConfig(path); }
/** * Returns the config object associated with the given class and name. * @param klass The generic interface or superclass, not the specific implementation. * @param name The name of the class as it appears in the config file. If name is null, * the configurator tries to guess by looking for a "default" entry in * the config that provides the name for a default implementation or, if * there is exactly one implementation returning it. Otherwise, if name is * null it throws an error. * @return The requested config object. * @throws ConfigurationException */ public Config getConfig(Class klass, String name) throws ConfigurationException { if (!providers.containsKey(klass)) { throw new ConfigurationException("No registered providers for components with class " + klass); } ProviderSet pset = providers.get(klass); name = resolveComponentName(klass, name); String path = pset.path + "." + name; if (!conf.get().hasPath(path)) { throw new ConfigurationException("Configuration path " + path + " does not exist"); } return conf.get().getConfig(path); }
throw new ConfigurationException( "inconsistent component path declared for provider " + klass + " that provides type " + type + throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (InvocationTargetException e) { throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (NoSuchMethodException e) { throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (InstantiationException e) { throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (IllegalAccessException e) { throw new ConfigurationException("error when loading provider " + providerClass, e);
throw new ConfigurationException( "inconsistent component path declared for provider " + klass + " that provides type " + type + throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (InvocationTargetException e) { throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (NoSuchMethodException e) { throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (InstantiationException e) { throw new ConfigurationException("error when loading provider " + providerClass, e); } catch (IllegalAccessException e) { throw new ConfigurationException("error when loading provider " + providerClass, e);
@Override public LuceneOptions get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!name.equalsIgnoreCase(config.getString("type"))) { throw new ConfigurationException("Could not find configuration " + name); } return new LuceneOptions( name, getConfigurator(), config.getString("version"), config.getString("directory"), config.getStringList("namespaces"), buildOptions( config.getBoolean("caseInsensitive"), config.getBoolean("useStopWords"), config.getBoolean("useStem")), buildElements( config.getInt("title"), config.getBoolean("redirects"), config.getBoolean("plaintext")) ); } }
@Override public MetaInfoDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("sql")) { return null; } try { return new MetaInfoSqlDao( getConfigurator().get( WpDataSource.class, config.getString("dataSource")) ); } catch (DaoException e) { throw new ConfigurationException(e); } } }
@Override public InterLanguageLinkSqlDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("sql")){ return null; } try { return new InterLanguageLinkSqlDao( getConfigurator().get( WpDataSource.class, config.getString("dataSource")) ); } catch (DaoException e) { throw new ConfigurationException(e); } } }