/** * Merges this profile into the specified properties. * If properties already contains entries related to this profile, * then this method will overwrite them. * @param properties target properties * @throws IllegalArgumentException if some parameters were {@code null} */ public void storeTo(Properties properties) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); //$NON-NLS-1$ } properties.setProperty(prefix, getServiceClass().getName()); for (Map.Entry<String, String> entry : getConfiguration().entrySet()) { properties.setProperty(prefix + '.' + entry.getKey(), entry.getValue()); } } }
private void checkPrefix(ServiceProfile<?> profile, String prefix) { assert profile != null; assert prefix != null; if (profile.getPrefix().equals(prefix) == false) { throw new IllegalArgumentException(MessageFormat.format( "Profile \"{1}\" is invalid, this must be \"{0}\" ({2})", prefix, profile.getPrefix(), profile.getServiceClass().getName())); } }
@Override public final void configure(ServiceProfile<?> profile) throws InterruptedException, IOException { try { configureVersion(profile); doConfigure(profile); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getServiceClass().getName()), e); } }
/** * Creates a new instance using context parameters. * The created service will automatically {@link Service#configure(ServiceProfile) configured} * by using this profile. * @return the created instance. * @throws InterruptedException if interrupted in configuring the target service * @throws IOException if failed to create or configure the service * @since 0.2.4 */ 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; }
GROUP_PREFIX_COMMAND, profile.getPrefix(), profile.getServiceClass().getName())); "Profile \"{0}\" is duplicated ({1} <=> {2})", profileName, profile.getServiceClass().getName(), map.get(profileName).getServiceClass().getName()));
@Override public void configure(ServiceProfile<?> profile) throws IOException, InterruptedException { this.prefix = profile.getPrefix(); try { this.confDirectory = getConfDirectory(profile); this.delegations = getDelegations(profile); this.forceSetUp = profile.getConfiguration(KEY_SETUP, false, true); this.forceCleanUp = profile.getConfiguration(KEY_CLEANUP, false, true); } catch (IllegalArgumentException e) { throw new IOException(MessageFormat.format( "Failed to configure \"{0}\" ({1})", profile.getPrefix(), profile.getServiceClass().getName()), e); } if (forceSetUp != null && delegations.containsKey(forceSetUp) == false) { throw new IOException(MessageFormat.format( "Failed to detect setUp target: \"{2}\" in {0}.{1}", profile.getPrefix(), KEY_SETUP, forceSetUp)); } if (forceCleanUp != null && delegations.containsKey(forceCleanUp) == false) { throw new IOException(MessageFormat.format( "Failed to detect cleanUp target: \"{2}\" in {0}.{1}", profile.getPrefix(), KEY_CLEANUP, forceCleanUp)); } }