@SuppressWarnings("unused") public File getTempOutDir() { if(tempOutDir == null) { throw new SmooksConfigurationException("Temp OutDir not set."); } return tempOutDir; }
@SuppressWarnings("unused") public File getTempOutDir() { if(tempOutDir == null) { throw new SmooksConfigurationException("Temp OutDir not set."); } return tempOutDir; }
public ExpressionEvaluator getConditionEvaluator(String idRef) { SmooksConfig smooksConfig = configStack.peek(); while(smooksConfig != null) { ExpressionEvaluator evaluator = smooksConfig.conditionEvaluators.get(idRef); if(evaluator != null) { return evaluator; } smooksConfig = smooksConfig.parent; } throw new SmooksConfigurationException("Unknown condition idRef '" + idRef + "'."); }
private void assertUniqueConditionId(String id) { if(configStack.peek().conditionEvaluators.containsKey(id)) { throw new SmooksConfigurationException("Duplicate condition ID '" + id + "'."); } }
public void visitBefore(Element element, ExecutionContext execContext) throws SmooksException { boolean isBeanIdRefSpecified = element.hasAttribute("beanIdRef"); boolean isBeanTypeSpecified = element.hasAttribute("beanType"); boolean isBeanAnnotationSpecified = element.hasAttribute("beanAnnotation"); if(!isBeanIdRefSpecified && !isBeanTypeSpecified && !isBeanAnnotationSpecified) { throw new SmooksConfigurationException("One or more of attributes 'beanIdRef', 'beanType' and 'beanAnnotation' must be specified on a bean wiring configuration."); } } }
private void assertSelectorOK(SmooksResourceConfiguration config) { String selector = config.getSelector(); if(selector != null) { if(selector.contains(SmooksResourceConfiguration.DOCUMENT_FRAGMENT_SELECTOR) || selector.contains(SmooksResourceConfiguration.LEGACY_DOCUMENT_FRAGMENT_SELECTOR)) { throw new SmooksConfigurationException("Cannot use the document selector with the XMLBinding class. Must use an absolute path. Selector value '" + selector + "'."); } if(!selector.startsWith("/") && !selector.startsWith("${") && !selector.startsWith("#")) { throw new SmooksConfigurationException("Invalid selector value '" + selector + "'. Selector paths must be absolute."); } rootElementNames.add(config.getSelectorSteps()[0].getTargetElement()); } }
private void pushConfig(String file, URI fileURI) { for (SmooksConfig smooksConfig : configStack) { if(fileURI.equals(smooksConfig.fileURI)) { throw new SmooksConfigurationException("Invalid circular reference to config file '" + fileURI + "' from inside config file '" + getCurrentPath() + "'."); } } SmooksConfig config = new SmooksConfig(file); config.parent = configStack.peek(); config.fileURI = fileURI; configStack.push(config); }
private void pushConfig(String file, URI fileURI) { for (SmooksConfig smooksConfig : configStack) { if(fileURI.equals(smooksConfig.fileURI)) { throw new SmooksConfigurationException("Invalid circular reference to config file '" + fileURI + "' from inside config file '" + getCurrentPath() + "'."); } } SmooksConfig config = new SmooksConfig(file); config.parent = configStack.peek(); config.fileURI = fileURI; configStack.push(config); }
private void assertElementPermitted(Element configElement) { if(isExtensionConfig()) { String elementName = DomUtils.getName(configElement); if(!elementName.equals("import") && !elementName.equals("resource-config")) { throw new SmooksConfigurationException("Configuration element '" + elementName + "' not supported in an extension configuration."); } } }
/** * Checks if the class has a default constructor */ private void checkForDefaultConstructor() { try { beanRuntimeInfo.getPopulateType().getConstructor(); } catch (NoSuchMethodException e) { throw new SmooksConfigurationException("Invalid Smooks bean configuration. Bean class " + beanRuntimeInfo.getPopulateType().getName() + " doesn't have a public default constructor."); } }
public static void recordBeanRuntimeInfo(String beanId, BeanRuntimeInfo beanRuntimeInfo, ApplicationContext appContext) { Map<String, BeanRuntimeInfo> runtimeInfoMap = getRuntimeInfoMap(appContext); BeanRuntimeInfo existingBeanConfig = runtimeInfoMap.get(beanId); if(existingBeanConfig != null && !beanRuntimeInfo.equals(existingBeanConfig)) { throw new SmooksConfigurationException("Multiple configurations present with beanId='" + beanId + "', but the bean runtime infos are not equal i.e bean classes etc are different. Use a different beanId and the 'setOnMethod' config if needed."); } runtimeInfoMap.put(beanId, beanRuntimeInfo); }
/** * Checks if the class has a default constructor */ private void checkForDefaultConstructor() { try { beanRuntimeInfo.getPopulateType().getConstructor(); } catch (NoSuchMethodException e) { throw new SmooksConfigurationException("Invalid Smooks bean configuration. Bean class " + beanRuntimeInfo.getPopulateType().getName() + " doesn't have a public default constructor."); } }
@Initialize public void createBeanWriter() { try { BeanWriter beanWriter = beanWriterClass.newInstance(); Configurator.configure(beanWriter, config, appContext); getBeanWriters(beanClass, appContext).put(config.getSelectorNamespaceURI(), beanWriter); } catch (InstantiationException e) { throw new SmooksConfigurationException("Unable to create BeanWriter instance.", e); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to create BeanWriter instance.", e); } }
@Initialize public void createBeanWriter() { try { BeanWriter beanWriter = beanWriterClass.newInstance(); Configurator.configure(beanWriter, config, appContext); getBeanWriters(beanClass, appContext).put(config.getSelectorNamespaceURI(), beanWriter); } catch (InstantiationException e) { throw new SmooksConfigurationException("Unable to create BeanWriter instance.", e); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to create BeanWriter instance.", e); } }
private Class<?> getBeanClass(Element bindingElement) { String beanClassName = getBeanTypeName(bindingElement); Class<?> beanClass; try { beanClass = ClassUtil.forName(beanClassName, getClass()); } catch (ClassNotFoundException e) { throw new SmooksConfigurationException("Bean class '" + beanClassName + "' not avilable on classpath."); } return beanClass; }
public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException { if(!isCreateOnElementSet(element) && !isWireOnElementSet(element)) { throw new SmooksConfigurationException("The bindings attribute 'createOnElement' and wiring attribute 'wireOnElement' " + "are both not set. One of them must at least be set. If the result of this binding should be a new populated Object " + "then you need to set the 'createOnElement' bindings attribute. If you want to update an existing object in the bean " + "context then you must set the 'wireOnElement' attribute."); } }
private static <U> void applyConfig(Field field, U instance, SmooksResourceConfiguration config) { try { ClassUtil.setField(field, instance, config); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Failed to set paramater configuration value on '" + getLongMemberName(field) + "'.", e); } }
private synchronized void initializeResourceConfigurations() { if(!isConfigurable) { return; } isConfigurable = false; try { context.getStore().setNamespaces(); } catch (SAXPathException e) { throw new SmooksConfigurationException("Error configuring namespaces", e); } }
private synchronized void initializeResourceConfigurations() { if(!isConfigurable) { return; } isConfigurable = false; try { context.getStore().setNamespaces(); } catch (SAXPathException e) { throw new SmooksConfigurationException("Error configuring namespaces", e); } }
public static SmooksResourceConfiguration findBeanCreatorConfig(String beanId, ExecutionContext executionContext) { ExtensionContext extensionContext = ExtensionContext.getExtensionContext(executionContext); List<SmooksResourceConfiguration> creatorConfigs = extensionContext.lookupResource(new ConfigSearch().resource(BeanInstanceCreator.class.getName()).param("beanId", beanId)); if(creatorConfigs.size() > 1) { throw new SmooksConfigurationException("Multiple <jb:bean> configurations exist for beanId '" + beanId + "'. 'beanId' values must be unique."); } return creatorConfigs.get(0); } }