@ConfigParam (name="name") public void setCompositRuleName(final String compositRuleName) { this.compositRuleName = compositRuleName; this.ruleProviderName = RuleProviderAccessor.parseRuleProviderName(compositRuleName); this.ruleName = RuleProviderAccessor.parseRuleName(compositRuleName); }
/** * * @param compositeRuleName The composite rule name in the form ruleProvider.ruleName. * @return {@code String} The rule provider name part of the composite rule name. */ public static String parseRuleProviderName(final String compositeRuleName) { final int lastIndexOfDot = compositeRuleName.indexOf('.'); if (lastIndexOfDot == -1) { throwInvalidCompositeRuleName(compositeRuleName); } return compositeRuleName.substring(0, lastIndexOfDot); }
/** * Creates and installs the configured rule provider. * * @throws SmooksConfigurationException */ @Initialize public void installRuleProvider() throws SmooksConfigurationException { logger.debug(this); if(RuleProvider.class.isAssignableFrom(provider)) { final RuleProvider providerImpl = createProvider(provider); providerImpl.setName(name); providerImpl.setSrc(src); RuleProviderAccessor.add(applicationContext, providerImpl); } else { throw new SmooksConfigurationException("Invalid rule provider configuration :'" + this + "'"); } }
/** * Adds the passed-in provider to the Smooks {@link ApplicationContext}. * * @param context The Smooks {@link ApplicationContext}. * @param provider The {@link RuleProvider} that is to be added. */ public static final void add(final ApplicationContext context, final RuleProvider provider) { AssertArgument.isNotNull(context, "context"); AssertArgument.isNotNull(provider, "provider"); Map<String, RuleProvider> providers = getRuleProviders(context); if (providers == null) { providers = new HashMap<String, RuleProvider>(); context.setAttribute(RuleProvider.class, providers); } providers.put(provider.getName(), provider); }
/** * Validate will lookup the configured RuleProvider and validate the text against the * rule specfied by the composite rule name. * * @param text The selected data to perform the evaluation on. * @param executionContext The Smooks {@link org.milyn.container.ExecutionContext}. * * @throws ValidationException A FATAL Validation failure has occured, or the maximum number of * allowed failures has been exceeded. */ private OnFailResultImpl _validate(final String text, final ExecutionContext executionContext) throws ValidationException { if(ruleProvider == null) { setRuleProvider(executionContext); } final RuleEvalResult result = ruleProvider.evaluate(ruleName, text, executionContext); if(logger.isDebugEnabled()) { logger.debug(result); } if (!result.matched()) { ValidationResult validationResult = getValidationResult(executionContext); OnFailResultImpl onFailResult = new OnFailResultImpl(); onFailResult.setRuleResult(result); onFailResult.setBeanContext(executionContext.getBeanContext().getBeanMap()); validationResult.addResult(onFailResult, onFail); return onFailResult; } return null; }
/** * Gets a {@link RuleProvider} matching the passed in ruleProviderName. * * @param context The Smooks {@link ApplicationContext}. * @param ruleProviderName The name of the rule provider to lookup. * @return {@link RuleProvider} The {@link RuleProvider} matching the passed in ruleProviderName. * * @throws SmooksException * If no providers have been previously set in the {@link ApplicationContext}, or if * the specified ruleProviderName cannot be found. */ public static final RuleProvider get(final ApplicationContext context, final String ruleProviderName) { AssertArgument.isNotNull(context, "context"); Map<String, RuleProvider> providers = getRuleProviders(context); if ( providers == null || providers.isEmpty()) { throw new SmooksException("No RuleProviders were found. Have you configured a rules section in your Smooks configuration?"); } final RuleProvider provider = providers.get(ruleProviderName); if (provider == null) { throw new SmooksException("Not provider with name '" + ruleProviderName + "' was found in the execution context. Have you configured the rules section properly?"); } return provider; }
private void setMessageBundleBaseName() { String ruleSource = ruleProvider.getSrc(); File srcFile = new File(ruleSource); String srcFileName = srcFile.getName(); int indexOfExt = srcFileName.lastIndexOf('.'); File parentFolder = srcFile.getParentFile(); if(indexOfExt != -1) { messageBundleBaseName = srcFileName.substring(0, indexOfExt); } else { messageBundleBaseName = ruleSource; } if(parentFolder != null) { messageBundleBaseName = parentFolder.getPath() + "/i18n/" + messageBundleBaseName; } else { messageBundleBaseName = "i18n/" + messageBundleBaseName; } messageBundleBaseName = messageBundleBaseName.replace('\\', '/'); }
/** * Creates and installs the configured rule provider. * * @throws SmooksConfigurationException */ @Initialize public void installRuleProvider() throws SmooksConfigurationException { logger.debug(this); if(RuleProvider.class.isAssignableFrom(provider)) { final RuleProvider providerImpl = createProvider(provider); providerImpl.setName(name); providerImpl.setSrc(src); RuleProviderAccessor.add(applicationContext, providerImpl); } else { throw new SmooksConfigurationException("Invalid rule provider configuration :'" + this + "'"); } }
/** * Adds the passed-in provider to the Smooks {@link ApplicationContext}. * * @param context The Smooks {@link ApplicationContext}. * @param provider The {@link RuleProvider} that is to be added. */ public static final void add(final ApplicationContext context, final RuleProvider provider) { AssertArgument.isNotNull(context, "context"); AssertArgument.isNotNull(provider, "provider"); Map<String, RuleProvider> providers = getRuleProviders(context); if (providers == null) { providers = new HashMap<String, RuleProvider>(); context.setAttribute(RuleProvider.class, providers); } providers.put(provider.getName(), provider); }
/** * Parse the rule name from the passed in composite rule name. * * @param compositeRuleName The composite rule name in the form ruleProvider.ruleName. * @return {@code String} The rule name part of the composite rule name. */ public static String parseRuleName(final String compositeRuleName) { final int lastIndexOfDot = compositeRuleName.lastIndexOf('.'); if (lastIndexOfDot == -1) { throwInvalidCompositeRuleName(compositeRuleName); } return compositeRuleName.substring(lastIndexOfDot + 1); }
@ConfigParam (name="name") public void setCompositRuleName(final String compositRuleName) { this.compositRuleName = compositRuleName; this.ruleProviderName = RuleProviderAccessor.parseRuleProviderName(compositRuleName); this.ruleName = RuleProviderAccessor.parseRuleName(compositRuleName); }
/** * Gets a {@link RuleProvider} matching the passed in ruleProviderName. * * @param context The Smooks {@link ApplicationContext}. * @param ruleProviderName The name of the rule provider to lookup. * @return {@link RuleProvider} The {@link RuleProvider} matching the passed in ruleProviderName. * * @throws SmooksException * If no providers have been previously set in the {@link ApplicationContext}, or if * the specified ruleProviderName cannot be found. */ public static final RuleProvider get(final ApplicationContext context, final String ruleProviderName) { AssertArgument.isNotNull(context, "context"); Map<String, RuleProvider> providers = getRuleProviders(context); if ( providers == null || providers.isEmpty()) { throw new SmooksException("No RuleProviders were found. Have you configured a rules section in your Smooks configuration?"); } final RuleProvider provider = providers.get(ruleProviderName); if (provider == null) { throw new SmooksException("Not provider with name '" + ruleProviderName + "' was found in the execution context. Have you configured the rules section properly?"); } return provider; }
private void setMessageBundleBaseName() { String ruleSource = ruleProvider.getSrc(); File srcFile = new File(ruleSource); String srcFileName = srcFile.getName(); int indexOfExt = srcFileName.lastIndexOf('.'); File parentFolder = srcFile.getParentFile(); if(indexOfExt != -1) { messageBundleBaseName = srcFileName.substring(0, indexOfExt); } else { messageBundleBaseName = ruleSource; } if(parentFolder != null) { messageBundleBaseName = parentFolder.getPath() + "/i18n/" + messageBundleBaseName; } else { messageBundleBaseName = "i18n/" + messageBundleBaseName; } messageBundleBaseName = messageBundleBaseName.replace('\\', '/'); }
/** * Creates and installs the configured rule provider. * * @throws SmooksConfigurationException smooks configuration error */ @Initialize public void installRuleProvider() throws SmooksConfigurationException { logger.debug(this); if(RuleProvider.class.isAssignableFrom(provider)) { final RuleProvider providerImpl = createProvider(provider); providerImpl.setName(name); providerImpl.setSrc(src); RuleProviderAccessor.add(applicationContext, providerImpl); } else { throw new SmooksConfigurationException("Invalid rule provider configuration :'" + this + "'"); } }
/** * Adds the passed-in provider to the Smooks {@link ApplicationContext}. * * @param context The Smooks {@link ApplicationContext}. * @param provider The {@link RuleProvider} that is to be added. */ public static final void add(final ApplicationContext context, final RuleProvider provider) { AssertArgument.isNotNull(context, "context"); AssertArgument.isNotNull(provider, "provider"); Map<String, RuleProvider> providers = getRuleProviders(context); if (providers == null) { providers = new HashMap<String, RuleProvider>(); context.setAttribute(RuleProvider.class, providers); } providers.put(provider.getName(), provider); }
/** * Parse the rule name from the passed in composite rule name. * * @param compositeRuleName The composite rule name in the form ruleProvider.ruleName. * @return {@code String} The rule name part of the composite rule name. */ public static String parseRuleName(final String compositeRuleName) { final int lastIndexOfDot = compositeRuleName.lastIndexOf('.'); if (lastIndexOfDot == -1) { throwInvalidCompositeRuleName(compositeRuleName); } return compositeRuleName.substring(lastIndexOfDot + 1); }
/** * Gets a {@link RuleProvider} matching the passed in ruleProviderName. * * @param context The Smooks {@link ApplicationContext}. * @param ruleProviderName The name of the rule provider to lookup. * @return {@link RuleProvider} The {@link RuleProvider} matching the passed in ruleProviderName. * * @throws SmooksException * If no providers have been previously set in the {@link ApplicationContext}, or if * the specified ruleProviderName cannot be found. */ public static final RuleProvider get(final ApplicationContext context, final String ruleProviderName) { AssertArgument.isNotNull(context, "context"); Map<String, RuleProvider> providers = getRuleProviders(context); if ( providers == null || providers.isEmpty()) { throw new SmooksException("No RuleProviders were found. Have you configured a rules section in your Smooks configuration?"); } final RuleProvider provider = providers.get(ruleProviderName); if (provider == null) { throw new SmooksException("Not provider with name '" + ruleProviderName + "' was found in the execution context. Have you configured the rules section properly?"); } return provider; }
/** * * @param compositeRuleName The composite rule name in the form ruleProvider.ruleName. * @return {@code String} The rule provider name part of the composite rule name. */ public static String parseRuleProviderName(final String compositeRuleName) { final int lastIndexOfDot = compositeRuleName.indexOf('.'); if (lastIndexOfDot == -1) { throwInvalidCompositeRuleName(compositeRuleName); } return compositeRuleName.substring(0, lastIndexOfDot); }
/** * * @param compositeRuleName The composite rule name in the form ruleProvider.ruleName. * @return {@code String} The rule provider name part of the composite rule name. */ public static String parseRuleProviderName(final String compositeRuleName) { final int lastIndexOfDot = compositeRuleName.indexOf('.'); if (lastIndexOfDot == -1) { throwInvalidCompositeRuleName(compositeRuleName); } return compositeRuleName.substring(0, lastIndexOfDot); }
/** * Parse the rule name from the passed in composite rule name. * * @param compositeRuleName The composite rule name in the form ruleProvider.ruleName. * @return {@code String} The rule name part of the composite rule name. */ public static String parseRuleName(final String compositeRuleName) { final int lastIndexOfDot = compositeRuleName.lastIndexOf('.'); if (lastIndexOfDot == -1) { throwInvalidCompositeRuleName(compositeRuleName); } return compositeRuleName.substring(lastIndexOfDot + 1); }