@Test public void testService() { assertThat(registry.getService("Calculator", "calculator"), is(sameInstance(Calculator.kDescriptor))); try { registry.getService("gurba.dot.Calculator"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Invalid identifier: \"gurba.dot.Calculator\"")); } try { registry.getService("Calculator"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Requesting global service name without package: \"Calculator\"")); } try { registry.getService("gurba.Calculator"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such program \"gurba\" known for service \"Calculator\"")); } try { registry.getService("Calculator", "gurba"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such program \"gurba\" known for service \"Calculator\"")); } try { registry.getService("calculator.Gurba"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such service \"Gurba\" in program \"calculator\"")); } try { registry.getService("Gurba", "calculator"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such service \"Gurba\" in program \"calculator\"")); } }
@Nonnull @Override public PService getService(String serviceName, String programContext) { String finalName = qualifiedNameFromIdAndContext(serviceName, programContext); if (services.containsKey(finalName)) { return services.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException("No such service \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException("No such program \"" + program + "\" known for service \"" + serviceName + "\""); } }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override public PService getService(String serviceName, String programContext) { String finalName = qualifiedNameFromIdAndContext(serviceName, programContext); if (services.containsKey(finalName)) { return services.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException("No such service \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException("No such program \"" + program + "\" known for service \"" + serviceName + "\""); } } }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override public PService getService(String serviceName, String programContext) { String finalName = qualifiedNameFromIdAndContext(serviceName, programContext); if (services.containsKey(finalName)) { return services.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException("No such service \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException("No such program \"" + program + "\" known for service \"" + serviceName + "\""); } } SimpleTypeRegistry(); }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override public PService getService(String serviceName, String programContext) { String finalName = qualifiedNameFromIdAndContext(serviceName, programContext); if (services.containsKey(finalName)) { return services.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException("No such service \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException("No such program \"" + program + "\" known for service \"" + serviceName + "\""); } } SimpleTypeRegistry(); @Nonnull @Override @SuppressWarnings("unchecked") T getDeclaredType(@Nonnull String typeName,
                                                                @Nonnull String programContext); @Nullable @Override @SuppressWarnings("unchecked") T getConstantValue(@Nonnull String constReference, @Nonnull String programContext); @Nonnull @Override PService getService(String serviceName, String programContext); @Override void registerConstant(@Nonnull String identifier, @Nonnull String program, @Nonnull Object value); @Override @SuppressWarnings("unchecked") boolean register(@Nonnull PService service); @Override boolean register(PDeclaredDescriptor<T> declaredType); }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override public PService getService(String serviceName, String programContext) { String finalName = qualifiedNameFromIdAndContext(serviceName, programContext); if (services.containsKey(finalName)) { return services.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException("No such service \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException("No such program \"" + program + "\" known for service \"" + serviceName + "\""); } } SimpleTypeRegistry(); @Nonnull @Override @SuppressWarnings("unchecked") T getDeclaredType(@Nonnull String typeName,
                                                                @Nonnull String programContext); @Nullable @Override @SuppressWarnings("unchecked") T getConstantValue(@Nonnull String constReference, @Nonnull String programContext); @Nonnull @Override PService getService(String serviceName, String programContext); @Override void registerConstant(@Nonnull String identifier, @Nonnull String program, @Nonnull Object value); @Override @SuppressWarnings("unchecked") boolean register(@Nonnull PService service); @Override boolean register(PDeclaredDescriptor<T> declaredType);  }