@Test public void testFirstMatching() throws Exception { final ConfigurationFactory cf = new ConfigurationFactory(); final AutoConfig ac = new AutoConfig(cf); final AppModule appModule = new AppModule(new EjbModule(new EjbJar())); for (final String s : list) { appModule.getResources().add(new Resource(s, "DataSource")); } final AutoConfig.AppResources resources = new AutoConfig.AppResources(appModule, Collections.<ContainerInfo>emptyList()); final Method m = ac.getClass().getDeclaredMethod("firstMatching", String.class, String.class, Properties.class, AutoConfig.AppResources.class); m.setAccessible(true); for (final String s : list) { final String prefix = s.substring(0, s.indexOf('/')); final String result = (String) m.invoke(ac, prefix, "DataSource", new Properties(), resources); Assert.assertTrue(result.startsWith(prefix)); } String result = (String) m.invoke(ac, "abc-jkl-uvw-jkl-web", "DataSource", new Properties(), resources); Assert.assertEquals("abc-jkl-uvw-jkl-web/jdbc/appmgr-jta", result); result = (String) m.invoke(ac, "jdbc", "DataSource", new Properties(), resources); Assert.assertEquals("jdbc/appmgr-jta", result); }
private String firstMatching(final String prefix, final String type, final Properties required, final AppResources appResources) { final List<String> resourceIds = getResourceIds(appResources, type, required); if(resourceIds.isEmpty()){ return null; } return Collections.min(resourceIds, new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (o1.startsWith(prefix) && o2.startsWith(prefix)) { return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } else if (o1.startsWith(prefix)) { return -1; } else if (o2.startsWith(prefix)) { return 1; } return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } }); }
AutoConfig implements DynamicDeployer, JndiConstants { private String firstMatching(final String prefix, final String type, final Properties required, final AppResources appResources) { final List<String> resourceIds = getResourceIds(appResources, type, required); if(resourceIds.isEmpty()){ return null; } return Collections.min(resourceIds, new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (o1.startsWith(prefix) && o2.startsWith(prefix)) { return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } else if (o1.startsWith(prefix)) { return -1; } else if (o2.startsWith(prefix)) { return 1; } return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } }); } }
AutoConfig implements DynamicDeployer, JndiConstants { private String firstMatching(final String prefix, final String type, final Properties required, final AppResources appResources) { final List<String> resourceIds = getResourceIds(appResources, type, required); if(resourceIds.isEmpty()){ return null; } return Collections.min(resourceIds, new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (o1.startsWith(prefix) && o2.startsWith(prefix)) { return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } else if (o1.startsWith(prefix)) { return -1; } else if (o2.startsWith(prefix)) { return 1; } return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } }); } AutoConfig(final ConfigurationFactory configFactory); }
AutoConfig implements DynamicDeployer, JndiConstants { private String firstMatching(final String prefix, final String type, final Properties required, final AppResources appResources) { final List<String> resourceIds = getResourceIds(appResources, type, required); if(resourceIds.isEmpty()){ return null; } return Collections.min(resourceIds, new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (o1.startsWith(prefix) && o2.startsWith(prefix)) { return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } else if (o1.startsWith(prefix)) { return -1; } else if (o2.startsWith(prefix)) { return 1; } return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } }); } AutoConfig(final ConfigurationFactory configFactory); synchronized boolean autoCreateResources(); synchronized void autoCreateResources(final boolean autoCreateResources); synchronized boolean autoCreateContainers(); synchronized void autoCreateContainers(final boolean autoCreateContainers); void init(); @Override synchronized AppModule deploy(final AppModule appModule); static String findResourceId(final Collection<String> resourceIds, final String inId); }
AutoConfig implements DynamicDeployer, JndiConstants { private String firstMatching(final String prefix, final String type, final Properties required, final AppResources appResources) { final List<String> resourceIds = getResourceIds(appResources, type, required); if(resourceIds.isEmpty()){ return null; } return Collections.min(resourceIds, new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (o1.startsWith(prefix) && o2.startsWith(prefix)) { return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } else if (o1.startsWith(prefix)) { return -1; } else if (o2.startsWith(prefix)) { return 1; } return resourceIds.indexOf(o1) - resourceIds.indexOf(o2); } }); } AutoConfig(final ConfigurationFactory configFactory); synchronized boolean autoCreateResources(); synchronized void autoCreateResources(final boolean autoCreateResources); synchronized boolean autoCreateContainers(); synchronized void autoCreateContainers(final boolean autoCreateContainers); void init(); @Override synchronized AppModule deploy(final AppModule appModule); static String findResourceId(final Collection<String> resourceIds, final String inId); static final String ORIGIN_ANNOTATION; static final String ORIGIN_FLAG; static final String ORIGINAL_ID; static Logger logger; static final String AUTOCREATE_JTA_DATASOURCE_FROM_NON_JTA_ONE_KEY; }