@Test public void newInstance() throws Exception { Properties prop = new Properties(); prop.setProperty("mock1", MockService.class.getName()); prop.setProperty("mock1.hoge", "foo"); prop.setProperty("mock1.bar.1", "moga"); ClassLoader cl = getClass().getClassLoader(); ServiceProfile<Service> service = ServiceProfile.load(prop, "mock1", Service.class, ProfileContext.system(cl)); Service instance = service.newInstance(); assertThat(instance, instanceOf(MockService.class)); MockService mock = (MockService) instance; assertThat(mock.serviceProfile.getPrefix(), is("mock1")); assertThat(mock.serviceProfile.getConfiguration().size(), is(2)); assertThat(mock.serviceProfile.getConfiguration().get("hoge"), is("foo")); assertThat(mock.serviceProfile.getConfiguration().get("bar.1"), is("moga")); }
public T newInstance() throws InterruptedException, IOException { LOG.debug("Creating new instance for {}: {}", prefix, serviceClass.getName()); T instance; try { instance = serviceClass.newInstance(); } catch (Exception e) { throw new IOException(MessageFormat.format( "Failed to create a new service instance for {0}: {1}", getPrefix(), getServiceClass().getName()), e); } instance.configure(this); return instance; }
ServiceProfile { public T newInstance() throws InterruptedException, IOException { LOG.debug("Creating new instance for {}: {}", prefix, serviceClass.getName()); T instance; try { instance = serviceClass.newInstance(); } catch (Exception e) { throw new IOException(MessageFormat.format( "Failed to create a new service instance for {0}: {1}", getPrefix(), getServiceClass().getName()), e); } instance.configure(this); return instance; } }
ServiceProfile { public T newInstance() throws InterruptedException, IOException { LOG.debug("Creating new instance for {}: {}", prefix, serviceClass.getName()); T instance; try { instance = serviceClass.newInstance(); } catch (Exception e) { throw new IOException(MessageFormat.format( "Failed to create a new service instance for {0}: {1}", getPrefix(), getServiceClass().getName()), e); } instance.configure(this); return instance; } ServiceProfile(
            String prefix,
            Class<? extends T> serviceClass,
            Map<String, String> configuration,
            ProfileContext context); }
ServiceProfile { public T newInstance() throws InterruptedException, IOException { LOG.debug("Creating new instance for {}: {}", prefix, serviceClass.getName()); T instance; try { instance = serviceClass.newInstance(); } catch (Exception e) { throw new IOException(MessageFormat.format( "Failed to create a new service instance for {0}: {1}", getPrefix(), getServiceClass().getName()), e); } instance.configure(this); return instance; } ServiceProfile(
            String prefix,
            Class<? extends T> serviceClass,
            Map<String, String> configuration,
            ProfileContext context); String getPrefix(); Class<? extends T> getServiceClass(); Map<String, String> getConfiguration(); String getConfiguration(String key, boolean mandatory, boolean resolve); String normalize(String key, String value, boolean mandatory, boolean resolve); ProfileContext getContext(); @Deprecated ClassLoader getClassLoader(); T newInstance(); @Deprecated T newInstance(VariableResolver variables); @Deprecated static ServiceProfile<T> load(
            Properties properties,
            String prefix,
            Class<T> serviceBaseClass,
            ClassLoader classLoader); static ServiceProfile<T> load(
            Properties properties,
            String prefix,
            Class<T> serviceBaseClass,
            ProfileContext context); void storeTo(Properties properties); }
ServiceProfile { public T newInstance() throws InterruptedException, IOException { LOG.debug("Creating new instance for {}: {}", prefix, serviceClass.getName()); T instance; try { instance = serviceClass.newInstance(); } catch (Exception e) { throw new IOException(MessageFormat.format( "Failed to create a new service instance for {0}: {1}", getPrefix(), getServiceClass().getName()), e); } instance.configure(this); return instance; } ServiceProfile(
            String prefix,
            Class<? extends T> serviceClass,
            Map<String, String> configuration,
            ProfileContext context); String getPrefix(); Class<? extends T> getServiceClass(); Map<String, String> getConfiguration(); String getConfiguration(String key, boolean mandatory, boolean resolve); String normalize(String key, String value, boolean mandatory, boolean resolve); ProfileContext getContext(); @Deprecated ClassLoader getClassLoader(); T newInstance(); @Deprecated T newInstance(VariableResolver variables); @Deprecated static ServiceProfile<T> load(
            Properties properties,
            String prefix,
            Class<T> serviceBaseClass,
            ClassLoader classLoader); static ServiceProfile<T> load(
            Properties properties,
            String prefix,
            Class<T> serviceBaseClass,
            ProfileContext context); void storeTo(Properties properties);  }